Skip to content

Instantly share code, notes, and snippets.

View angry-dan's full-sized avatar

Dan James angry-dan

  • Kent, United Kingdom
View GitHub Profile
@angry-dan
angry-dan / acquia-log-management.sh
Created February 3, 2015 13:01
Bash one-liners for reading and analyzing Acquia's log files.
# Find and print all PHP errors that found their way into watchdog, sorted by number of ocurrences
zgrep '|php|' drupal-watchdog.log* | cut -d'|' -f9 | sed -r "s/(.*?)request_id\=\"[0-9a-f-]*\"/\1/" | sort | uniq -c | sort -rn | less

If you ever need to run an update hook again with drush you can often do this:

drush eval "module_load_instal('module_name'); module_name_update_7012();"

But! If that update is run as a batch then that won't work. So instead you can do this:

drush eval "drupal_set_installed_schema_version('module_name', '7011');"
drush updb

Which effectively rolls the module back to it's old version number.

<?php
// If you are unfortunate enough to still be using nodequeues (see entity queue)
// this will should work for creating new queues:
// Note I built the array from a drupal_var_export and a nodequeue load operation
// Then I added the add_subqueue argument and removed the qid (both mandatory).
function mymodule_update_N() {
$queue = (object) array(
'name' => 'machine_name',
@angry-dan
angry-dan / create-custom-tokens.php
Last active August 29, 2015 14:06
Create custom tokens (Drupal token_custom module) with an update hook.
<?php
$token = new stdClass();
$token->machine_name = 'machine-name-like-this';
$token->name = 'Name like this';
$token->description = 'Description like this';
$token->type = 'bundle_name';
$token->content = 'Default value';
$token->format = 'filtered_html';
$token->is_new = TRUE;
<?php
db_query("
INSERT IGNORE INTO {field_data_FIELD_NAME} (entity_type, bundle, deleted, entity_id, revision_id, language, delta, VALUE_COLUMNS...)
SELECT
'ENTITY TYPE' AS entity_type,
'BUNDLE' AS bundle,
0 AS deleted,
ENTITY ID AS entity_id,
REVISION ID IF EXISTS ELSE ENTITY ID AS revision_id,
'und' AS language,
<?php
/**
* Join a string with a natural language conjunction at the end.
*/
function natural_language_join(array $list, $conjunction = 'and') {
$last = array_pop($list);
if ($list) {
return implode(', ', $list) . ' ' . $conjunction . ' ' . $last;
}
return $last;
# Use: red for live, yellow
# Red
PS1='\[\033[0;31m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
# Yellow
PS1='\[\033[0;33m\]\u@\h\[\033[0;34m\] \w \$\[\033[00m\] '
# Green
PS1='\[\033[0;32m\]\u@\h\[\033[0;34m\] \w \$\[\033[00m\] '
// ==UserScript==
// @name Disable overlay
// @namespace http://angrydan.example.com
// @description Disable the Drupal overlay
// @include *
// @version 1
// @grant none
// ==/UserScript==
// Drupal.ajaxError was introduced in D7. D6 won't have it.
@angry-dan
angry-dan / disable-view.php
Created July 17, 2014 15:47
Add to an install/update hook to turn off a view.
<?php
$view = views_get_view('VIEW_NAME');
if (!empty($view)) {
ctools_include('export');
ctools_export_crud_set_status('views_view', $view, TRUE);
}