Skip to content

Instantly share code, notes, and snippets.

View dchatry's full-sized avatar

Damien Chatry dchatry

View GitHub Profile
@dchatry
dchatry / run_task.php
Last active November 5, 2015 14:57
[Rules scheduler] Run a specific task
$task = rules_scheduler_task_load([tid]);
rules_scheduler_run_task($task);
@dchatry
dchatry / redirect_from_node.php
Last active November 5, 2015 14:57
[Drupal] Redirection inside a node
function MODULE_node_view($node, $view_mode, $langcode) {
if ($view_mode == 'full' && node_is_page($node)) {
//It is safe to call drupal_goto() from here
}
}
@dchatry
dchatry / .htaccess
Last active November 5, 2015 14:57
[Drupal] Clean URL for files
# Clean URL for files in Drupal
#
# Replace : http://www.site.com/sites/default/files/myfile.txt
# by : http://www.site.com/files/myfile.txt
# Be careful to put this rule before any other blocking rule.
RewriteRule ^files/(.*)$ /sites/default/files/$1 [L]
@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))
@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 / 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);
sudo du -d 1 -x -c -g /
@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'])) {
@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 / 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