-
Notifications
You must be signed in to change notification settings - Fork 5
/
rebuild_project_paths.drush.inc
58 lines (51 loc) · 1.48 KB
/
rebuild_project_paths.drush.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* 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}');
while ($mod = db_fetch_array($result)) {
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_query("UPDATE system SET filename='%s' WHERE name='%s'", $modpath, $mod['name']);
}
}
unset($modpath_arr);
}
}