Skip to content

Commit

Permalink
Fix login during bootstrap for D8
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman committed Aug 19, 2013
1 parent ba732f8 commit 1dd8dc5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions includes/drupal.inc
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,22 @@ function drush_find_profiles($drupal_root , $key = 'name') {
*/
function drush_drupal_login($drush_user) {
global $user;
if (drush_drupal_major_version() >= 7) {
if (drush_drupal_major_version() >= 8) {
// @todo the global $user is no longer the right way to login a user in D8.
// @todo: might be time to move this function into the Drupal engine.
$user = is_numeric($drush_user) ? user_load($drush_user) : user_load_by_name($drush_user);
$name = $user->getUsername() ? $user->getUsername() : variable_get('anonymous', t('Anonymous'));
$uid = $user->id();
}
elseif (drush_drupal_major_version() == 7) {
$user = is_numeric($drush_user) ? user_load($drush_user) : user_load_by_name($drush_user);
$name = $user->name ? $user->name : variable_get('anonymous', t('Anonymous'));
$uid = $user->uid;
}
else {
$user = user_load(is_numeric($drush_user) ? array('uid' => $drush_user) : array('name' => $drush_user));
$name = $user->name ? $user->name : variable_get('anonymous', t('Anonymous'));
$uid = $user->uid;
}

if (empty($user)) {
Expand All @@ -154,8 +165,7 @@ function drush_drupal_login($drush_user) {
return drush_set_error('DRUPAL_USER_LOGIN_FAILED', $message);
}
else {
$name = $user->name ? $user->name : variable_get('anonymous', t('Anonymous'));
drush_log(dt('Successfully logged into Drupal as !name', array('!name' => $name . " (uid=$user->uid)")), 'bootstrap');
drush_log(dt('Successfully logged into Drupal as !name', array('!name' => $name . " (uid=$uid)")), 'bootstrap');
}

return TRUE;
Expand Down

0 comments on commit 1dd8dc5

Please sign in to comment.