Created
July 27, 2012 11:28
-
-
Save kalabro/3187485 to your computer and use it in GitHub Desktop.
Drupal 7: Drush command 'pm-lost' lists projects which are not installed or disabled.
This file contains hidden or 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 | |
/** | |
* @file pm_lost.drush.inc | |
* Drush command 'pm-lost' lists projects which are not installed or disabled. | |
* | |
* It can be useful to detect waste modules which was downloaded once and then forgotten. | |
*/ | |
/** | |
* Implementation of hook_drush_command(). | |
*/ | |
function pm_lost_drush_command() { | |
$items['pm-lost'] = array( | |
'description' => 'Show a list of lost (downloaded but disabled) modules.', | |
'aliases' => array('lost'), | |
); | |
return $items; | |
} | |
/** | |
* Command callback | |
*/ | |
function drush_pm_lost() { | |
$modules = pm_lost_get_list(); | |
uasort($modules, '_drush_pm_sort_extensions'); | |
$rows = array(); | |
$header = array(dt('Name'), dt('Package'), dt('Type'), dt('Version'), dt('Status')); | |
$rows[] = $header; | |
foreach ($modules as $key => $module) { | |
$rows[] = array( | |
$module->info['name'] . ' (' . $module->name . ')', | |
($module->info['package'] ? $module->info['package'] : ''), | |
ucfirst($module->type), | |
@$module->info['version'], | |
drush_get_extension_status($module), | |
); | |
$pipe[] = $module->name; | |
} | |
drush_print_table($rows, TRUE); | |
if (isset($pipe)) { | |
// Newline-delimited list for use by other scripts. Set the --pipe option. | |
drush_print_pipe($pipe); | |
} | |
return $modules; | |
} | |
/** | |
* Returns list of lost modules | |
*/ | |
function pm_lost_get_list() { | |
// All modules (without hidden) | |
$modules = drush_get_extensions(FALSE); | |
// Lost modules | |
$lost_modules = array(); | |
foreach ($modules as $module) { | |
if ($module->status == 0) { | |
$still_not_lost = FALSE; | |
// If it is not first level project, skip it | |
if (!empty($module->info['project']) && $module->info['project'] != $module->name) { | |
$still_not_lost = TRUE; | |
} | |
// Skip core modules like Forum | |
if (!empty($module->info['package']) && $module->info['package'] == 'Core') { | |
$still_not_lost = TRUE; | |
} | |
// If it is base theme for other theme, skip it | |
if ($module->type == 'theme') { | |
$all_themes = drush_get_themes(); | |
foreach ($all_themes as $theme) { | |
if (!empty($theme->info['base theme'])) { | |
if ($theme->status && $theme->info['base theme'] == $module->name) { | |
$still_not_lost = TRUE; | |
} | |
} | |
} | |
} | |
if (!$still_not_lost) { | |
$lost_modules[$module->name] = $module; | |
} | |
} | |
} | |
return $lost_modules; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this! I use it regularly to keep my Drupal installs clean.
I need it to work with Backdrop CMS too, but it had issues out-of-the-box, so I forked it and wrote my own copy. You can check it out here if you're interested: https://gist.github.com/BWPanda/c82f09d8490b5a04a8b5468e001df642