diff --git a/endpoints/README.md b/endpoints/README.md new file mode 100644 index 0000000..87c994e --- /dev/null +++ b/endpoints/README.md @@ -0,0 +1,20 @@ +Naming node type + ++ Publication +- Publications + +Naming field + ++ image for single value ++ imaged for mutiple values + +Naming taxonomy + ++ article_category +> single value field +> in the url path + ++ article_subcategories +> multiple value field +> in url query + diff --git a/endpoints/endpoint-get-delete.sh b/endpoints/endpoint-get-delete.sh index d157fc9..d4c96b1 100755 --- a/endpoints/endpoint-get-delete.sh +++ b/endpoints/endpoint-get-delete.sh @@ -34,7 +34,7 @@ echo -e " 🍓 Found module ${B}endpoint_get_${NODE}${E}" ../vendor/drush/drush/drush pml --fields=name,status > /tmp/.drush.pml cat /tmp/.drush.pml | grep -e "Enabled" | grep "endpoint_get_${NODE}" if [ $? -eq 0 ];then - echo -n "\e 🍓 Disabling module ${B}endpoint_get_${NODE}${E}" + echo -n "\n 🍓 Disabling module ${B}endpoint_get_${NODE}${E}" ../vendor/drush/drush/drush pmu "endpoint_get_${NODE}" fi diff --git a/endpoints/endpoint-get.sh b/endpoints/endpoint-get.sh index bf94cb8..965cfc3 100755 --- a/endpoints/endpoint-get.sh +++ b/endpoints/endpoint-get.sh @@ -165,7 +165,7 @@ function add_fields () { for FIELD in $(bash ${SCRIPT_DIR}/get-fields.sh ${BASE_DIR}/${SITE_COMPOSER} node ${NODE}); do FIELD_NAME=$(echo $FIELD | awk '{print $1}') FIELD_TYPE=$(echo $FIELD | awk '{print $2}') - DST_FILES=("NodesController.php" "NodeController.php") + DST_FILES=( "NodesController.php" "NodeController.php" ) DST_PATH="${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}/src/Controller" # echo @@ -175,7 +175,7 @@ function add_fields () { # echo -e "DST_FILES :" ${DST_FILES} # echo -e "DST_PATH :" ${DST_PATH} - for DST_FILE in ${DST_FILES}; do + for DST_FILE in ${DST_FILES[@]}; do echo echo -en " 🍄 ${W}${DST_FILE}${E} : Add field ${B}${FIELD_TYPE}${E} with name ${B}${FIELD_NAME}${E}? [y/n] " read -n 1 response diff --git a/endpoints/endpoint_get_AAAAA/endpoint_get_AAAAA.routing.yml b/endpoints/endpoint_get_AAAAA/endpoint_get_AAAAA.routing.yml index f004b26..c07e1f1 100644 --- a/endpoints/endpoint_get_AAAAA/endpoint_get_AAAAA.routing.yml +++ b/endpoints/endpoint_get_AAAAA/endpoint_get_AAAAA.routing.yml @@ -1,5 +1,5 @@ endpoint_get_AAAAA.node: - path: '/api/{lang}/AAAAAs/{alias}' + path: '/api/{lang}/AAAAA/{alias}' defaults: _controller: 'Drupal\endpoint_get_AAAAA\Controller\NodeController::getNode' diff --git a/endpoints/endpoint_get_AAAAA/src/Controller/NodeController.php b/endpoints/endpoint_get_AAAAA/src/Controller/NodeController.php index 7469f7b..45479e0 100644 --- a/endpoints/endpoint_get_AAAAA/src/Controller/NodeController.php +++ b/endpoints/endpoint_get_AAAAA/src/Controller/NodeController.php @@ -12,8 +12,32 @@ use Drupal\Core\Url; use Drupal\media\Plugin\media\Source; use Drupal\media\Entity; use Drupal\node\Entity\Node; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\File\FileSystemInterface; +use Drupal\Core\File\FileUrlGeneratorInterface; +use Drupal\node\NodeInterface; +use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; -class NodeController extends ControllerBase { +class NodeController extends ControllerBase implements ContainerInjectionInterface { + + public static function create(ContainerInterface $container) { + return new static( + $container->get('entity_type.manager'), + $container->get('file_url_generator') + ); + } + + protected $entityTypeManager; + protected $fileUrlGenerator; + + public function __construct( + EntityTypeManagerInterface $entityTypeManager, + FileUrlGeneratorInterface $fileUrlGenerator + ) { + $this->entityTypeManager = $entityTypeManager; + $this->fileUrlGenerator = $fileUrlGenerator; + } private const FIELD_CATEGORY = 'field_AAAAA_category'; // Editable private const FIELD_SUBCATEGORY = 'field_AAAAA_subcategory'; // Editable @@ -36,7 +60,7 @@ class NodeController extends ControllerBase { } /* Get unaliased path */ - $path_alias = '/'.$alias; + $path_alias = '/AAAAA/'.$alias; $path = \Drupal::service('path_alias.repository')->lookupByAlias($path_alias, $lang); /* Quit if path does not exist in drupal */ @@ -77,7 +101,7 @@ class NodeController extends ControllerBase { $this->response = [ 'code' => $this->statusCode, - 'alias' => $alias, + 'alias' => '/AAAAA/'.$alias, 'nid' => $nid, 'author' => $name, 'title' => $node->get('title')->value, diff --git a/toolbox/db.sh b/toolbox/db.sh index 8ca5bae..1e562ef 100755 --- a/toolbox/db.sh +++ b/toolbox/db.sh @@ -39,7 +39,7 @@ function usage() { exit } -# List +# List function list_databases() { mysql -u${DBUSER} -p${DBPASS} -Nse 'show databases' | grep -Ev '(information_schema|mysql|performance_schema)' @@ -75,13 +75,13 @@ function delete_all() { function create_database() { mysql -u${DBUSER} -p${DBPASS} -e "create database $1" - echo -e "Database created: ${BOLDGRN}$(list_databases | grep $1)${END}" + echo -e "Database created: ${BOLDGRN}$(list_databases | grep -e ^${1}$)${END}" } function create_user() { mysql -u${DBUSER} -p${DBPASS} -e "CREATE USER $1@localhost IDENTIFIED BY '1234'" mysql -u${DBUSER} -p${DBPASS} -e "GRANT ALL ON $1.* TO $1@localhost" - echo -e "User created: ${BOLDGRN}$(list_users | grep $1)${END}" + echo -e "User created: ${BOLDGRN}$(list_users | grep -e ^${1}$)${END}" } function create_all() { @@ -159,6 +159,6 @@ do exit ;; esac -done +done usage diff --git a/toolbox/restore.sh b/toolbox/restore.sh index 87043a4..67a2264 100755 --- a/toolbox/restore.sh +++ b/toolbox/restore.sh @@ -10,30 +10,64 @@ DBUSER="root" DBPASS="1234" TAR=$1 -NAME=$(echo $TAR | awk -F\. '{print $1}') +NAME=$(echo $TAR | awk -F\. '{print $1}' | awk -F- '{print $1}') +echo -[ $# -lt 1 ] && echo -e "Tarball argWment is missing" && exit -[ $# -gt 1 ] && echo -e "Too many arWuments" && exit -[ -d $NAME ] && echo -e "Directory $R$NAME$E already exist" && exit +[ $# -lt 1 ] && echo -e "Tarball argument is missing" && exit +[ $# -gt 1 ] && echo -e "Too many arguments" && exit +[ -d ${NAME} ] && echo -e "Directory ${R}${NAME}${E} already exist" && exit mysql -uroot -p1234 -e 'show databases' | grep "^${NAME}$" &> /dev/null -[ $? -eq 0 ] && echo -e "Database $R$NAME$E already exist" && exit - -echo -ne " 🔎 Verify file" -bzip2 -tv $TAR -[ $? -ne 0 ] && "Cannot verify $TAR" && exit - +[ $? -eq 0 ] && echo -e "Database ${R}${NAME}${E} already exist" && exit function log() { - [ $1 == 0 ] && echo -e " ${G}[ OK ]${E}"; return - echo -e " ${R}[FAIL]${E}" - exit + if [ $1 == 0 ]; then + echo -e " ${G}[ OK ]${E}" + return 0 + else + echo -e " ${R}[FAIL]${E}" + exit + fi } -echo -ne " 📦 Extract tarball $TAR" -tar jxf $TAR +function verify_integrity() { + echo -ne " 🔎 Verify file $1" + if [[ "$1" =~ \.bz2$ ]]; then + bzip2 -tv $1 + return $? + fi + if [[ "$1" =~ \.gz$ ]]; then + gzip -t $1 + return $? + fi + if [[ "$1" =~ \.tar$ ]]; then + tar f $1 + return $? + fi + return 1 +} + +function extract_tarball() { + echo -ne " 📦 Extract tarball $1" + if [[ "$1" =~ \.bz2$ ]]; then + tar jxf $1 + return $? + fi + if [[ "$1" =~ \.gz$ ]]; then + tar zxf $1 + return $? + fi + if [[ "$1" =~ \.tar$ ]]; then + tar xf $1 + return $? + fi +} + +verify_integrity ${TAR} log $? +extract_tarball $TAR +log $? echo -ne " 🐬 Create database $NAME" mysql -u${DBUSER} -p${DBPASS} -e "create database $NAME"