Skip to content

Commit

Permalink
Move drush_drupal_login() to drupal.inc
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman committed Nov 13, 2011
1 parent 3bca35d commit 78bae06
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
38 changes: 0 additions & 38 deletions drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,41 +125,3 @@ function _drush_bootstrap_and_dispatch() {
}
return $return;
}

/**
* Log the given user in to a bootstrapped Drupal site.
*
* @param mixed
* Numeric user id or user name.
*
* @return boolean
* TRUE if user was logged in, otherwise FALSE.
*/
function drush_drupal_login($drush_user) {
global $user;
if (drush_drupal_major_version() >= 7) {
$user = is_numeric($drush_user) ? user_load($drush_user) : user_load_by_name($drush_user);
}
else {
$user = user_load(is_numeric($drush_user) ? array('uid' => $drush_user) : array('name' => $drush_user));
}

if (empty($user)) {
if (is_numeric($drush_user)) {
$message = dt('Could not login with user ID #!user.', array('!user' => $drush_user));
if ($drush_user === 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' => $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');
}

return TRUE;
}
38 changes: 38 additions & 0 deletions includes/drupal.inc
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,41 @@ function _drush_log_update_sql($ret) {
function drush_find_profiles($drupal_root , $key = 'name') {
return drush_scan_directory($drupal_root . '/profiles', "/.*\.profile$/", array('.', '..', 'CVS', 'tests'), 0, 2, $key);
}

/**
* Log the given user in to a bootstrapped Drupal site.
*
* @param mixed
* Numeric user id or user name.
*
* @return boolean
* TRUE if user was logged in, otherwise FALSE.
*/
function drush_drupal_login($drush_user) {
global $user;
if (drush_drupal_major_version() >= 7) {
$user = is_numeric($drush_user) ? user_load($drush_user) : user_load_by_name($drush_user);
}
else {
$user = user_load(is_numeric($drush_user) ? array('uid' => $drush_user) : array('name' => $drush_user));
}

if (empty($user)) {
if (is_numeric($drush_user)) {
$message = dt('Could not login with user ID #!user.', array('!user' => $drush_user));
if ($drush_user === 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' => $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');
}

return TRUE;
}
7 changes: 4 additions & 3 deletions tests/COVERAGE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ output

ROOT
-------------
drush
drush:
need test: drush.ini
drush.php
drush.bat
drush.complete.sh:
drush.bat: N/A
drush.complete.sh: N/A

0 comments on commit 78bae06

Please sign in to comment.