better endpoints

This commit is contained in:
Ste Vaidis 2024-02-20 10:30:02 +02:00
parent ffb833f00c
commit bee9f98667
4 changed files with 137 additions and 89 deletions

View File

@ -14,25 +14,30 @@ cd /var/www/sites/${SITE}
echo echo
# if module does not exist # if module does not exist
../vendor/drush/drush/drush pml | grep "(endpoint_get_${NODE})" ../vendor/drush/drush/drush pml --fields=name,status | grep "endpoint_get_${NODE}"
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
echo -n " 🌈 Cannot found module ${B}endpoint_get_${NODE}${E}" echo -n " 🌈 Cannot find module ${B}endpoint_get_${NODE}${E}"
exit exit
fi fi
echo -e " 🍓 Found module ${B}endpoint_get_${NODE}${E}" echo -e " 🍓 Found module ${B}endpoint_get_${NODE}${E}"
../vendor/drush/drush/drush cr
# if is enabled, disable it # if is enabled, disable it
../vendor/drush/drush/drush pml | grep -e "Enabled" | grep "(endpoint_get_${NODE})" &> /dev/null ../vendor/drush/drush/drush pml --fields=name,status > /tmp/.drush.pml
cat /tmp/.drush.pml | grep -e "Enabled" | grep "endpoint_get_${NODE}"
# cat ./drush.pml | grep -e "Enabled" | grep "(endpoint_get_${NODE})" &> /dev/null
if [ $? -eq 0 ];then if [ $? -eq 0 ];then
echo -n " 🍓 Disabling module ${B}endpoint_get_${NODE}${E}" echo -n " 🍓 Disabling module ${B}endpoint_get_${NODE}${E}"
../vendor/drush/drush/drush pmu "endpoint_get_${NODE}" ../vendor/drush/drush/drush pmu "endpoint_get_${NODE}"
../vendor/drush/drush/drush pml | grep "(endpoint_get_${NODE})"
fi fi
# if is not disabled, dont delete it # if is not disabled, dont delete it
../vendor/drush/drush/drush pml | grep -e "Disabled" | grep "(endpoint_get_${NODE})" &> /dev/null ../vendor/drush/drush/drush pml --fields=name,status > /tmp/.drush.pml
if [ $? -ne 0 ];then cat ./drush.pml | grep -e "Enabled" | grep "endpoint_get_${NODE}"
echo -n " 🌈 Cannot deleting enabled module ${B}endpoint_get_${NODE}${E}" if [ $? -eq 0 ];then
echo -n " 🌈 Cannot delete enabled module ${B}endpoint_get_${NODE}${E}"
../vendor/drush/drush/drush pml --fields=name,status | grep "endpoint_get_${NODE}"
exit exit
fi fi

View File

