function _masquerade_drush_terminate_masquerade in Masquerade Extras 7.2
Same name and namespace in other branches
- 6.2 masquerade_drush/masquerade_drush.drush.inc \_masquerade_drush_terminate_masquerade()
Deletes active masquerades from the database. This is exceptionally useful when an active masquerade is causing a development problem and the user can't end the masquerade.
Parameters
string $account: The source account name whose masquerade(s) need to be stopped.
1 call to _masquerade_drush_terminate_masquerade()
- drush_masquerade_drush_masquerade in masquerade_drush/
masquerade_drush.drush.inc - Implements drush_HOOK_COMMAND().
File
- masquerade_drush/
masquerade_drush.drush.inc, line 176 - Provides some drush commands for masquerade.
Code
function _masquerade_drush_terminate_masquerade($account) {
$account = _masquerade_drush_get_user($account);
// Make sure the user provided exists.
if (empty($account)) {
return drush_print("You must specify a valid user account. You can provide an email address, user ID, or username.");
}
$masquerades = db_select('masquerade', 'm')
->fields('m')
->condition('uid_from', $account->uid, '=')
->execute()
->fetchAll();
// Check that the user specified is actually masquerading.
if (empty($masquerades)) {
return drush_log("The specified account is not currently masquerading.", 'warning');
}
// Loop over each masquerade the user currently has active.
foreach ($masquerades as $masquerade) {
// Restore the session owner to its originator.
$upd = db_update('sessions')
->fields(array(
'uid' => $masquerade->uid_from,
))
->condition('sid', $masquerade->sid, '=')
->execute();
}
// Terminate all masquerades in the masquerade table from this user.
$num_ended = db_delete('masquerade')
->condition('uid_from', $account->uid, '=')
->execute();
if ($num_ended > 0) {
return drush_log('Ended "' . $num_ended . '" masquerades from account "' . $account->name . '"', 'success');
}
drush_log('No active masquerades for "' . $account->name . '" were located.', 'warning');
}