Skip to content

Instantly share code, notes, and snippets.

@lightweight
Created August 18, 2010 02:36
Show Gist options
  • Select an option

  • Save lightweight/533167 to your computer and use it in GitHub Desktop.

Select an option

Save lightweight/533167 to your computer and use it in GitHub Desktop.
<?php
// $Id$
/**
* @file
* Drush command to force reassessing of the system table after moving a site to a new location (path) or doing an upgrade
*
* To run this run the command "drush reassess modules" or "drush reassess themes"
* from within your drush directory.
*
* Installation: copy this file into your .drush/command directory (you might need to create those:
* mkdir -p ~/.drush/command
* should do it) or you can ensure it's in the drush path for your site or on the server...
*/
/**
* Implementation of hook_drush_command().
*
* In this hook, you specify which commands your
* drush module makes available, what it does and
* description.
*
* Notice how this structure closely resembles how
* you define menu hooks.
*
* @See drush_parse_command() for a list of recognized keys.
*
* @return
* An associative array describing your command(s).
*/
function reassess_drush_command() {
$items = array();
$items['reassess'] = array(
'description' => "reassesss the requested Drupal cache",
'arguments' => array(
'cache' => 'The cache to reassess - either "modules" or "themes"',
),
'options' => array(
'verbose' => 'print out other information',
),
'examples' => array(
'drush reassess modules',
'drush reassess themes',
),
'aliases' => array('ra'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL, // Give me the works.
);
return $items;
}
/**
* Implementation of hook_drush_help().
*
* This function is called whenever a drush user calls
* 'drush help <name-of-your-command>'
*
* @param
* A string with the help section (prepend with 'drush:')
*
* @return
* A string with the help text for your command.
*/
function reassess_drush_help($section) {
switch ($section) {
case 'drush:reassess':
return dt("This command will reassess the requested cache, either the module or the theme cache.");
}
}
/*
* Implementation of drush_hook_COMMAND_validate().
*/
function drush_reassess_validate() {
}
/**
* Example drush command callback. This is where the action takes place.
*
* The function name should be same as command name but with dashes turned to
* underscores and 'drush_commandfile_' prepended, where 'commandfile' is
* taken from the file 'commandfile.drush.inc', which in this case is 'sandwich'.
* Note also that a simplification step is also done in instances where
* the commandfile name is the same as the beginning of the command name,
* "drush_example_example_foo" is simplified to just "drush_example_foo".
* To also implement a hook that is called before your command, implement
* "drush_hook_pre_example_foo". For a list of all available hooks for a
* given command, run drush in --debug mode.
*
* If for some reason you do not want your hook function to be named
* after your command, you may define a 'callback' item in your command
* object that specifies the exact name of the function that should be
* called. However, the specified callback function must still begin
* with "drush_commandfile_" (e.g. 'callback' => "drush_example_foo_execute").
* All hook functions are still called (e.g. drush_example_pre_foo_execute,
* and so on.)
*
* In this function, all of Drupal's API is (usually) available, including
* any functions you have added in your own modules/themes.
*
*/
function drush_reassess($cache) {
//$modules = module_rebuild_cache();
//drush_print(dt('testing: !opt', array('!opt' => $cache)));
$msg = "nuthin'";
switch ($cache) {
case 'modules':
//drush_print(dt('testing 2: !opt', array('!opt' => $cache)));
$modules = array();
$modules = module_rebuild_cache();
if (count($modules)) {
$msg = dt('rebuilt the module cache.');
}
else {
$msg = dt('failed to rebuild the module cache.');
}
break;
case 'themes':
$themes = array();
$themes = system_theme_data();
if (count($themes)) {
$msg = dt('rebuilt the themes list.');
}
else {
$msg = dt('failed to rebuild the theme list.');
}
break;
default:
$msg = dt('check: drush help reassess.');
}
drush_print("\n" . $msg . "\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment