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
# 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
echo -n " 🌈 Cannot found module ${B}endpoint_get_${NODE}${E}"
echo -n " 🌈 Cannot find module ${B}endpoint_get_${NODE}${E}"
exit
fi
echo -e " 🍓 Found module ${B}endpoint_get_${NODE}${E}"
../vendor/drush/drush/drush cr
# 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
echo -n " 🍓 Disabling module ${B}endpoint_get_${NODE}${E}"
../vendor/drush/drush/drush pmu "endpoint_get_${NODE}"
../vendor/drush/drush/drush pml | grep "(endpoint_get_${NODE})"
fi
# if is not disabled, dont delete it
../vendor/drush/drush/drush pml | grep -e "Disabled" | grep "(endpoint_get_${NODE})" &> /dev/null
if [ $? -ne 0 ];then
echo -n " 🌈 Cannot deleting enabled module ${B}endpoint_get_${NODE}${E}"
../vendor/drush/drush/drush pml --fields=name,status > /tmp/.drush.pml
cat ./drush.pml | grep -e "Enabled" | grep "endpoint_get_${NODE}"
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
fi

View File

@ -6,6 +6,8 @@ B="\e[0;34m"
W="\e[0;97m"
E="\e[00m"
SCRIPT_PATH=$(realpath $0)
SCRIPT_DIR=$(dirname ${SCRIPT_PATH})
SOURCE="/root/dev/endpoints"
BASE_DIR="/var/www/sites"
MODULES="modules/custom"
@ -32,66 +34,94 @@ function quit() {
function log() {
[ $1 == 0 ] && echo -e " ${G}[ OK ]${E}"; return
echo -e " ${R}[FAIL]${E}"
exit
if [ $? -eq 0 ]; then
echo -e "${G}[ OK ]${E}"
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}"
}
# 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"
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"
mv "endpoint_get_AAAAA.routing.yml" "endpoint_get_${NODE}.routing.yml" &> /dev/null
log $?
}
# Edit files
function edit_files() {
echo
echo -en " ⭐ Edit ${B}endpoint_get_${NODE}.info.yml${E} file "
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 "
sed -i "s/AAAAA/${NODE}/g" "endpoint_get_${NODE}.routing.yml"
log $?
[ $? -ne 0 ] && return 1
echo -en " ⭐ Edit ${B}src/Controller/NodeController.php${E} file "
sed -i "s/AAAAA/${NODE}/g" "src/Controller/NodeController.php"
log $?
[ $? -ne 0 ] && return 1
echo -en " ⭐ Edit ${B}src/Controller/NodesController.php${E} file "
sed -i "s/AAAAA/${NODE}/g" "src/Controller/NodesController.php"
log $?
[ $? -ne 0 ] && return 1
echo -en " ⭐ Edit ${B}src/Controller/CategoryController.php${E} file "
sed -i "s/AAAAA/${NODE}/g" "src/Controller/CategoryController.php"
log $?
[ $? -ne 0 ] && return 1
return 0
}
function file_permissions() {
echo
# Filesystem
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
}
# Enable module
echo -e " 🌈 Enable module"
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
}
# Test endpoint
function test_module() {
BASE_URL="http://$(ls -l /var/www/ | grep ${SITE} | awk {'print $9'}).vm7"
API_URL="api/el"
NODE_URL="${BASE_URL}/${API_URL}/${NODE}"
@ -113,16 +143,12 @@ for ENDPOINT in ${ENDPOINTS[@]}; do
echo
done
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 () {
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_TYPE=$(echo $FIELD | awk '{print $2}')
echo
@ -136,3 +162,20 @@ function add_fields () {
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 */
$this->buildNodeResponse($lang, $alias, $nid)
$this->buildNodeResponse($lang, $alias, $nid);
return new JsonResponse($this->response, $this->statusCode);
}

View File

@ -11,13 +11,13 @@
#
IFS=$'\n'
DIR=$1
SITE_DIR=$1
TYPE=$2
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}')
TYPE=$(echo $FIELD | awk '{print $2}')
COUNT=$(echo $TYPE | wc -c)