Skip to content

Instantly share code, notes, and snippets.

@szeidler
Last active September 1, 2016 21:48
Show Gist options
  • Save szeidler/68687fb3dd25a6bb5b82 to your computer and use it in GitHub Desktop.
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"
#!/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');
}
@esolitos
Copy link

Shall we integrate this into our Site Aliases repo?

@szeidler
Copy link
Author

szeidler commented Sep 1, 2016

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