more code
This commit is contained in:
parent
84ae2f07e2
commit
e4a5ea0f99
@ -10,9 +10,35 @@ MODULES="modules/custom"
|
|||||||
[ ! -d ${SITE} ] && echo "Directory ${SITE} does not exist" && exit
|
[ ! -d ${SITE} ] && echo "Directory ${SITE} does not exist" && exit
|
||||||
[ -d ${SITE}/web ] && SITE=${SITE}/web
|
[ -d ${SITE}/web ] && SITE=${SITE}/web
|
||||||
|
|
||||||
echo -en " 🌈 Disable module ${B}bundle_${NODE}${E}"
|
|
||||||
cd /var/www/sites/${SITE}
|
cd /var/www/sites/${SITE}
|
||||||
../vendor/drush/drush/drush pmu "bundle_${NODE}"
|
echo
|
||||||
|
|
||||||
|
# if module does not exist
|
||||||
|
../vendor/drush/drush/drush pml | grep "(endpoint_get_${NODE})"
|
||||||
|
if [ $? -ne 0 ];then
|
||||||
|
echo -n " 🌈 Cannot found module ${B}endpoint_get_${NODE}${E}"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
echo -e " 🍓 Found module ${B}endpoint_get_${NODE}${E}"
|
||||||
|
|
||||||
|
# if is enabled, disable it
|
||||||
|
../vendor/drush/drush/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}"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# delete the damn thing
|
||||||
|
rm "/var/www/sites/${SITE}/modules/custom/endpoint_get_${NODE}" -rf
|
||||||
|
if [ $? -eq 0 ];then
|
||||||
|
echo -e " 🍓 Directory ${B}${SITE}/modules/custom/endpoint_get_${NODE}${E} deleted"
|
||||||
|
fi
|
||||||
|
|
||||||
echo -en " 📂 Delete directory ${B}${SITE}/modules/custom/bundle_${NODE}${E}"
|
|
||||||
rm "/var/www/sites/${SITE}/modules/custom/bundle_${NODE}" -rf
|
|
||||||
|
|||||||
@ -1,8 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
SITE=${1}
|
|
||||||
NODE=${2}
|
|
||||||
|
|
||||||
G="\e[0;32m"
|
G="\e[0;32m"
|
||||||
B="\e[0;34m"
|
B="\e[0;34m"
|
||||||
W="\e[0;97m"
|
W="\e[0;97m"
|
||||||
@ -12,10 +9,22 @@ SOURCE="/root/dev/endpoints"
|
|||||||
BASE_DIR="/var/www/sites"
|
BASE_DIR="/var/www/sites"
|
||||||
MODULES="modules/custom"
|
MODULES="modules/custom"
|
||||||
|
|
||||||
|
SITE=${1}
|
||||||
|
NODE=${2}
|
||||||
|
|
||||||
|
function quit() {
|
||||||
|
echo
|
||||||
|
echo -e "Syntax:"
|
||||||
|
echo -e "${W}./endpoint-get <drupal dir> <node type>${E}"
|
||||||
|
echo
|
||||||
|
echo -e "Example:"
|
||||||
|
echo -e "${W}./endpoint-get mysite4 events${E}"
|
||||||
|
echo
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
[ "$#" -lt 2 ] && echo "Argument missing" && exit
|
[ "$#" -lt 2 ] && echo "Argument missing" && quit
|
||||||
[ ! -d ${SITE} ] && echo "Directory ${SITE} does not exist" && exit
|
[ ! -d ${SITE} ] && echo "Directory ${SITE} does not exist" && quit
|
||||||
[ -d ${SITE}/web ] && SITE=${SITE}/web
|
[ -d ${SITE}/web ] && SITE=${SITE}/web
|
||||||
|
|
||||||
|
|
||||||
@ -32,9 +41,11 @@ echo
|
|||||||
echo -en " 📂 Copy template module dir to ${B}${SITE}${E}"
|
echo -en " 📂 Copy template module dir to ${B}${SITE}${E}"
|
||||||
cp -r "${SOURCE}/endpoint_get_AAAAA" "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}"
|
cp -r "${SOURCE}/endpoint_get_AAAAA" "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}"
|
||||||
log $?
|
log $?
|
||||||
|
echo
|
||||||
|
|
||||||
cd "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}"
|
cd "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}"
|
||||||
|
|
||||||
|
|
||||||
# Rename files
|
# Rename files
|
||||||
|
|
||||||
echo -en " 🍓 Rename ${B}endpoint_get_${NODE}.info.yml${E} file"
|
echo -en " 🍓 Rename ${B}endpoint_get_${NODE}.info.yml${E} file"
|
||||||
@ -46,7 +57,7 @@ mv "endpoint_get_AAAAA.routing.yml" "endpoint_get_${NODE}.routing.yml"
|
|||||||
log $?
|
log $?
|
||||||
|
|
||||||
# Edit files
|
# Edit files
|
||||||
|
echo
|
||||||
echo -en " ⭐ Edit ${B}endpoint_get_${NODE}.info.yml${E} file"
|
echo -en " ⭐ Edit ${B}endpoint_get_${NODE}.info.yml${E} file"
|
||||||
sed -i "s/AAAAA/${NODE}/g" "endpoint_get_${NODE}.info.yml"
|
sed -i "s/AAAAA/${NODE}/g" "endpoint_get_${NODE}.info.yml"
|
||||||
log $?
|
log $?
|
||||||
@ -66,29 +77,24 @@ log $?
|
|||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
# Filesystem
|
||||||
|
chown -R apache:apache "${BASE_DIR}/${SITE}/${MODULES}/endpoint_get_${NODE}"
|
||||||
|
|
||||||
|
|
||||||
exit
|
|
||||||
# Enable module
|
# Enable module
|
||||||
|
|
||||||
echo -e " 🌈 Enable module"
|
echo -e " 🌈 Enable module"
|
||||||
cd /var/www/sites/${SITE}
|
cd /var/www/sites/${SITE}
|
||||||
../vendor/drush/drush/drush en "endpoint_get_${NODE}"
|
../vendor/drush/drush/drush en "endpoint_get_${NODE}"
|
||||||
|
|
||||||
# Test endpoint
|
# Test endpoint
|
||||||
|
|
||||||
BASE_URL="http://$(ls -l /var/www/ | grep ${SITE} | awk {'print $9'}).vm7"
|
BASE_URL="http://$(ls -l /var/www/ | grep ${SITE} | awk {'print $9'}).vm7"
|
||||||
API_URL="api/el"
|
API_URL="api/el"
|
||||||
NODE_URL="${BASE_URL}/${API_URL}/${NODE}"
|
NODE_URL="${BASE_URL}/${API_URL}/${NODE}"
|
||||||
NODES_URL="${BASE_URL}/${API_URL}/${NODE}s"
|
NODES_URL="${BASE_URL}/${API_URL}/${NODE}s"
|
||||||
|
|
||||||
cat "endpoint-get-${NODE}.routing.yml" | grep path
|
|
||||||
|
|
||||||
# echo "BASE_URL :" ${BASE_URL}
|
|
||||||
# echo "API_URL :" ${API_URL}
|
|
||||||
# echo "NODE :" ${NODE}
|
|
||||||
# echo "NODE_URL :" ${NODE_URL}
|
|
||||||
# echo "NODEs_URL:" ${NODES_URL}
|
|
||||||
|
|
||||||
ENDPOINTS=(
|
ENDPOINTS=(
|
||||||
api/en/${NODE}s
|
api/en/${NODE}s
|
||||||
api/el/${NODE}s
|
api/el/${NODE}s
|
||||||
@ -97,7 +103,18 @@ ENDPOINTS=(
|
|||||||
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 " " $3'})
|
--header "Content-type: application/json" | grep HTTP | awk {'print $2'})
|
||||||
echo -e " 🍒 GET $ENDPOINT: $ENDPOINT_STATUS"
|
RESPONSE=$(curl -s --location --request GET $BASE_URL/$ENDPOINT | head -c100)
|
||||||
done
|
|
||||||
|
|
||||||
|
echo -e "\n 🍒 GET $BASE_URL/$ENDPOINT $ENDPOINT_STATUS"
|
||||||
|
[ "${ENDPOINT_STATUS}" == "200" ] && curl -s --location --request GET $BASE_URL/$ENDPOINT | head -c75
|
||||||
|
echo
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo -e "Relmember to check the settings for:"
|
||||||
|
echo -e " - Permissions"
|
||||||
|
echo -e " - Translations"
|
||||||
|
echo -e " - Aliases"
|
||||||
|
echo
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
endpoint_get_AAAAA.node:
|
endpoint_get_AAAAA.node:
|
||||||
path: '/api/{lang}/AAAAAs/{alias}'
|
path: '/api/{lang}/AAAAAs/{alias}'
|
||||||
defaults:
|
defaults:
|
||||||
_controller: 'Drupal\endpoint_get_AAAAA\Controller\NodeController::getNode'
|
_controller:
|
||||||
|
'Drupal\endpoint_get_AAAAA\Controller\NodeController::getNode'
|
||||||
methods: [GET]
|
methods: [GET]
|
||||||
requirements:
|
requirements:
|
||||||
_access: 'TRUE'
|
_access: 'TRUE'
|
||||||
@ -11,7 +12,8 @@ endpoint_get_AAAAA.node:
|
|||||||
endpoint_get_AAAAA.nodes:
|
endpoint_get_AAAAA.nodes:
|
||||||
path: '/api/{lang}/AAAAAs'
|
path: '/api/{lang}/AAAAAs'
|
||||||
defaults:
|
defaults:
|
||||||
_controller: 'Drupal\endpoint_get_AAAAA\Controller\NodesController::getNodes'
|
_controller:
|
||||||
|
'Drupal\endpoint_get_AAAAA\Controller\NodesController::getNodes'
|
||||||
methods: [GET]
|
methods: [GET]
|
||||||
requirements:
|
requirements:
|
||||||
_access: 'TRUE'
|
_access: 'TRUE'
|
||||||
@ -21,7 +23,8 @@ endpoint_get_AAAAA.nodes:
|
|||||||
# endpoint_get_AAAAA.categories:
|
# endpoint_get_AAAAA.categories:
|
||||||
# path: '/api/{lang}/AAAAAs/categories'
|
# path: '/api/{lang}/AAAAAs/categories'
|
||||||
# defaults:
|
# defaults:
|
||||||
# _controller: 'Drupal\endpoint_get_AAAAA\Controller\CategoryController::getCategories'
|
# _controller:
|
||||||
|
# 'Drupal\endpoint_get_AAAAA\Controller\CategoryController::getCategories'
|
||||||
# methods: [GET]
|
# methods: [GET]
|
||||||
# requirements:
|
# requirements:
|
||||||
# _access: 'TRUE'
|
# _access: 'TRUE'
|
||||||
@ -31,7 +34,8 @@ endpoint_get_AAAAA.nodes:
|
|||||||
# endpoint_get_AAAAA.nodes_category:
|
# endpoint_get_AAAAA.nodes_category:
|
||||||
# path: '/api/{lang}/AAAAAs/categories/{category}'
|
# path: '/api/{lang}/AAAAAs/categories/{category}'
|
||||||
# defaults:
|
# defaults:
|
||||||
# _controller: 'Drupal\endpoint_get_AAAAA\Controller\NodesController::getNodes'
|
# _controller:
|
||||||
|
# 'Drupal\endpoint_get_AAAAA\Controller\NodesController::getNodes'
|
||||||
# methods: [GET]
|
# methods: [GET]
|
||||||
# requirements:
|
# requirements:
|
||||||
# _access: 'TRUE'
|
# _access: 'TRUE'
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Drupal\bundle_article\Controller;
|
namespace Drupal\endpoint_get_AAAAA\Controller;
|
||||||
|
|
||||||
use Drupal\Core\Controller\ControllerBase;
|
use Drupal\Core\Controller\ControllerBase;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@ -14,19 +15,25 @@ class CategoryController extends ControllerBase {
|
|||||||
private array $response = [];
|
private array $response = [];
|
||||||
private int $statusCode = self::HTTP_OK;
|
private int $statusCode = self::HTTP_OK;
|
||||||
|
|
||||||
// MAIN
|
/*
|
||||||
|
*
|
||||||
|
* MAIN
|
||||||
|
*
|
||||||
|
*/
|
||||||
public function getCategories(Request $request, $lang) {
|
public function getCategories(Request $request, $lang) {
|
||||||
$this->response = [
|
$this->response = [
|
||||||
'code' => $this->statusCode,
|
'code' => $this->statusCode,
|
||||||
'lang' => $lang,
|
'lang' => $lang,
|
||||||
'categories' => $this->buildVocabulary($lang)];
|
'categories' => $this->buildVocabulary($lang)
|
||||||
|
];
|
||||||
return new JsonResponse($this->response, $this->statusCode);
|
return new JsonResponse($this->response, $this->statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// RESPONSE ARRAY
|
/*
|
||||||
|
*
|
||||||
|
* RESPONSE ARRAY
|
||||||
|
*
|
||||||
|
*/
|
||||||
private function buildVocabulary($lang): array {
|
private function buildVocabulary($lang): array {
|
||||||
$terms = $this->loadTerms($lang);
|
$terms = $this->loadTerms($lang);
|
||||||
$terms_response = [];
|
$terms_response = [];
|
||||||
@ -39,8 +46,11 @@ class CategoryController extends ControllerBase {
|
|||||||
return $terms_response;
|
return $terms_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RESPONSE ARRAY VALUES
|
/*
|
||||||
|
*
|
||||||
|
* RESPONSE ARRAY VALUES
|
||||||
|
*
|
||||||
|
*/
|
||||||
private function loadTerms($lang) {
|
private function loadTerms($lang) {
|
||||||
|
|
||||||
// All terms from the vocabulary
|
// All terms from the vocabulary
|
||||||
|
|||||||
@ -1,15 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Drupal\bundle_article\Controller;
|
namespace Drupal\endpoint_get_AAAAA\Controller;
|
||||||
use Drupal\Core\Controller\ControllerBase;
|
|
||||||
use Drupal\node\Entity\Node;
|
|
||||||
use Drupal\media\Plugin\media\Source;
|
|
||||||
use Drupal\media\Entity;
|
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Drupal\Core\Url;
|
use Drupal\Core\Controller\ControllerBase;
|
||||||
use Drupal\Core\Language\LanguageInterface;
|
use Drupal\Core\Language\LanguageInterface;
|
||||||
|
use Drupal\Core\Path\AliasManagerInterface;
|
||||||
use Drupal\Core\TempStore;
|
use Drupal\Core\TempStore;
|
||||||
|
use Drupal\Core\Url;
|
||||||
|
use Drupal\media\Plugin\media\Source;
|
||||||
|
use Drupal\media\Entity;
|
||||||
|
use Drupal\node\Entity\Node;
|
||||||
|
|
||||||
class NodeController extends ControllerBase {
|
class NodeController extends ControllerBase {
|
||||||
|
|
||||||
@ -22,42 +24,55 @@ class NodeController extends ControllerBase {
|
|||||||
private array $response = [];
|
private array $response = [];
|
||||||
private int $statusCode = self::HTTP_OK;
|
private int $statusCode = self::HTTP_OK;
|
||||||
|
|
||||||
/* Main */
|
/*
|
||||||
|
*
|
||||||
|
* Main
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
public function getNode(Request $request, $lang, $alias) {
|
public function getNode(Request $request, $lang, $alias) {
|
||||||
|
|
||||||
/* check if alias exist in path */
|
/* Quit if alias not exist in path */
|
||||||
if (empty($alias)) {
|
if (empty($alias)) {
|
||||||
$this->errorAliasMissing();
|
$this->errorAliasMissing();
|
||||||
return new JsonResponse($this->response, $this->statusCode);
|
return new JsonResponse($this->response, $this->statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if alias exist in drupal */
|
/* Get unaliased path */
|
||||||
$path_alias = '/'.$alias;
|
$path_alias = '/'.$alias;
|
||||||
$path = \Drupal::service('path_alias.manager')->getPathByAlias($path_alias);
|
$path = \Drupal::service('path_alias.repository')->lookupByAlias($path_alias, $lang);
|
||||||
if ( $path_alias == $path) {
|
|
||||||
$this->errorNodeNotExist($alias, $path);
|
/* Quit if path does not exist in drupal */
|
||||||
|
if (is_null($path)) {
|
||||||
|
$this->errorNodeNotExist($alias);
|
||||||
return new JsonResponse($this->response, $this->statusCode);
|
return new JsonResponse($this->response, $this->statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if node has translation */
|
/* Get the nid from unaliased path */
|
||||||
$nid = Url::fromUri('internal:' . $path_alias)->getRouteParameters()['node'];
|
$path = $path['path'];
|
||||||
|
$nid = explode('/',$path)[2];
|
||||||
|
|
||||||
|
/* Get the node */
|
||||||
$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
|
$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
|
||||||
|
|
||||||
|
/* Quit if node has no tranlation */
|
||||||
if (! $node->hasTranslation($lang)) {
|
if (! $node->hasTranslation($lang)) {
|
||||||
$this->errorTranslationNotExist($lang, $alias);
|
$this->errorTranslationNotExist($lang, $alias);
|
||||||
return new JsonResponse($this->response, $this->statusCode);
|
return new JsonResponse($this->response, $this->statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* build response */
|
/* Build the response */
|
||||||
$this->buildNodeResponse($lang, $alias);
|
$this->buildNodeResponse($lang, $alias, $nid)
|
||||||
return new JsonResponse($this->response, $this->statusCode);
|
return new JsonResponse($this->response, $this->statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Response */
|
/*
|
||||||
|
*
|
||||||
|
* Node Response
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
private function buildNodeResponse($lang, $alias) {
|
private function buildNodeResponse($lang, $alias, $nid) {
|
||||||
$path = \Drupal::service('path_alias.manager')->getPathByAlias($alias);
|
|
||||||
$nid = Url::fromUri('internal:/' . $path)->getRouteParameters()['node'];
|
|
||||||
$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid)->getTranslation($lang);
|
$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid)->getTranslation($lang);
|
||||||
|
|
||||||
/* user name */
|
/* user name */
|
||||||
@ -66,26 +81,32 @@ class NodeController extends ControllerBase {
|
|||||||
$name = $user->getDisplayName();
|
$name = $user->getDisplayName();
|
||||||
|
|
||||||
/* absolute urls for body inline images */
|
/* absolute urls for body inline images */
|
||||||
$base_url = Url::fromRoute('<current>')->setAbsolute()->toString();
|
// $base_url = Url::fromRoute('<current>')->setAbsolute()->toString();
|
||||||
$url_components = parse_url($base_url);
|
// $url_components = parse_url($base_url);
|
||||||
$domain = $url_components['scheme'].'://'.$url_components['host'].':'.$url_components['port'];
|
// $domain = $url_components['scheme'].'://'.$url_components['host'].':'.$url_components['port'];
|
||||||
$body = str_replace(
|
// $body = str_replace(
|
||||||
'/sites/default/',
|
// '/sites/default/',
|
||||||
$domain.'/sites/default/',
|
// $domain.'/sites/default/',
|
||||||
$node->get('body')->value
|
// $node->get('body')->value
|
||||||
);
|
// );
|
||||||
|
|
||||||
|
// $manager = '';
|
||||||
|
// if ($node->hasField('manager') && !$node->get('manager')->isEmpty()) {
|
||||||
|
// $manager = $node->get('manager')->value;
|
||||||
|
// }
|
||||||
|
|
||||||
$this->response = [
|
$this->response = [
|
||||||
'code' => $this->statusCode,
|
'code' => $this->statusCode,
|
||||||
'alias' => $alias,
|
'alias' => $alias,
|
||||||
'path' => $path,
|
// 'path' => $path,
|
||||||
'nid' => $nid,
|
'nid' => $nid,
|
||||||
'title' => $node->get('title')->value,
|
|
||||||
'body' => $body,
|
|
||||||
'lang' => $node->get('langcode')->value,
|
|
||||||
'alias' => $node->get('path')->alias,
|
|
||||||
'created' => $node->get('created')->value,
|
|
||||||
'author' => $name,
|
'author' => $name,
|
||||||
|
'title' => $node->get('title')->value,
|
||||||
|
// 'manager' => $manager,
|
||||||
|
// 'body' => $node->get('body')->value,
|
||||||
|
// 'body' => $body,
|
||||||
|
// 'lang' => $node->get('langcode')->value,
|
||||||
|
// 'alias' => $node->get('path')->alias,
|
||||||
// 'files' => $this->getFiles($node, 'field_file'),
|
// 'files' => $this->getFiles($node, 'field_file'),
|
||||||
// 'images' => $this->getImages($node, 'field_image'),
|
// 'images' => $this->getImages($node, 'field_image'),
|
||||||
// 'category' => (
|
// 'category' => (
|
||||||
@ -97,11 +118,16 @@ class NodeController extends ControllerBase {
|
|||||||
// $node->currentTranslation
|
// $node->currentTranslation
|
||||||
// )->getName():'',
|
// )->getName():'',
|
||||||
// 'subcategory' => $this->getTerms($node, self::FIELD_SUBCATEGORY)
|
// 'subcategory' => $this->getTerms($node, self::FIELD_SUBCATEGORY)
|
||||||
|
'created' => $node->get('created')->value
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Multiple value fields */
|
/*
|
||||||
|
*
|
||||||
|
* Multiple value fields
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
// private function getTerms(Node $node, string $field): array {
|
// private function getTerms(Node $node, string $field): array {
|
||||||
// $terms = $node->get($field)->referencedEntities();
|
// $terms = $node->get($field)->referencedEntities();
|
||||||
@ -143,13 +169,17 @@ class NodeController extends ControllerBase {
|
|||||||
// return $uris;
|
// return $uris;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/* Error functions */
|
/*
|
||||||
|
*
|
||||||
|
* Error functions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
private function errorNodeNotExist($alias, $path) {
|
private function errorNodeNotExist($alias) {
|
||||||
$this->statusCode = self::HTTP_NOT_FOUND;
|
$this->statusCode = self::HTTP_NOT_FOUND;
|
||||||
$this->response = [
|
$this->response = [
|
||||||
'code' => $this->statusCode,
|
'code' => $this->statusCode,
|
||||||
"message" => "Node with alias " . $alias . " does not exist." . $path
|
"message" => "Node with alias " . $alias . " does not exist."
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,25 +21,27 @@ class NodesController extends ControllerBase {
|
|||||||
* Value : single ID of field_article_category value
|
* Value : single ID of field_article_category value
|
||||||
* Url : optional URL argument - single value
|
* Url : optional URL argument - single value
|
||||||
* Example : /api/en/articles/1234
|
* Example : /api/en/articles/1234
|
||||||
*/
|
*/
|
||||||
// private const FIELD_CATEGORY = 'field_AAAAA_category'; // Editable
|
private const FIELD_CATEGORY = 'field_AAAAA_category'; // Editable
|
||||||
|
|
||||||
/* Used for : Taxonomy reference field
|
/* Used for : Taxonomy reference field
|
||||||
* Value : multiple ID's of field_article_subcategory values
|
* Value : multiple ID's of field_article_subcategory values
|
||||||
* Url : optional URL query params - accept multiple values
|
* Url : optional URL query params - accept multiple values
|
||||||
* Example : /api/en/articles/1234?subcategory=55,66,77
|
* Example : /api/en/articles/1234?subcategory=55,66,77
|
||||||
*/
|
*/
|
||||||
// private const FIELD_SUBCATEGORY = 'field_AAAAA_subcategory'; // Editable
|
private const FIELD_SUBCATEGORY = 'field_AAAAA_subcategory'; // Editable
|
||||||
|
|
||||||
private const HTTP_BAD_REQUEST = 400;
|
private const HTTP_BAD_REQUEST = 400;
|
||||||
private const HTTP_NOT_FOUND = 404;
|
private const HTTP_NOT_FOUND = 404;
|
||||||
private const HTTP_OK = 200;
|
private const HTTP_OK = 200;
|
||||||
|
|
||||||
private array $response = [];
|
private array $response = [];
|
||||||
private int $statusCode = self::HTTP_OK;
|
private int $statusCode = self::HTTP_OK;
|
||||||
|
|
||||||
/* Main */
|
/*
|
||||||
|
*
|
||||||
|
* Main
|
||||||
|
*
|
||||||
|
*/
|
||||||
public function getNodes(Request $request, $lang, $category = 'all') {
|
public function getNodes(Request $request, $lang, $category = 'all') {
|
||||||
$nodes = $this->loadNodes($request, $lang, $category);
|
$nodes = $this->loadNodes($request, $lang, $category);
|
||||||
$nodes_response = $this->buildNodes($nodes, $lang, $category);
|
$nodes_response = $this->buildNodes($nodes, $lang, $category);
|
||||||
@ -52,8 +54,11 @@ class NodesController extends ControllerBase {
|
|||||||
return new JsonResponse($this->response, $this->statusCode);
|
return new JsonResponse($this->response, $this->statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Response List */
|
/*
|
||||||
|
*
|
||||||
|
* Response List
|
||||||
|
*
|
||||||
|
*/
|
||||||
private function buildNodes(array $nodes, $lang): array {
|
private function buildNodes(array $nodes, $lang): array {
|
||||||
$nodes_response = [];
|
$nodes_response = [];
|
||||||
foreach ($nodes as $node) {
|
foreach ($nodes as $node) {
|
||||||
@ -107,10 +112,9 @@ class NodesController extends ControllerBase {
|
|||||||
|
|
||||||
if ($published == 1) {
|
if ($published == 1) {
|
||||||
$nodes_response[] = [
|
$nodes_response[] = [
|
||||||
'id' => $node->id(),
|
'id' => intval($node->id()),
|
||||||
'title' => $node->getTitle(),
|
'title' => $node->getTitle(),
|
||||||
'lang' => $node->get('langcode')->value,
|
'lang' => $node->get('langcode')->value,
|
||||||
'created' => $node->get('created')->value,
|
|
||||||
'alias' => $node->get('path')->alias,
|
'alias' => $node->get('path')->alias,
|
||||||
'author' => $name,
|
'author' => $name,
|
||||||
// 'field_geolocation' => $field_geolocation,
|
// 'field_geolocation' => $field_geolocation,
|
||||||
@ -135,6 +139,7 @@ class NodesController extends ControllerBase {
|
|||||||
// $node->currentTranslation
|
// $node->currentTranslation
|
||||||
// )->getName():'',
|
// )->getName():'',
|
||||||
// 'subcategory' => $this->getTerms($node, self::FIELD_SUBCATEGORY)
|
// 'subcategory' => $this->getTerms($node, self::FIELD_SUBCATEGORY)
|
||||||
|
'created' => $node->get('created')->value
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,8 +147,11 @@ class NodesController extends ControllerBase {
|
|||||||
return $nodes_response;
|
return $nodes_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Multivalue fields */
|
/*
|
||||||
|
*
|
||||||
|
* Multivalue fields
|
||||||
|
*
|
||||||
|
*/
|
||||||
// private function getTerms(Node $node, string $field): array {
|
// private function getTerms(Node $node, string $field): array {
|
||||||
// $terms = $node->get($field)->referencedEntities();
|
// $terms = $node->get($field)->referencedEntities();
|
||||||
// $response = [];
|
// $response = [];
|
||||||
@ -184,22 +192,25 @@ class NodesController extends ControllerBase {
|
|||||||
// return $uris;
|
// return $uris;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/* get response data */
|
/*
|
||||||
|
*
|
||||||
|
* get response nodes
|
||||||
|
*
|
||||||
|
*/
|
||||||
private function loadNodes($request, $lang, $category) {
|
private function loadNodes($request, $lang, $category) {
|
||||||
|
|
||||||
/* build query for nodes */
|
/* build the query for nodes */
|
||||||
$query = \Drupal::entityTypeManager()
|
$query = \Drupal::entityTypeManager()
|
||||||
->getStorage('node')
|
->getStorage('node')
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->accessCheck(false);
|
->accessCheck(false);
|
||||||
|
|
||||||
/* category is a URL parameter, matched with a taxonomy field */
|
/* if category exist as URL parameter, create a query condition */
|
||||||
if ($category != 'all'){
|
if ($category != 'all'){
|
||||||
$query->condition(self::FIELD_CATEGORY, $category);
|
$query->condition(self::FIELD_CATEGORY, $category);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add subcategory URL query filter, matched with a taxonomy field */
|
/* if subcategory exist as URL query, create the query condition */
|
||||||
if ($request->query->get('subcategory')){
|
if ($request->query->get('subcategory')){
|
||||||
$or_group = $query->orConditionGroup();
|
$or_group = $query->orConditionGroup();
|
||||||
$terms = explode(',', $request->query->get('subcategory'));
|
$terms = explode(',', $request->query->get('subcategory'));
|
||||||
@ -259,7 +270,6 @@ class NodesController extends ControllerBase {
|
|||||||
$node->currentTranslation = $lang;
|
$node->currentTranslation = $lang;
|
||||||
}
|
}
|
||||||
return $nodeList;
|
return $nodeList;
|
||||||
|
|
||||||
}
|
}
|
||||||
// \Drupal::logger('Bundle AAAAA')->notice(''.$some_var);
|
// \Drupal::logger('Bundle AAAAA')->notice(''.$some_var);
|
||||||
}
|
}
|
||||||
|
|||||||
24
endpoints/info-fields.sh
Executable file
24
endpoints/info-fields.sh
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
IFS=$'\n'
|
||||||
|
DIR=$1
|
||||||
|
TYPE=$2
|
||||||
|
NAME=$3
|
||||||
|
|
||||||
|
cd $DIR
|
||||||
|
|
||||||
|
for FIELD in $(vendor/drush/drush/drush fi ${TYPE} ${NAME} | tail -n +3 | grep -v '\-\-\-'); do
|
||||||
|
NAME=$(echo $FIELD | awk '{print $1}')
|
||||||
|
SECOND=$(echo $FIELD | awk '{print $2}')
|
||||||
|
THIRD=$(echo $FIELD | awk '{print $3}')
|
||||||
|
COUNT=$(echo $SECOND | wc -c)
|
||||||
|
|
||||||
|
if [ "$COUNT" -gt 5 ]; then
|
||||||
|
TYPE=$SECOND
|
||||||
|
else
|
||||||
|
TYPE=$THIRD
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$NAME $TYPE"
|
||||||
|
done
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ function log() {
|
|||||||
echo -e "`date +'%d/%m/%Y %H:%M:%S'` ${1}" >> $LOG
|
echo -e "`date +'%d/%m/%Y %H:%M:%S'` ${1}" >> $LOG
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# database - get credentials
|
# database - get credentials
|
||||||
#
|
#
|
||||||
function get_db_credentials() {
|
function get_db_credentials() {
|
||||||
@ -35,7 +35,7 @@ function get_db_credentials() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# database - verify credentials
|
# database - verify credentials
|
||||||
#
|
#
|
||||||
function verify_db_credentials() {
|
function verify_db_credentials() {
|
||||||
@ -50,7 +50,7 @@ function verify_db_credentials() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# database - export data
|
# database - export data
|
||||||
#
|
#
|
||||||
function export_db() {
|
function export_db() {
|
||||||
@ -79,18 +79,24 @@ function check_path() {
|
|||||||
# Create tarball
|
# Create tarball
|
||||||
#
|
#
|
||||||
function create_tarball() {
|
function create_tarball() {
|
||||||
log "Create backup-${DIR}.tar.gz"
|
log "Create ${DIR}-backup.tar.gz"
|
||||||
tar -czpf "backup-${DIR}.tar.gz" "${DIR}" "${DIR}.sql"
|
tar -czpf "${DIR}-backup.tar.gz" "${DIR}" "${DIR}.sql"
|
||||||
[ $? -ne 0 ] && return 1
|
[ $? -ne 0 ] && return 1
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Create checksum
|
||||||
|
#
|
||||||
function create_checksum() {
|
function create_checksum() {
|
||||||
log "Create backup-${DIR}-md5sum checksum"
|
log "Create ${DIR}-backup.md5sum checksum"
|
||||||
CHECKSUM=$(md5sum backup-${DIR}.tar.gz | awk '{print $1}' )
|
CHECKSUM=$(md5sum ${DIR}-backup.tar.gz | awk '{print $1}' )
|
||||||
echo ${CHECKSUM} > "backup-${DIR}.md5sum"
|
echo ${CHECKSUM} > "${DIR}-backup.md5sum"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Start
|
||||||
|
#
|
||||||
function main () {
|
function main () {
|
||||||
if check_path; then
|
if check_path; then
|
||||||
if get_db_credentials; then
|
if get_db_credentials; then
|
||||||
@ -110,5 +116,13 @@ function main () {
|
|||||||
|
|
||||||
main
|
main
|
||||||
|
|
||||||
ls -lh backup-${DIR}.tar.gz --color=auto
|
#
|
||||||
ls -lh backup-${DIR}.md5sum --color=auto
|
# Show results
|
||||||
|
#
|
||||||
|
echo
|
||||||
|
ls -lh ${DIR}-backup.tar.gz --color=auto
|
||||||
|
ls -lh ${DIR}-backup.md5sum --color=auto
|
||||||
|
echo
|
||||||
|
echo -e " MD5 checksum: $(cat ${DIR}-backup.md5sum)"
|
||||||
|
echo
|
||||||
|
|
||||||
|
|||||||
@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
df -h | awk 'NR==1 || /\/$/'
|
df -h | awk 'NR==1 || /\/$/'
|
||||||
|
|
||||||
rm -rf $1
|
[ -d "${1}" ] && ls -1 | grep -E "^${1}$" | xargs rm -rf
|
||||||
rm -r $1.sql
|
|
||||||
rm -r $1.info
|
[ -f $1.sql ] && rm -r $1.sql
|
||||||
rm -r $1.copy.log
|
[ -f $1.info ] && rm -r $1.info
|
||||||
rm -r $1.composer.log
|
[ -f $1.copy.log ] && rm -r $1.copy.log
|
||||||
rm -r $1.settings.php
|
[ -f $1.composer.log ] && rm -r $1.composer.log
|
||||||
|
[ -f $1.settings.log ] && rm -r $1.settings.log
|
||||||
|
|
||||||
./db -du $1
|
./db -du $1
|
||||||
./db -dd $1
|
./db -dd $1
|
||||||
|
|||||||
@ -32,11 +32,14 @@ function fail() {
|
|||||||
|
|
||||||
echo
|
echo
|
||||||
echo -ne " 💧 Create new drupal in dir ${WHT}$NAME${END} ..."
|
echo -ne " 💧 Create new drupal in dir ${WHT}$NAME${END} ..."
|
||||||
composer --no-interaction create-project drupal/recommended-project $NAME
|
composer --no-interaction create-project drupal/recommended-project $NAME
|
||||||
|
# CMD="composer --no-interaction create-project drupal/recommended-project $NAME"
|
||||||
|
# sudo su -l apache -s /bin/bash -c "$CMD"
|
||||||
|
# sudo su -l apache -s /bin/bash -c "cd $PWD; $CMD"
|
||||||
|
|
||||||
# composer --no-interaction create-project drupal/recommended-project:9.5.10 $NAME > /dev/null 2>&1
|
# composer --no-interaction create-project drupal/recommended-project:9.5.10 $NAME > /dev/null 2>&1
|
||||||
#CMD="composer --no-interaction create-project drupal/recommended-project:9 $NAME > /dev/null 2>&1"
|
#CMD="composer --no-interaction create-project drupal/recommended-project:9 $NAME > /dev/null 2>&1"
|
||||||
#CMD="composer create-project drupal/recommended-project:9 $NAME"
|
#CMD="composer create-project drupal/recommended-project:9 $NAME"
|
||||||
#sudo su -l apache -s /bin/bash -c "cd $PWD; $CMD"
|
|
||||||
if [ $? = 0 ]; then ok; else fail; fi
|
if [ $? = 0 ]; then ok; else fail; fi
|
||||||
|
|
||||||
echo -ne " 🐬 Create database ${WHT}$NAME${END} ..."
|
echo -ne " 🐬 Create database ${WHT}$NAME${END} ..."
|
||||||
@ -55,8 +58,9 @@ echo -ne " 🐬 Flush privilages ..."
|
|||||||
mysql -uroot -p1234 -e "FLUSH PRIVILEGES"
|
mysql -uroot -p1234 -e "FLUSH PRIVILEGES"
|
||||||
if [ $? = 0 ]; then ok; else fail; fi
|
if [ $? = 0 ]; then ok; else fail; fi
|
||||||
|
|
||||||
# echo -ne " 🍒 Drupal settings.php"
|
echo -ne " 🍒 Drupal settings.php"
|
||||||
# cd $NAME/web
|
cd $NAME/web
|
||||||
|
|
||||||
# cp sites/default/default.settings.php sites/default/settings.php
|
# cp sites/default/default.settings.php sites/default/settings.php
|
||||||
# cat >> sites/default/settings.php <<EOL
|
# cat >> sites/default/settings.php <<EOL
|
||||||
# \$databases['default']['default'] = array (
|
# \$databases['default']['default'] = array (
|
||||||
@ -70,12 +74,10 @@ if [ $? = 0 ]; then ok; else fail; fi
|
|||||||
# 'driver' => 'mysql',
|
# 'driver' => 'mysql',
|
||||||
# 'autoload' => 'core/modules/mysql/src/Driver/Database/mysql/',
|
# 'autoload' => 'core/modules/mysql/src/Driver/Database/mysql/',
|
||||||
# );
|
# );
|
||||||
|
|
||||||
# EOL
|
# EOL
|
||||||
# if [ $? = 0 ]; then ok; else fail; fi
|
# if [ $? = 0 ]; then ok; else fail; fi
|
||||||
|
|
||||||
echo -ne " 🐷 Change files owner to user ${WHT}apache${END}"
|
echo -ne " 🐷 Change files owner to user ${WHT}apache${END}"
|
||||||
cd $NAME/web
|
|
||||||
mkdir sites/default/files
|
mkdir sites/default/files
|
||||||
cd ../..
|
cd ../..
|
||||||
chown apache:apache $NAME -R
|
chown apache:apache $NAME -R
|
||||||
@ -83,13 +85,15 @@ find $NAME -type d -exec chmod 755 {} \;
|
|||||||
find $NAME -type f -exec chmod 644 {} \;
|
find $NAME -type f -exec chmod 644 {} \;
|
||||||
if [ $? = 0 ]; then ok; else fail; fi
|
if [ $? = 0 ]; then ok; else fail; fi
|
||||||
|
|
||||||
#echo -ne " 🍒 link html to ${WHT}$NAME${END}"
|
|
||||||
#unlink /var/www/html
|
|
||||||
#ln -s /var/www/sites/$NAME/web /var/www/html
|
#echo -ne " 🍒 link html to ${WHT}$NAME${END}"
|
||||||
#if [ $? = 0 ]; then ok; else fail; fi
|
#unlink /var/www/html
|
||||||
|
#ln -s /var/www/sites/$NAME/web /var/www/html
|
||||||
|
#if [ $? = 0 ]; then ok; else fail; fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
ls -l --color=auto /var/www/site[1234]
|
ls -l --color=auto /var/www/site[1234567890]
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# echo -ne " 🌈 Restart httpd "
|
# echo -ne " 🌈 Restart httpd "
|
||||||
@ -113,7 +117,6 @@ echo -e "Password: 1234"
|
|||||||
echo
|
echo
|
||||||
read -p "...and press [ENTER] to continue installing extra modules"
|
read -p "...and press [ENTER] to continue installing extra modules"
|
||||||
echo
|
echo
|
||||||
exit
|
|
||||||
|
|
||||||
echo -e "🍓"
|
echo -e "🍓"
|
||||||
|
|
||||||
@ -152,9 +155,9 @@ echo
|
|||||||
#composer require 'drupal/rest_entity_recursive:^2.0@RC'
|
#composer require 'drupal/rest_entity_recursive:^2.0@RC'
|
||||||
|
|
||||||
# Devel
|
# Devel
|
||||||
composer require 'drupal/devel'
|
# composer require 'drupal/devel'
|
||||||
rm -rf vendor/autoload.php vendor/autoload_runtime.php vendor/composer
|
# rm -rf vendor/autoload.php vendor/autoload_runtime.php vendor/composer
|
||||||
composer install
|
# composer install
|
||||||
drush cr
|
# drush cr
|
||||||
drush en devel_generate
|
# drush en devel_generate
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user