function _masquerade_drush_list in Masquerade Extras 7.2
Same name and namespace in other branches
- 6.2 masquerade_drush/masquerade_drush.drush.inc \_masquerade_drush_list()
Displays a table of active masquerades in the site.
Parameters
string $account: An optional username, user ID, or email address to filter the list down to.
1 call to _masquerade_drush_list()
- drush_masquerade_drush_masquerade in masquerade_drush/
masquerade_drush.drush.inc - Implements drush_HOOK_COMMAND().
File
- masquerade_drush/
masquerade_drush.drush.inc, line 294 - Provides some drush commands for masquerade.
Code
function _masquerade_drush_list($account = NULL) {
$account = _masquerade_drush_get_user($account);
// @todo: There is a strange PHP chaining problem which
// won't allow us to db_select()->join()->fields()
// as expected. Instead, we'll just step through
// each part...
// This only happens in this function...
$query = db_select('masquerade', 'm');
$query
->join('users', 'u', 'm.uid_from = u.uid');
$query
->join('users', 'u2', 'm.uid_as = u2.uid');
// $query->fields('m', array('sid')); // Hidden
$query
->fields('u', array(
'name',
'uid',
));
$query
->fields('u2', array(
'name',
'uid',
));
// If a user account was provided, we can whittle down
// the list to just masquerades with this account.
if (!empty($account)) {
$query
->condition('m.uid_as', $account->uid, '=');
}
// Request the list of active masquerades.
$list = $query
->execute()
->fetchAll();
// Check if no masquerades were found.
if (empty($list)) {
return drush_log('No one is masquerading at this time.', 'ok');
}
// Fill in the rows.
$rows = array();
$rows[] = array(
'Source User',
'UserId',
'Posing As',
'UserId',
);
// Just a helpful display trick.
$rows[] = array(
'-------------------------',
'----------',
'-------------------------',
'----------',
);
// Loop through the active masquerades and turn them into rows.
foreach ($list as $m) {
$rows[] = array(
$m->name,
// $m->sid, // Hidden
$m->uid,
$m->u2_name,
$m->u2_uid,
);
}
// Display the list.
drush_print_table($rows, TRUE);
}