Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Achraf Jeday achraf-jeday

🏠
Working from home
View GitHub Profile
@achraf-jeday
achraf-jeday / bash.sh
Created January 19, 2022 00:13
Curl inside loop
View bash.sh
set -B # enable brace expansion
for i in {1..200}; do
echo "Hello Hey $i"
curl --location --request POST 'http://dev.passwordlocker.loc/api/json/password' \
--header 'Accept: application/vnd.api+json' \
--header 'Content-type: application/vnd.api+json' \
--header 'X-CSRF-Token: Kbl6ZFLWvrPOtyD6EmULWcRsOMk3CH4WmSrLgPGExzU' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImMzNzhlYmEyNmU1NjcwYjYzMjM2YmE5NjljN2E5NzEyZTBmMGVlMzRlOGYwNzI0MmI5YzkzNGFiNmU1NjNhNWUyYzQ4ODYwNjkzNmUwNzg5In0.eyJhdWQiOiIwNzgwYWVkYy1jZWZhLTQ2MDMtODFiZi1hOWZkMzVjZDcwMmQiLCJqdGkiOiJjMzc4ZWJhMjZlNTY3MGI2MzIzNmJhOTY5YzdhOTcxMmUwZjBlZTM0ZThmMDcyNDJiOWM5MzRhYjZlNTYzYTVlMmM0ODg2MDY5MzZlMDc4OSIsImlhdCI6MTY0MjU1MDIwOSwibmJmIjoxNjQyNTUwMjA5LCJleHAiOjE2NDU1NTAyMDguOTU2ODI1LCJzdWIiOiIyIiwic2NvcGUiOlsiY3VzdG9tZXIiLCJhdXRoZW50aWNhdGVkIl19.qWaPozwNbJZyYHjVMbnrN7vB6PDgij5oLe6NmjYOpeZz6a1TwzMYXqtSbbDQuhBuNaihEaF4Xn4fJLzGgnhVled8ZgQrDBL72DknIuVkPMjaBkoMn5A05RaSmY-DreYVDUeKN_JOveQxDWHbBj98uY7pj0mmvm2T
View Get current user in drupal 8
get current user in drupal 8
Description: In drupal 7 we get the current user object by defining global $user but in drupal 8 this quite different. If you want to get current user object then follow below code.
$current_user = \Drupal::currentUser();
$uid = $current_user->id();
It returns user id of current user.
$user_mail = $current_user->getEmail();
It returns user email id.
@achraf-jeday
achraf-jeday / nginx.conf
Last active December 3, 2021 22:40
Nginx configuration for Drupal 9 without ssl (only http)
View nginx.conf
server {
listen 80;
listen [::]:80;
server_name dev.passwordlocker.loc;
index index.php index.html index.htm;
root /var/www/html/web;
@achraf-jeday
achraf-jeday / git-rebase.txt
Last active December 9, 2020 14:05
Git: git rebase and git -D
View git-rebase.txt
10225 gco develop
10226 git fetch --all
10227 git pull
10228 git branch -D feature/DevOps-Refonte-du-docker
10229 git fetch --all
10230 gco feature/DevOps-Refonte-du-docker
10232 git branch
10234 git rebase origin/develop
10236 git add composer.lock
10238 git rebase --continue
View hook_cron to run a migration periodically
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateMessage;
/**
* Implements hook_cron().
*/
function migrate_tools_cron() {
$manager = Drupal::service('plugin.manager.migration');
$migration_ids = ['drupal_planet_rss_importer'];
foreach ($migration_ids as $migration_id) {
View XML RSS Migration Drupal 8
id: drupal_planet_rss_importer
label: 'Import Drupal planet RSS feed'
status: true
source:
plugin: url
data_fetcher_plugin: http
urls: 'https://www.drupal.org/planet/rss.xml'
data_parser_plugin: simple_xml
@achraf-jeday
achraf-jeday / import.sh
Created June 16, 2020 08:44
Import local translation file in Drupal 8
View import.sh
drush locale-import file modules/custom/custom_opm/translations/custom_opm.fr.po
@achraf-jeday
achraf-jeday / Symfony.sh
Last active June 11, 2020 18:02
Symfony framework useful commands
View Symfony.sh
# Execute PHPUnit tests in Symfony:
vendor/bin/phpunit -d memory_limit=-1 --group active
# Execute php code sniffer for Symfony:
phpcs --standard=Symfony --extensions=php --ignore=node_modules,bower_components,vendor DemandeController.php
phpcbf --standard=Symfony --extensions=php --ignore=node_modules,bower_components,vendor DemandeController.php
# Execute console commands from the host with docker-compose:
docker-compose exec php php bin/console doctrine:schema:update --force
@achraf-jeday
achraf-jeday / MigrateOPMCommands.php
Created April 21, 2020 07:02
Progress bar Example: drush command drupal 8
View MigrateOPMCommands.php
<?php
namespace Drupal\migrate_opm\Commands;
use Drush\Commands\DrushCommands;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* A Drush commandfile.
@achraf-jeday
achraf-jeday / documents.php
Last active April 19, 2020 11:47
Generate a massive CSV file in PHP
View documents.php
<?php
$header = array('uid','name','pass','mail','status','created','access','login','timezone','language','init','users_roles','prenom','patronyme','autre_prenoms','civilite','date_naissance','lieu_naissance','nouveau_email','nom_usage');
$line = array('4509','altman.afchir@rfi.de','$S$DUOohSWRaHv5IZOpqAQHfFiKFOVBbyo9yogtOIMicsI0jVv8TMR3','altman.afchir@rfi.de','1','1479377985','1532625913','1532625913','Europe/Paris','fr','582d8441638a9@mail.fr','3','jérémy','lacroze','','mr','1991-03-01 00:00:00','enghien-les-bains','','');
$file = fopen("modules/custom/migrate_opm/data/user/usrs.csv","w");
fputcsv($file, $header);
for ($i = 2; $i <= 1500001; $i++) {
$line[0] = $i;