function DrupalBoot::bootstrap_drupal_login

8.0.x DrupalBoot.php DrupalBoot::bootstrap_drupal_login()
7.x DrupalBoot.php DrupalBoot::bootstrap_drupal_login()
master DrupalBoot.php DrupalBoot::bootstrap_drupal_login()

Log into the bootstrapped Drupal site with a specific username or user id.

File

lib/Drush/Boot/DrupalBoot.php, line 556

Namespace

Drush\Boot

Class

DrupalBoot

Code

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();
}