Last active
September 1, 2016 21:48
-
-
Save szeidler/68687fb3dd25a6bb5b82 to your computer and use it in GitHub Desktop.
Search in all aliases for module occurrence. Returns hits and version. Usage " ./module_finder.drush module_name"
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
#!/usr/bin/env drush | |
<?php | |
/** | |
* Usage: " ./module_finder.drush metatag" | |
* Usage multiple modules: " ./module_finder.drush 'views|metatag" | |
*/ | |
// Get all aliases. | |
$aliases = _drush_sitealias_all_list(); | |
$arguments = drush_get_arguments(); | |
if (!empty($arguments[2])) { | |
$module_name = $arguments[2]; | |
// Drop alias @none | |
unset($aliases['@none']); | |
// Get applied aliases to drop. | |
$exclude_aliases = drush_get_option('exclude-aliases'); | |
$exclude = array(); | |
$exclude = explode(',', $exclude_aliases); | |
// Traverse aliases | |
foreach ($aliases as $alias_name => $alias) { | |
// Skip loop if in exclude option. | |
if (in_array($alias_name, $exclude)) { | |
continue; | |
} | |
$output = array(); | |
exec('drush ' . $alias_name . ' pm-list -y | grep -E "(' . $module_name . ')"', $output, $exit_status); | |
if (!empty($output)) { | |
foreach ($output as $output_line) { | |
drush_print('' . $alias_name . ': is running ' . $output_line); | |
} | |
} | |
} | |
} | |
else { | |
drush_set_error('MISSING_ARGUMENTS', 'Error: Please define a module name as parameter'); | |
} |
We can. It's a naive and slow way of finding modules in all of our sites, but it works.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shall we integrate this into our Site Aliases repo?