Skip to content

Instantly share code, notes, and snippets.

View achraf-jeday's full-sized avatar
🏠
Working from home

Achraf Jeday achraf-jeday

🏠
Working from home
View GitHub Profile
@achraf-jeday
achraf-jeday / Symfony.sh
Last active June 11, 2020 18:02
Symfony framework useful commands
# 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 / Postgres_useful_commands.txt
Last active April 20, 2020 01:58
Postgres useful commands
Connect to the Postgres server:
psql postgres postgres
Create a database:
CREATE DATABASE drupal_legacy;
Connect to a database:
\c drupal_legacy
List all tables:
@achraf-jeday
achraf-jeday / documents.php
Last active April 19, 2020 11:47
Generate a massive CSV file in 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;
@achraf-jeday
achraf-jeday / delete_content_entities.d8.php
Created April 7, 2020 15:38 — forked from Jaesin/delete_content_entities.d8.php
Delete all content entities in Drupal 8.
<?php
// Delete all nodes.
entity_delete_multiple('node', \Drupal::entityQuery('node')->execute());
// Delete all files.
entity_delete_multiple('file', \Drupal::entityQuery('file')->execute());
// Delete all taxonomy terms.
entity_delete_multiple('taxonomy_term', \Drupal::entityQuery('taxonomy_term')->execute());
@achraf-jeday
achraf-jeday / module.php
Created April 6, 2020 05:56 — forked from modcab/module.php
Drupal 8 - Get MIME type from file uri.
<?php
$mime = \Drupal::service('file.mime_type.guesser')->guess($uri);
@achraf-jeday
achraf-jeday / my_module.install
Last active March 2, 2020 14:15
Drupal 8: Log error messages programmatically in a custom module.
// Logs a notice
\Drupal::logger('my_module')->notice($message);
// Logs an error
\Drupal::logger('my_module')->error($message);
// Logs an info
\Drupal::logger('my_module')->info($message);
@achraf-jeday
achraf-jeday / PHP_CodeSniffer
Last active February 13, 2020 13:56
PHP_CodeSniffer phpcs How to install PHP_CodeSniffer and to check drupal code (.module)
To install PHP_CodeSniffer and to check drupal code type the following (composer is required system-wide):
First make sure you have the composer bin dir in your PATH. The default value is ~/.composer/vendor/bin/, but you can check the value that you need to use by running:
composer global config bin-dir --absolute
echo $PATH
PATH=$PATH:~/.composer/vendor/bin/
echo $PATH
Add the following to the /home/<user>/.profile file:
docker events&
Then run your failing docker run ... command. Then you should see something like the following on screen:
2015-12-22T15:13:05.503402713+02:00 xxxxxxxacd8ca86df9eac5fd5466884c0b42a06293ccff0b5101b5987f5da07d: (from xxx/xxx:latest) die
Then you can get the startup hex id from previous message or the output of the run command. Then you can use it with the logs command:
docker logs <copy the instance id from docker events messages on screen>
@achraf-jeday
achraf-jeday / docker4drupal.txt
Last active January 8, 2020 10:28
We are going to use composer to create a codebase with the latest version of Drupal 8.
We are going to use composer to create a codebase with the latest version of Drupal 8 or 7:
Drupal 8:
composer create-project drupal-composer/drupal-project:8.x-dev docker_drupal --stability dev --no-interaction
Drupal 7:
composer create-project drupal-composer/drupal-project:7.x-dev docker_drupal --no-interaction
Then we are going to clone the latest version of docker4drupal and remove the .git folder from it:
git clone git@github.com:wodby/docker4drupal.git docker_drupal_server
@achraf-jeday
achraf-jeday / drush.sh (Drupal 7)
Last active January 7, 2020 14:20
Drupal 7 drush commands.
drush fra -y
drush fr-all --force -y
drush fl
drush cc all
drush mmmff --all
drush rr
drush updb -y
drush uli