more good code
This commit is contained in:
parent
0abcd1cbc1
commit
61911396ea
20
endpoints/README.md
Normal file
20
endpoints/README.md
Normal 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
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ echo -e " 🍓 Found module ${B}endpoint_get_${NODE}${E}"
|
|||||||
../vendor/drush/drush/drush pml --fields=name,status > /tmp/.drush.pml
|
../vendor/drush/drush/drush pml --fields=name,status > /tmp/.drush.pml
|
||||||
cat /tmp/.drush.pml | grep -e "Enabled" | grep "endpoint_get_${NODE}"
|
cat /tmp/.drush.pml | grep -e "Enabled" | grep "endpoint_get_${NODE}"
|
||||||
if [ $? -eq 0 ];then
|
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}"
|
../vendor/drush/drush/drush pmu "endpoint_get_${NODE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@ -175,7 +175,7 @@ function add_fields () {
|
|||||||
# echo -e "DST_FILES :" ${DST_FILES}
|
# echo -e "DST_FILES :" ${DST_FILES}
|
||||||
# echo -e "DST_PATH :" ${DST_PATH}
|
# echo -e "DST_PATH :" ${DST_PATH}
|
||||||
|
|
||||||
for DST_FILE in ${DST_FILES}; do
|
for DST_FILE in ${DST_FILES[@]}; do
|
||||||
echo
|
echo
|
||||||
echo -en " 🍄 ${W}${DST_FILE}${E} : Add field ${B}${FIELD_TYPE}${E} with name ${B}${FIELD_NAME}${E}? [y/n] "
|
echo -en " 🍄 ${W}${DST_FILE}${E} : Add field ${B}${FIELD_TYPE}${E} with name ${B}${FIELD_NAME}${E}? [y/n] "
|
||||||
read -n 1 response
|
read -n 1 response
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
endpoint_get_AAAAA.node:
|
endpoint_get_AAAAA.node:
|
||||||
path: '/api/{lang}/AAAAAs/{alias}'
|
path: '/api/{lang}/AAAAA/{alias}'
|
||||||
defaults:
|
defaults:
|
||||||
_controller:
|
_controller:
|
||||||
'Drupal\endpoint_get_AAAAA\Controller\NodeController::getNode'
|
'Drupal\endpoint_get_AAAAA\Controller\NodeController::getNode'
|
||||||
|
|||||||
@ -12,8 +12,32 @@ use Drupal\Core\Url;
|
|||||||
use Drupal\media\Plugin\media\Source;
|
use Drupal\media\Plugin\media\Source;
|
||||||
use Drupal\media\Entity;
|
use Drupal\media\Entity;
|
||||||
use Drupal\node\Entity\Node;
|
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_CATEGORY = 'field_AAAAA_category'; // Editable
|
||||||
private const FIELD_SUBCATEGORY = 'field_AAAAA_subcategory'; // Editable
|
private const FIELD_SUBCATEGORY = 'field_AAAAA_subcategory'; // Editable
|
||||||
@ -36,7 +60,7 @@ class NodeController extends ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get unaliased path */
|
/* Get unaliased path */
|
||||||
$path_alias = '/'.$alias;
|
$path_alias = '/AAAAA/'.$alias;
|
||||||
$path = \Drupal::service('path_alias.repository')->lookupByAlias($path_alias, $lang);
|
$path = \Drupal::service('path_alias.repository')->lookupByAlias($path_alias, $lang);
|
||||||
|
|
||||||
/* Quit if path does not exist in drupal */
|
/* Quit if path does not exist in drupal */
|
||||||
@ -77,7 +101,7 @@ class NodeController extends ControllerBase {
|
|||||||
|
|
||||||
$this->response = [
|
$this->response = [
|
||||||
'code' => $this->statusCode,
|
'code' => $this->statusCode,
|
||||||
'alias' => $alias,
|
'alias' => '/AAAAA/'.$alias,
|
||||||
'nid' => $nid,
|
'nid' => $nid,
|
||||||
'author' => $name,
|
'author' => $name,
|
||||||
'title' => $node->get('title')->value,
|
'title' => $node->get('title')->value,
|
||||||
|
|||||||
@ -75,13 +75,13 @@ function delete_all() {
|
|||||||
|
|
||||||
function create_database() {
|
function create_database() {
|
||||||
mysql -u${DBUSER} -p${DBPASS} -e "create database $1"
|
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() {
|
function create_user() {
|
||||||
mysql -u${DBUSER} -p${DBPASS} -e "CREATE USER $1@localhost IDENTIFIED BY '1234'"
|
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"
|
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() {
|
function create_all() {
|
||||||
|
|||||||
@ -10,30 +10,64 @@ DBUSER="root"
|
|||||||
DBPASS="1234"
|
DBPASS="1234"
|
||||||
|
|
||||||
TAR=$1
|
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
|
[ $# -lt 1 ] && echo -e "Tarball argument is missing" && exit
|
||||||
[ $# -gt 1 ] && echo -e "Too many arWuments" && exit
|
[ $# -gt 1 ] && echo -e "Too many arguments" && exit
|
||||||
[ -d $NAME ] && echo -e "Directory $R$NAME$E already exist" && exit
|
[ -d ${NAME} ] && echo -e "Directory ${R}${NAME}${E} already exist" && exit
|
||||||
|
|
||||||
mysql -uroot -p1234 -e 'show databases' | grep "^${NAME}$" &> /dev/null
|
mysql -uroot -p1234 -e 'show databases' | grep "^${NAME}$" &> /dev/null
|
||||||
[ $? -eq 0 ] && echo -e "Database $R$NAME$E already exist" && exit
|
[ $? -eq 0 ] && echo -e "Database ${R}${NAME}${E} already exist" && exit
|
||||||
|
|
||||||
echo -ne " 🔎 Verify file"
|
|
||||||
bzip2 -tv $TAR
|
|
||||||
[ $? -ne 0 ] && "Cannot verify $TAR" && exit
|
|
||||||
|
|
||||||
|
|
||||||
function log() {
|
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}"
|
echo -e " ${R}[FAIL]${E}"
|
||||||
exit
|
exit
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
echo -ne " 📦 Extract tarball $TAR"
|
function verify_integrity() {
|
||||||
tar jxf $TAR
|
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 $?
|
log $?
|
||||||
|
|
||||||
|
extract_tarball $TAR
|
||||||
|
log $?
|
||||||
|
|
||||||
echo -ne " 🐬 Create database $NAME"
|
echo -ne " 🐬 Create database $NAME"
|
||||||
mysql -u${DBUSER} -p${DBPASS} -e "create database $NAME"
|
mysql -u${DBUSER} -p${DBPASS} -e "create database $NAME"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user