You are here

function _masquerade_drush_list in Masquerade Extras 6.2

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

Code

function _masquerade_drush_list($account = NULL) {
  $query_masqueraders = "SELECT m.sid AS sid, \n       u2.uid AS u2_uid, \n       u2.name AS u2_name,\n       u.uid AS uid,\n       u.name AS name\n       FROM {masquerade} AS m\n     LEFT JOIN {users} AS u2\n         ON u2.uid = m.uid_as\n     LEFT JOIN {users} AS u\n         ON u.uid = m.uid_from";

  // If a user account was provided, we can whittle down
  // the list to just masquerades with this account.
  if (FALSE !== ($account = _masquerade_drush_get_user($account))) {
    $query .= sprintf("WHERE m.uid_from = %d", $account->uid);
  }
  $query_list = db_query($query_masqueraders);

  // Fill in the rows.
  $rows = array();
  $rows[] = array(
    'Source User',
    'UserId',
    'Posing As',
    'UserId',
  );

  // Just a helpful display trick.
  $rows[] = array(
    '-------------------------',
    '----------',
    '-------------------------',
    '----------',
  );
  $found = 0;

  // Loop through the active masquerades and turn them into rows.
  while (FALSE !== ($m = db_fetch_object($query_list))) {
    $rows[] = array(
      $m->name,
      $m->uid,
      $m->u2_name,
      $m->u2_uid,
    );
    $found++;
  }
  if ($found < 1) {
    return drush_log(dt('No one is masquerading at this time.'), 'ok');
  }

  // Display the list.
  drush_print_table($rows, TRUE);
}