more good code

This commit is contained in:
Ste Vaidis 2024-03-28 12:58:52 +02:00
parent 0abcd1cbc1
commit 61911396ea
7 changed files with 104 additions and 26 deletions

20
endpoints/README.md Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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,

View File

@ -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() {

View File

@ -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
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"