Skip to content

Instantly share code, notes, and snippets.

@rfay
Created June 30, 2011 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rfay/1056726 to your computer and use it in GitHub Desktop.
Save rfay/1056726 to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Provide Drush integration for release building and dependency building.
*/
/**
* Implements hook_drush_command().
*/
function registry_rebuild_drush_command() {
$items = array();
$items['registry-rebuild'] = array(
'description' => 'Rebuild the registry table (for classes) and the system table (for module locations) in a Drupal install.',
'callback' => 'drush_registry_rebuild',
'bootstrap' => DRUSH_BOOTSTRAP_DATABASE,
'aliases' => array('rr'),
);
$items['junk'] = array(
'description' => 'JUNK: Display DRUPAL_ROOT',
'callback' => 'drush_registry_rebuild_junk',
'aliases' => array('junk'),
'bootstrap' => DRUSH_BOOTSTRAP_DATABASE,
);
return $items;
}
/**
* Rebuild the registry.
*/
function drush_registry_rebuild() {
drush_registry_rebuild_rebuild();
}
function drush_registry_rebuild_junk() {
$context = drush_get_context();
print_r($context, 'context');
$x = 1;
}
/**
* Before calling this we need to be bootstrapped to DRUPAL_BOOTSTRAP_DATABASE.
*/
function drush_registry_rebuild_rebuild() {
$context = drush_get_context();
print "Context is " . print_r($context, TRUE);
print "CWD is " . getcwd();
require_once $drupal_root . '/includes/registry.inc';
// This section is not functionally important. It's just getting the
// registry_parsed_files() so that it can report the change.
$connection_info = Database::getConnectionInfo();
$driver = $connection_info['default']['driver'];
require_once $drupal_root . '/includes/database/' . $driver . '/query.inc';
$parsed_before = registry_get_parsed_files();
cache_clear_all('lookup_cache', 'cache_bootstrap');
cache_clear_all('variables', 'cache_bootstrap');
cache_clear_all('module_implements', 'cache_bootstrap');
print "Doing registry_rebuild() in DRUPAL_BOOTSTRAP_SESSION<br/>\n";
registry_rebuild(); // At lower level
print "Bootstrapping to DRUPAL_BOOTSTRAP_FULL<br/>\n";
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
print "Doing registry_rebuild() in DRUPAL_BOOTSTRAP_FULL<br/>\n";
registry_rebuild();
$parsed_after = registry_get_parsed_files();
print "Flushing all caches<br/>\n";
drupal_flush_all_caches();
print "There were " . count($parsed_before) . " files in the registry before and " . count($parsed_after) . " files now.<br/>\n";
print "If you don't see any crazy fatal errors, your registry has been rebuilt.<br/>\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment