function _masquerade_drush_sessions in Masquerade Extras 6.2
Same name and namespace in other branches
- 7.2 masquerade_drush/masquerade_drush.drush.inc \_masquerade_drush_sessions()
Utility command to dump the active sessions table from the site.
Parameters
string $account: An account name, user ID, or email address to search for.
1 call to _masquerade_drush_sessions()
- drush_masquerade_drush_sessions in masquerade_drush/
masquerade_drush.drush.inc - Implements drush_HOOK_COMMAND().
File
- masquerade_drush/
masquerade_drush.drush.inc, line 394 - Provides some drush commands for masquerade.
Code
function _masquerade_drush_sessions($account = NULL) {
// Grab all the sessions
$query_sessions = "\n SELECT s.`uid`, s.`sid`, u.`name`, s.`timestamp`, s.`hostname`\n FROM {sessions} AS s\n LEFT JOIN {users} AS u\n ON u.`uid` = s.`uid`";
// If the account was found, limit the results to just that account.
if (!empty($account)) {
// If an account was provided, load it.
$user = _masquerade_drush_get_user($account);
// Make sure we found the user.
if (!$user) {
return drush_log(dt('The account "@name" could not be found.', array(
'@name' => $account,
)), 'error');
}
// This is the closest and safest way to affect the query in oen shot.
$query_sessions .= sprintf(" AND s.uid = %d", $user->uid);
}
$query_sessions = db_query($query_sessions);
if (!empty($user) && empty($sessions)) {
return drush_log(dt('The user "@name" is not logged in right now.', array(
'@name' => $user->name,
)), 'ok');
}
// Dump a list of headers so the table actually makes sense.
$list = array(
array(
'uid',
'username',
'hostname',
'timestamp',
),
array(
'----------',
'-----------',
'---------------',
'-----------',
),
);
while (FALSE !== ($s = db_fetch_object($query_sessions))) {
$list[] = array(
$s->uid,
$s->name,
$s->hostname,
$s->timestamp,
);
}
drush_print_table($list, TRUE);
}