Last active
January 18, 2016 06:43
-
-
Save kekkis/ecd186d344cde71b5d26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Modernized for use in Drupal 7 | |
*/ | |
/** | |
* Implementation of hook_drush_command(). | |
* | |
* @See drush_parse_command() for a list of recognized keys. | |
* | |
* @return | |
* An associative array describing your command(s). | |
*/ | |
function rebuild_project_paths_drush_command() { | |
$items = array(); | |
$items['rebuild-project-paths'] = array( | |
'description' => "Rebuilds the system table when you move projects around.", | |
'aliases' => array('rpp'), | |
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_DATABASE, // No bootstrap at all. | |
); | |
return $items; | |
} | |
/** | |
* Implementation of hook_drush_help(). | |
* | |
* @param | |
* A string with the help section (prepend with 'drush:') | |
* | |
* @return | |
* A string with the help text for your command. | |
*/ | |
function rebuild_project_paths_drush_help($section) { | |
switch ($section) { | |
case 'drush:rebuild-project-paths': | |
return dt("Rebuilds project paths in the system table."); | |
} | |
} | |
/** | |
* Command callback for drush rebuild-project-paths | |
*/ | |
function drush_rebuild_project_paths() { | |
$result = db_query('SELECT filename, name FROM {system}'); | |
foreach ($result as $mod) { | |
exec('find . -name ' . basename($mod->filename), $modpath_arr); | |
if (count($modpath_arr) == 1) { | |
$modpath = ltrim($modpath_arr[0], './'); | |
$dbpath = $mod->filename; | |
if ($dbpath != $modpath) { | |
drush_print("Updating " . $mod->name. "'s path"); | |
db_update('system')->fields(array('filename' => $modpath))->condition('name', $mod->name)->execute(); | |
} | |
} | |
unset($modpath_arr); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment