Skip to content

Instantly share code, notes, and snippets.

@ezheidtmann
Created May 21, 2014 17:21
Show Gist options
  • Save ezheidtmann/07fc848f53592f3f70cd to your computer and use it in GitHub Desktop.
Save ezheidtmann/07fc848f53592f3f70cd to your computer and use it in GitHub Desktop.
Safety-oriented implementation of drush hooks, for squishymedia
<?php
/** @file squishy.drush.inc
*
* Place this file in sites/all/drush to enable its features. Attempts to
* prevent sql-sync to prod and sets up some safe dev settings after a sql-sync
* from anywhere.
*/
/**
* Implements drush_hook_pre_sql_sync()
*/
function drush_squishy_pre_sql_sync($source, $dest) {
$danger = drush_get_option('danger', FALSE);
if (strpos($dest, 'prod') !== FALSE && !$danger) {
return drush_set_error('danger', 'Refusing to sql-sync to a production server. Override with --strict=0 --danger if you really want to.');
}
}
/**
* Implements drush_hook_post_sql_sync()
*/
function drush_squishy_post_sql_sync($source, $dest) {
// Do some cleanup if coming from prod and we don't have --pristine option
if (strpos($source, 'prod') !== FALSE && !drush_get_option('pristine', FALSE)) {
drush_print('SQUISHY post-sql-sync: Running safety measures on sql-dump from prod. Use --pristine to disable.');
$ret = drush_invoke_process($dest, 'pm-enable', array('maillog'), array('-y'));
$ret && drush_log('SQUISHY post-sql-sync: Enabled maillog module', 'ok');
$ret = $ret && drush_invoke_process($dest, 'vset', array('maillog_devel', '1'));
$ret = $ret && drush_invoke_process($dest, 'vset', array('maillog_log', '1'));
$ret = $ret && drush_invoke_process($dest, 'vset', array('maillog_send', '0'));
$ret && drush_log('SQUISHY post-sql-sync: Enabled DEV environment settings for maillog', 'ok');
$ret = $ret && drush_invoke_process($dest, 'vset', array('preprocess_css', 0));
$ret = $ret && drush_invoke_process($dest, 'vset', array('preprocess_js', 0));
$ret && drush_log('SQUISHY post-sql-sync: Disabled CSS/JS preprocessing', 'ok');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment