You are here

function _masquerade_drush_sessions_terminate in Masquerade Extras 6.2

Same name and namespace in other branches
  1. 7.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 454
Provides some drush commands for masquerade.

Code

function _masquerade_drush_sessions_terminate($param1 = NULL) {
  if (empty($param1)) {
    return drush_log(dt('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(dt('The account "@name" could not be found.', array(
      '@name' => $param1,
    )), 'error');
  }

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