function _drush_user_get_users_from_options_and_arguments

6.x user.drush.inc _drush_user_get_users_from_options_and_arguments($users)
4.x user.drush.inc _drush_user_get_users_from_options_and_arguments($users)
5.x user.drush.inc _drush_user_get_users_from_options_and_arguments($users)

Return the list of matching uids given

4 calls to _drush_user_get_users_from_options_and_arguments()
drush_user_add_role in commands/user/user.drush.inc
Add a role to the specified user accounts.
drush_user_block in commands/user/user.drush.inc
Block the specified user(s).
drush_user_remove_role in commands/user/user.drush.inc
Remove a role from the specified user accounts.
drush_user_unblock in commands/user/user.drush.inc
Unblock the specified user(s).

File

commands/user/user.drush.inc, line 462
Drush User Management commands

Code

function _drush_user_get_users_from_options_and_arguments($users) {
  $uids = drush_get_option_list('uids');

  foreach (array('uid', 'name', 'mail') as $user_attr) {
    if ($arg = drush_get_option($user_attr)) {
      foreach (explode(',', $arg) as $search) {
        $uid_query = FALSE;
        switch ($user_attr) {
          case 'uid':
            if (drush_drupal_major_version() >= 7) {
              $uid_query = db_query("SELECT uid FROM {users} WHERE uid = :uid", array(':uid' => $search));
            }
            else {
              $uid_query = db_query("SELECT uid FROM {users} WHERE uid = %d", $search);
            }
            break;
          case 'name':
            if (drush_drupal_major_version() >= 7) {
              $uid_query = db_query("SELECT uid FROM {users} WHERE name = :name", array(':name' => $search));
            }
            else {
              $uid_query = db_query("SELECT uid FROM {users} WHERE name = '%s'", $search);
            }
            break;
          case 'mail':
            if (drush_drupal_major_version() >= 7) {
              $uid_query = db_query("SELECT uid FROM {users} WHERE mail = :mail", array(':mail' => $search));
            }
            else {
              $uid_query = db_query("SELECT uid FROM {users} WHERE mail = '%s'", $search);
            }
            break;
        }
        if ($uid_query !== FALSE) {
          if ($uid = drush_db_result($uid_query)) {
            $uids[] = $uid;
          }
          else {
            drush_set_error("Could not find a uid for $user_attr = $search");
          }
        }
      }
    }
  }

  return array_merge($uids, _drush_user_get_users_from_arguments($users));
}