-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added backdrop-pm-lost command. #152
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<?php | ||
/** | ||
* @file | ||
* Drush command to list disabled or not-installed projects in Backdrop sites. | ||
* | ||
* This can be useful for detecting projects which were downloaded and then | ||
* forgotten, or projects which have been uninstalled/disabled but not removed | ||
* from the file system. | ||
* | ||
* Inspired by the Drupal version: https://gist.github.com/kalabro/3187485 | ||
*/ | ||
|
||
/** | ||
* Implementation of hook_drush_command(). | ||
*/ | ||
function backdrop_pm_lost_drush_command() { | ||
return array( | ||
'backdrop-pm-lost' => array( | ||
'description' => 'Show a list of lost (downloaded but disabled) projects.', | ||
'aliases' => array('lost'), | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* Callback function for the 'backdrop-pm-lost' command. | ||
*/ | ||
function drush_backdrop_pm_lost() { | ||
// Output a leading newline. | ||
drush_print(); | ||
|
||
// Get 'lost' projects. | ||
$projects = backdrop_pm_lost_get_list(); | ||
|
||
if (!empty($projects)) { | ||
// Sort projects. | ||
uasort($projects, '_backdrop_pm_lost_sort_projects'); | ||
|
||
// Output table with header row. | ||
$rows = array( | ||
array(dt('NAME'), dt('TYPE'), dt('PACKAGE'), dt('VERSION'), dt('STATUS')), | ||
); | ||
|
||
// Output each project's details. | ||
foreach ($projects as $name => $project) { | ||
$rows[] = array( | ||
$project->name . ' (' . $project->info['name'] . ')', | ||
ucfirst($project->type), | ||
!empty($project->info['package']) ? $project->info['package'] : '', | ||
$project->info['version'], | ||
_backdrop_pm_lost_status($project), | ||
); | ||
} | ||
|
||
// Display output. | ||
drush_print_table($rows, TRUE); | ||
} | ||
else { | ||
drush_print(dt("No 'lost' projects."), 1); | ||
} | ||
|
||
// Output a trailing newline. | ||
drush_print(); | ||
} | ||
|
||
/** | ||
* Return a list of 'lost' projects. | ||
*/ | ||
function backdrop_pm_lost_get_list() { | ||
$lost_projects = array(); | ||
|
||
// Get all modules & themes. | ||
// Copied from modules_list_callback() in backdrop_pm_list.drush.inc. | ||
$modules = system_rebuild_module_data(); | ||
$themes = system_rebuild_theme_data(); | ||
$query = db_select('system', 's') | ||
->fields('s') | ||
->execute(); | ||
$projects = $query->fetchAll(); | ||
|
||
// Find 'lost' projects. | ||
foreach ($projects as $project) { | ||
if ($project->status == 0) { | ||
$lost = TRUE; | ||
|
||
$project->info = unserialize($project->info); | ||
if (!empty($project->info['project'])) { | ||
// Ignore core projects. | ||
if ($project->info['project'] == 'backdrop') { | ||
$lost = FALSE; | ||
} | ||
|
||
// Ignore sub-projects. | ||
if ($project->info['project'] != $project->name) { | ||
$lost = FALSE; | ||
} | ||
} | ||
|
||
// Ignore base themes that have an active sub-theme. | ||
if ($project->type == 'theme') { | ||
foreach ($themes as $theme) { | ||
if (!empty($theme->info['base theme']) && $theme->info['base theme'] == $project->name && $theme->status == 1) { | ||
$lost = FALSE; | ||
} | ||
} | ||
} | ||
|
||
// Make a list of 'lost' projects. | ||
if ($lost) { | ||
$lost_projects[$project->name] = $project; | ||
} | ||
} | ||
} | ||
|
||
return $lost_projects; | ||
} | ||
|
||
/** | ||
* Sort callback function for sorting projects. | ||
* | ||
* It will sort by type, then machine name. | ||
* | ||
* Partly copied from _drush_pm_sort_extensions() in pm.drush.inc. | ||
*/ | ||
function _backdrop_pm_lost_sort_projects($a, $b) { | ||
if ($a->type == 'module' && $b->type == 'theme') { | ||
return -1; | ||
} | ||
if ($a->type == 'theme' && $b->type == 'module') { | ||
return 1; | ||
} | ||
|
||
$cmp = strcasecmp($a->name, $b->name); | ||
|
||
return $cmp; | ||
} | ||
|
||
/** | ||
* Determine a project's status based on its current status and schema version. | ||
* | ||
* Partly copied from drush_get_extension_status() in pm.drush.inc. | ||
*/ | ||
function _backdrop_pm_lost_status($project) { | ||
$status = 'Disabled'; | ||
|
||
if ($project->type == 'module') { | ||
// Reminder to uninstall first. | ||
$status .= ' (needs uninstalling)'; | ||
|
||
if ($project->schema_version == -1) { | ||
$status = 'Not installed'; | ||
} | ||
} | ||
|
||
return $status; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BWPanda Isn't this going to mark a module as lost when it is just disabled? I thought the definition of lost was a module that still has a datbase record, but is not actually in the filesystem.
Maybe i've got that wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Kate describes her original Drush command for Drupal like so: "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."
I didn't think about modules existing in the database but not in the file system... If that's a possibility, then that might make a good feature request ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so how is this different than
drush pml
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tested both on my site.
lost
shows one contrib theme I have downloaded which isn't enabled.pml
shows all modules and themes on my site regardless of status.Basically,
lost
doesn't show:So again, the purpose of
lost
is to run it on a site and get a list of contrib modules and themes that can be removed from the file system (as they're not being used), or to remind you to enable them if you do need them.