/** * Log into the bootstrapped Drupal site with a specific * username or user id. */ function bootstrap_drupal_login() { $uid_or_name = drush_set_context('DRUSH_USER', drush_get_option('user', 0)); $userversion = drush_user_get_class(); if (!($account = $userversion->load_by_uid($uid_or_name))) { if (!($account = $userversion->load_by_name($uid_or_name))) { if (is_numeric($uid_or_name)) { $message = dt('Could not login with user ID !user.', array('!user' => $uid_or_name)); if ($uid_or_name === 0) { $message .= ' ' . dt('This is typically caused by importing a MySQL database dump from a faulty tool which re-numbered the anonymous user ID in the users table. See !link for help recovering from this situation.', array('!link' => 'http://drupal.org/node/1029506')); } } else { $message = dt('Could not login with user account `!user\'.', array('!user' => $uid_or_name)); } return drush_set_error('DRUPAL_USER_LOGIN_FAILED', $message); } } $userversion->setCurrentUser($account); _drush_log_drupal_messages(); }
/** * Given a comma-separated list of inputs, return accounts * for users that match by uid,name or email address. * * @param string $inputs * A comma delimited string (or array) of arguments, specifying user account(s). * * @throws UserListException * If any input is unmatched, an exception is thrown. * * @return \Drush\User\UserSingleBase[] * An associative array of UserSingleBase objects, keyed by user id. */ public static function getFromParameters($inputs) { $accounts = array(); $userversion = drush_user_get_class(); if ($inputs && $userversion) { $inputs = _convert_csv_to_array($inputs); foreach ($inputs as $input) { if (is_numeric($input) && ($account = $userversion->load_by_uid($input))) { } elseif ($account = $userversion->load_by_name($input)) { } elseif ($account = $userversion->load_by_mail($input)) { } else { // Unable to load an account for the input. throw new UserListException('Unable to find a matching user for ' . $input . '.'); } // Populate $accounts with a UserSingle object. Will go into $this->accounts. $single = drush_usersingle_get_class($account); $accounts[$single->id()] = $single; } } return $accounts; }