Skip to content

Instantly share code, notes, and snippets.

@alex-moreno
Created June 4, 2020 09:41
Show Gist options
  • Save alex-moreno/45f10359a18a900e3574d461bed46fe2 to your computer and use it in GitHub Desktop.
Save alex-moreno/45f10359a18a900e3574d461bed46fe2 to your computer and use it in GitHub Desktop.
/**
* Execute drush to fetch users and roles in a given site.
*
* @param [type] $site_alias
* @param [type] $drush_alias
* @return void
*/
function execDrushUserInfo($site_alias, $drush_alias)
{
$php = "/usr/local/bin/php";
$drush_php = "/usr/local/bin/drush";
$result = exec("drush $drush_alias -l $site_alias uinf \"$(drush $drush_alias -l $site_alias sqlq \"SELECT GROUP_CONCAT(name) FROM users_field_data\")\"", $output, $return);
if (strpos($output[2], "Command user-information was not found. Drush was unable to query the database")) {
echo "\nCould not query database in $site_alias \n ";
} else {
echo "\nUsers found in $site_alias \n";
print_r($result);
print_r($output);
}
}
// Execute drush example.
execDrush("sites_url_alias.com", " status ", " @drushalias.01dev ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment