You are here

function _masquerade_drush_sessions_terminate in Masquerade Extras 7.2

Same name and namespace in other branches
  1. 6.2 masquerade_drush/masquerade_drush.drush.inc \_masquerade_drush_sessions_terminate()

Ends a user's session.

Parameters

string $param1: The account name, user id, or email address to lookup.

1 call to _masquerade_drush_sessions_terminate()
drush_masquerade_drush_sessions in masquerade_drush/masquerade_drush.drush.inc
Implements drush_HOOK_COMMAND().

File

masquerade_drush/masquerade_drush.drush.inc, line 421
Provides some drush commands for masquerade.

Code

function _masquerade_drush_sessions_terminate($param1 = NULL) {
  if (empty($param1)) {
    return drush_log("Please specify an account.", 'error');
  }

  // Try to lookup the user account.
  $account = _masquerade_drush_get_user($param1);

  // Make sure we found the account we wanted.
  if (empty($account)) {
    return drush_log(sprintf('The account "%s" could not be found.', $param1), 'error');
  }

  // Check which command we wanted to execute.
  $response = drush_prompt(sprintf('Are you sure you want to terminate "%s"\'s session? (y/n)', $account->name), NULL);
  $response = strtoupper(trim($response));
  if (!in_array($response, array(
    'Y',
    'YES',
  ))) {
    return drush_log('Cancelled action.', 'ok');
  }
  $terminated = db_delete('sessions')
    ->condition('uid', $account->uid, '=')
    ->execute();
  drush_log(sprintf('Terminated %d sessions for "%s".', $terminated, $account->name), 'ok');
}