Skip to content

Instantly share code, notes, and snippets.

View QuentinFonteneau's full-sized avatar
🎯
Focusing

Quentin Fonteneau QuentinFonteneau

🎯
Focusing
View GitHub Profile
<?php
// For some queries, use `$query->sqlQuery->` instead of `$query->`.
str_replace(['{', '}'], ['', ''], str_replace(array_keys($query->getArguments()), array_values($query->getArguments()), $query->__toString()));
@QuentinFonteneau
QuentinFonteneau / script.sh
Created June 17, 2019 12:35
Drush generate salt hash
drush eval "var_dump(Drupal\Component\Utility\Crypt::randomBytesBase64(55))"
@QuentinFonteneau
QuentinFonteneau / script.sh
Created June 14, 2019 08:03
Drush exécuter un hook_update spécifique
drush eval "module_load_install('module_name'); module_name_update_XXXX();"
@QuentinFonteneau
QuentinFonteneau / script.sh
Last active June 13, 2019 07:13
Drush export/import database
drush sql-dump --gzip --result-file=../backup/dump_db_$(date +%Y%m%d-%H%M%S).sql.gz
gunzip -c dump.sql.gz | drush sqlc
@QuentinFonteneau
QuentinFonteneau / gist:a61d8b05c2452a0258e434d722f1f6e6
Created February 21, 2019 14:08
Duplicate git repo (and keep history)
create an empty repo on GitHub
git remote add github https://yourLogin@github.com/yourLogin/yourRepoName.git
git push --mirror github
@QuentinFonteneau
QuentinFonteneau / drupal8.php
Last active September 19, 2018 08:38
[Drupal 8] Get config from settings.php
// In your settings.php (or custom_settings.php)
$config['system.maintenance']['message']['sorry'] = 'Sorry, our site is down now.';
// To retrieve this config in PHP, do this :
\Drupal::config('system.maintenance')->get('message')['sorry'];
SELECT concat('DROP TABLE IF EXISTS `', table_name, '`;')
FROM information_schema.tables
WHERE table_schema = 'MyDatabaseName';
@QuentinFonteneau
QuentinFonteneau / getComposer.sh
Created March 26, 2018 17:28
Get composer and install it directly in right dir with right name
#!/bin/bash
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --filename=composer --install-dir=/usr/local/bin
php -r "unlink('composer-setup.php');"
@QuentinFonteneau
QuentinFonteneau / crop-automatically.php
Last active March 22, 2018 10:31
Generate crop automatically
/**
* This function will generate crop automatically.
*
* This makes it possible to generate the crops automatically
* if the contributor forgets to do so.
*/
function _generate_crop_auto($form, $form_state) {
// Retrieve crop list.
$crop_list = $form['field_image']['widget'][0]['image_crop']['#crop_type_list'];
foreach ($crop_list as $crop) {
@QuentinFonteneau
QuentinFonteneau / flush-image-style.php
Created January 19, 2018 13:26
Flush all image styles in Drupal 8
$imageStyle = \Drupal::entityTypeManager()->getStorage('image_style');
$styles = $imageStyle->loadMultiple();
foreach ($styles as $style) {
$imageStyle->load($style->get('name'))->flush();
}