@ -6,6 +6,8 @@ B="\e[0;34m"
W="\e[0;97m" W="\e[0;97m"
E="\e[00m" E="\e[00m"
SCRIPT_PATH=$(realpath $0)
SCRIPT_DIR=$(dirname ${SCRIPT_PATH})
SOURCE="/root/dev/endpoints" SOURCE="/root/dev/endpoints"
BASE_DIR="/var/www/sites" BASE_DIR="/var/www/sites"
MODULES="modules/custom" MODULES="modules/custom"
@ -32,77 +34,105 @@ function quit() {
function log() { function log() {
[ $1 == 0 ] && echo -e " ${G}[ OK ]${E}"; return if [ $? -eq 0 ]; then
echo -e " ${R}[FAIL]${E}" echo -e "${G}[ OK ]${E}"
exit return 0
else
echo -e "${G}[FAIL]${E}"
return 1
fi
}
function copy_template() {
echo
echo -en " 📂 Copy template module dir to ${B}${SITE}${E} "
cp -r "${SOURCE}/endpoint_get_AAAAA" "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}"
log $?
echo
cd "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}"
} }
echo
echo -en " 📂 Copy template module dir to ${B}${SITE}${E}"
cp -r "${SOURCE}/endpoint_get_AAAAA" "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}"
log $?
echo
cd "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}"
# Rename files # Rename files
function rename_info() {
echo -en " 🍓 Rename ${B}endpoint_get_${NODE}.info.yml${E} file "
mv "endpoint_get_AAAAA.info.yml" "endpoint_get_${NODE}.info.yml" &> /dev/null
log $?
}
function rename_routing() {
echo -en " 🍓 Rename ${B}endpoint_get_${NODE}.routing.yml${E} file "
mv "endpoint_get_AAAAA.routing.yml" "endpoint_get_${NODE}.routing.yml" &> /dev/null
log $?
}
echo -en " 🍓 Rename ${B}endpoint_get_${NODE}.info.yml${E} file"
mv "endpoint_get_AAAAA.info.yml" "endpoint_get_${NODE}.info.yml"
log $?
echo -en " 🍓 Rename ${B}endpoint_get_${NODE}.routing.yml${E} file"
mv "endpoint_get_AAAAA.routing.yml" "endpoint_get_${NODE}.routing.yml"
log $?
# Edit files # Edit files
echo function edit_files() {
echo -en " ⭐ Edit ${B}endpoint_get_${NODE}.info.yml${E} file" echo
sed -i "s/AAAAA/${NODE}/g" "endpoint_get_${NODE}.info.yml" echo -en " ⭐ Edit ${B}endpoint_get_${NODE}.info.yml${E} file "
log $? sed -i "s/AAAAA/${NODE}/g" "endpoint_get_${NODE}.info.yml"
log $?
[ $? -ne 0 ] && return 1
echo -en " ⭐ Edit ${B}endpoint_get_${NODE}.routing.yml${E} file" echo -en " ⭐ Edit ${B}endpoint_get_${NODE}.routing.yml${E} file "
sed -i "s/AAAAA/${NODE}/g" "endpoint_get_${NODE}.routing.yml" sed -i "s/AAAAA/${NODE}/g" "endpoint_get_${NODE}.routing.yml"
log $? log $?
[ $? -ne 0 ] && return 1
echo -en " ⭐ Edit ${B}src/Controller/NodeController.php${E} file" echo -en " ⭐ Edit ${B}src/Controller/NodeController.php${E} file "
sed -i "s/AAAAA/${NODE}/g" "src/Controller/NodeController.php" sed -i "s/AAAAA/${NODE}/g" "src/Controller/NodeController.php"
log $? log $?
[ $? -ne 0 ] && return 1
echo -en " ⭐ Edit ${B}src/Controller/NodesController.php${E} file" echo -en " ⭐ Edit ${B}src/Controller/NodesController.php${E} file "
sed -i "s/AAAAA/${NODE}/g" "src/Controller/NodesController.php" sed -i "s/AAAAA/${NODE}/g" "src/Controller/NodesController.php"
log $? log $?
[ $? -ne 0 ] && return 1
echo -en " ⭐ Edit ${B}src/Controller/CategoryController.php${E} file" echo -en " ⭐ Edit ${B}src/Controller/CategoryController.php${E} file "
sed -i "s/AAAAA/${NODE}/g" "src/Controller/CategoryController.php" sed -i "s/AAAAA/${NODE}/g" "src/Controller/CategoryController.php"
log $? log $?
echo [ $? -ne 0 ] && return 1
return 0
}
# Filesystem function file_permissions() {
chown -R apache:apache "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}" echo
echo -en " 🫐 chown -R apache:apache ${B}/endpoint_get_${NODE}${E} "
chown -R apache:apache "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}"
log $?
[ $? -ne 0 ] && return 1
return 0
}
function enable_module() {
return 0
echo
echo -en " 🌈 Enable module"
cd /var/www/sites/${SITE}
../vendor/drush/drush/drush en "endpoint_get_${NODE}"
log $?
[ $? -ne 0 ] && return 1
return 0
}
# Enable module function test_module() {
echo -e " 🌈 Enable module" BASE_URL="http://$(ls -l /var/www/ | grep ${SITE} | awk {'print $9'}).vm7"
cd /var/www/sites/${SITE} API_URL="api/el"
../vendor/drush/drush/drush en "endpoint_get_${NODE}" NODE_URL="${BASE_URL}/${API_URL}/${NODE}"
NODES_URL="${BASE_URL}/${API_URL}/${NODE}s"
# Test endpoint ENDPOINTS=(
BASE_URL="http://$(ls -l /var/www/ | grep ${SITE} | awk {'print $9'}).vm7"
API_URL="api/el"
NODE_URL="${BASE_URL}/${API_URL}/${NODE}"
NODES_URL="${BASE_URL}/${API_URL}/${NODE}s"
ENDPOINTS=(
api/en/${NODE}s api/en/${NODE}s
api/el/${NODE}s api/el/${NODE}s
) )
for ENDPOINT in ${ENDPOINTS[@]}; do for ENDPOINT in ${ENDPOINTS[@]}; do
ENDPOINT_STATUS=$(curl -sI --location --request GET $BASE_URL/$ENDPOINT?_format=json \ ENDPOINT_STATUS=$(curl -sI --location --request GET $BASE_URL/$ENDPOINT?_format=json \
-b cookie.txt \ -b cookie.txt \
--header "Content-type: application/json" | grep HTTP | awk {'print $2'}) --header "Content-type: application/json" | grep HTTP | awk {'print $2'})
@ -111,18 +141,14 @@ for ENDPOINT in ${ENDPOINTS[@]}; do
echo -e "\n 🍒 GET $BASE_URL/$ENDPOINT $ENDPOINT_STATUS" echo -e "\n 🍒 GET $BASE_URL/$ENDPOINT $ENDPOINT_STATUS"
[ "${ENDPOINT_STATUS}" == "200" ] && curl -s --location --request GET $BASE_URL/$ENDPOINT | head -c75 [ "${ENDPOINT_STATUS}" == "200" ] && curl -s --location --request GET $BASE_URL/$ENDPOINT | head -c75
echo echo
done done
echo echo
return 0
}
echo
echo -e "Relmember to check the settings for:"
echo -e " - Permissions"
echo -e " - Translations"
echo -e " - Aliases"
echo
function add_fields () { function add_fields () {
for FIELD in $(bash ./get-fields.sh ${SITE} node ${NODE});do for FIELD in $(bash ${SCRIPT_DIR}/get-fields.sh ${SITE} node ${NODE});do
FIELD_NAME=$(echo $FIELD | awk '{print $1}') FIELD_NAME=$(echo $FIELD | awk '{print $1}')
FIELD_TYPE=$(echo $FIELD | awk '{print $2}') FIELD_TYPE=$(echo $FIELD | awk '{print $2}')
echo echo
@ -136,3 +162,20 @@ function add_fields () {
done done
} }
if copy_template; then
if rename_info && rename_routing; then
if edit_files && file_permissions; then
if enable_module && test_module; then
add_fields
fi
fi
fi
fi
echo
echo -e "Relmember to check the settings for:"
echo -e " - Permissions"
echo -e " - Translations"
echo -e " - Aliases"
echo

View File

@ -62,7 +62,7 @@ class NodeController extends ControllerBase {
} }
/* Build the response */ /* Build the response */
$this->buildNodeResponse($lang, $alias, $nid) $this->buildNodeResponse($lang, $alias, $nid);
return new JsonResponse($this->response, $this->statusCode); return new JsonResponse($this->response, $this->statusCode);
} }

View File

@ -11,13 +11,13 @@
# #
IFS=$'\n' IFS=$'\n'
DIR=$1 SITE_DIR=$1
TYPE=$2 TYPE=$2
NAME=$3 NAME=$3
cd /var/www/sites/$DIR cd /var/www/sites/$SITE_DIR
for FIELD in $(vendor/drush/drush/drush fi ${TYPE} ${NAME} | tail -n +3 | grep -v '\-\-\-'); do for FIELD in $(../vendor/drush/drush/drush fi ${TYPE} ${NAME} | tail -n +3 | grep -v '\-\-\-'); do
NAME=$(echo $FIELD | awk '{print $1}') NAME=$(echo $FIELD | awk '{print $1}')
TYPE=$(echo $FIELD | awk '{print $2}') TYPE=$(echo $FIELD | awk '{print $2}')
COUNT=$(echo $TYPE | wc -c) COUNT=$(echo $TYPE | wc -c)