Skip to content

Instantly share code, notes, and snippets.

@jonhattan
jonhattan / migrate-one.sh
Last active February 1, 2024 14:19
[DRUPAL] Shell script to run a migration in chunks of 3k
ALIAS=@foo
MIGRATION=foo_news
LOG_FILE=/tmp/foo-migrate-logs/migration-foo_news.log
rm -f $LOG_FILE
date > $LOG_FILE
# Run migrations in chunks of 3000 items.
THRESHOLD=3000
TOTAL=$(COLUMNS=160 drush $ALIAS migrate-status $MIGRATION | tail -n 1 | awk '{print $3}')
@jonhattan
jonhattan / tmux.md
Last active March 9, 2018 11:03
tmux quickstart

tmux quickstart

$ tmux

CTRL+B C -> create new pane

CTRL+B [num] -> go to a pane

CTRL+D -> finish bash session, closes the pane. Closing all panes will destroy the window and thus the tmux

@jonhattan
jonhattan / example_ajax.php
Last active November 17, 2023 15:28
Drupal 8 - detect if we're in an ajax request, and if building the form for the first time, or re-building within the input processing.
<?php
use Drupal\Core\Form\FormStateInterface;
function example_ajax_form_alter() {
$ajax_form_request = \Drupal::request()->query->has(FormBuilderInterface::AJAX_FORM_REQUEST);
if ($ajax_form_request) {
if (!$form_state->isProcessingInput()) {
\Drupal::logger('example')->notice('first pass');
}
@jonhattan
jonhattan / drush-install.sh
Last active September 30, 2015 12:56
<strike>oneliner</strike> several-liner to install composer and drush system-wide
#!/bin/sh
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
COMPOSER_HOME=/opt/drush COMPOSER_BIN_DIR=/usr/local/bin COMPOSER_VENDOR_DIR=/opt/drush composer require drush/drush:7
cd /opt/drush/drush/drush/
composer install
@jonhattan
jonhattan / sb_surgery.drush.inc
Created September 29, 2015 18:46
Drush command to inspect cache config of blocks, views and panels
<?php
function sb_surgery_drush_command() {
$items = array();
$items['cache-status'] = array(
'description' => 'Show cache status for each block, view, panel or minipanel',
);
return $items;
}
@jonhattan
jonhattan / db_merge_example.php
Created March 3, 2015 14:32
db_merge() example
<?php
// Track # of places sold for an event. The event is addressed by $entity_id and $date.
// $quantity is a positive number of places sold or negative, if places are cancelled.
db_merge('places_sold')
->key(
array(
'entity_id' => $entity_id,
'date' => $date->format(DATE_FORMAT_DATE),
)
@jonhattan
jonhattan / gist:5384246f05cbb114dd65
Last active August 29, 2015 14:11
Sql to obtain views using php. #drupal
;; Select views using php
SELECT vd.vid, name, id FROM views_display vd LEFT JOIN views_view vv ON vd.vid=vv.vid WHERE display_options LIKE '%php%';
;; View php snippets
mysql DBNAME -e "SELECT vd.vid, name, id, display_options FROM views_display vd LEFT JOIN views_view vv ON vd.vid=vv.vid WHERE display_options LIKE '%php%' \G" | less
diff --git a/core/rebuild.php b/core/rebuild.php
index c915aff..f26eb6f 100644
--- a/core/rebuild.php
+++ b/core/rebuild.php
@@ -15,6 +15,9 @@
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpKernel\Event\GetResponseEvent;
+use Symfony\Component\HttpKernel\KernelEvents;
@jonhattan
jonhattan / bakupninja-handler-mysql
Last active August 29, 2015 14:01
Backupninja handler script for mysql. Declare in `nodata_any` the list of tables to exclude in all databases (if present).
# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
# vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
#
# mysql handler script for backupninja
#
getconf backupdir /var/backups/mysql
getconf databases all
getconf ignores
getconf nodata
@jonhattan
jonhattan / EXAMPLE.module
Created April 30, 2014 10:54
Example of a block with custom theme.
<?php
/**
* Implements hook_theme().
*/
function EXAMPLE_theme() {
$path = drupal_get_path('module', 'EXAMPLE');
$hooks = array(
'iu_license' => array(
'template' => 'iu-license',