Skip to content

Instantly share code, notes, and snippets.

View dchatry's full-sized avatar

Damien Chatry dchatry

View GitHub Profile
@dchatry
dchatry / gist:d3dd269ba7ef0819be33cf4acb9f2668
Created September 6, 2018 12:14
Allow more users on an already created git repository
// User have to be in the same group (apache for instance)
setfacl -R -m g:<whatever group>:rwX gitrepo
find gitrepo -type d | xargs setfacl -R -m d:g:<whatever group>:rwX
@dchatry
dchatry / drupal8-links.php
Created August 27, 2018 12:27 — forked from colorfield/drupal8-links.php
Drupal 8 links, or where is my l() function
@dchatry
dchatry / sync_cer_references.php
Created March 16, 2018 14:46
[Drupal 8] Sync CER References
# To be executed in a script or directly in Devel PHP console
$nids = \Drupal::entityQuery('node')->condition('type','YOUR_NODE_TYPE')->execute();
$nodes = \Drupal\node\Entity\Node::loadMultiple($nids);
foreach($nodes as $node) {
cer_sync_corresponding_references($node);
}
@dchatry
dchatry / backup.sh
Created February 5, 2018 16:58
Duplicate a Drupal instance for dev/test purposes (files + database)
#!/bin/bash
# Backup/duplicate a Drupal website and its database.
# Usage: sh backup.sh
# Prompt for website to backup.
read -p "Website directory to backup (/var/www/html/drupal): " WEBSITE_DIRECTORY
if [ -z "$WEBSITE_DIRECTORY" ]; then
WEBSITE_DIRECTORY="/var/www/html/drupal"
fi
@dchatry
dchatry / gist:9870be41131c29a740096cd65baccdc2
Created November 29, 2017 13:54
[Unix] How much bots crawled my website?
perl -lne 'print $& if /bot/' /var/log/httpd/access_log | wc -l
@dchatry
dchatry / menu_tree.inc
Last active January 25, 2017 14:20
[Drupal] Print menu tree to be imported in Taxonomy Manager
<?php
$tree = menu_tree_all_data('main-menu');
function _explore($trees) {
foreach($trees as $label => $sub) {
if($sub['link']['hidden'] != 1) {
$label = preg_replace('/[0-9]+/', '', $label);
print str_repeat('-', ($sub['link']['depth'] - 1)) . trim($label) . "<br />";
if(isset($sub['below'])) {
sudo du -d 1 -x -c -g /
@dchatry
dchatry / watchdog_backtrace.php
Created October 19, 2016 13:30
[Drupal] Watchdog backtrace
$backtrace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS);
$variables = array('@backtrace' => json_encode($backtrace, JSON_PRETTY_PRINT));
watchdog('MODULE', 'Things happend, here\'s a backtrace:<br><pre>@backtrace</pre>', $variables, WATCHDOG_ERROR);
@dchatry
dchatry / clean_string.php
Created August 30, 2016 09:01
[Drupal] Clean string
<?php
ctools_include('cleanstring');
$clean_string = ctools_cleanstring($string_to_clean);
?>
@dchatry
dchatry / cast_gdal
Created November 6, 2015 09:30
[Postgres/Postgis] Cast to varchar(255) to avoid GDAL default 80 char limit
CAST(text_column AS CHARACTER VARYING(255))