Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.673 diff -u -p -r1.673 comment.module --- modules/comment/comment.module 20 Dec 2008 18:24:35 -0000 1.673 +++ modules/comment/comment.module 23 Dec 2008 16:02:24 -0000 @@ -484,7 +484,7 @@ function comment_nodeapi_view($node, $te } } } - + if (isset($links['comment_forbidden'])) { $links['comment_forbidden']['html'] = TRUE; } @@ -1248,7 +1248,7 @@ function comment_validate($edit) { form_set_error('date', t('You have to specify a valid date.')); } } - if (isset($edit['author']) && !$account = user_load(array('name' => $edit['author']))) { + if (isset($edit['author']) && !$account = user_load_by_name($edit['author'])) { form_set_error('author', t('You have to specify a valid author.')); } @@ -1572,7 +1572,7 @@ function comment_form_add_preview($form, // Attach the user and time information. if (!empty($edit['author'])) { - $account = user_load(array('name' => $edit['author'])); + $account = user_load_by_name($edit['author']); } elseif ($user->uid && !isset($edit['is_anonymous'])) { $account = $user; @@ -1652,7 +1652,7 @@ function _comment_form_submit(&$comment_ $comment_values['timestamp'] = strtotime($comment_values['date']); if (isset($comment_values['author'])) { - $account = user_load(array('name' => $comment_values['author'])); + $account = user_load_by_name($comment_values['author']); $comment_values['uid'] = $account->uid; $comment_values['name'] = $comment_values['author']; } Index: modules/dblog/dblog.test =================================================================== RCS file: /cvs/drupal/drupal/modules/dblog/dblog.test,v retrieving revision 1.12 diff -u -p -r1.12 dblog.test --- modules/dblog/dblog.test 11 Dec 2008 20:35:37 -0000 1.12 +++ modules/dblog/dblog.test 23 Dec 2008 16:02:25 -0000 @@ -188,7 +188,7 @@ class DBLogTestCase extends DrupalWebTes $this->drupalPost('admin/user/user/create', $edit, t('Create new account')); $this->assertResponse(200); // Retrieve user object. - $user = user_load(array('name' => $name)); //, 'pass' => $pass, 'status' => 1)); + $user = user_load_by_name($name); //, 'pass' => $pass, 'status' => 1)); $this->assertTrue($user != null, t('User @name was loaded', array('@name' => $name))); $user->pass_raw = $pass; // Needed by drupalLogin. // Login user. Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.1004 diff -u -p -r1.1004 node.module --- modules/node/node.module 20 Dec 2008 18:24:38 -0000 1.1004 +++ modules/node/node.module 23 Dec 2008 16:02:27 -0000 @@ -926,7 +926,7 @@ function node_validate($node, $form = ar if (user_access('administer nodes')) { // Validate the "authored by" field. - if (!empty($node->name) && !($account = user_load(array('name' => $node->name)))) { + if (!empty($node->name) && !($account = user_load_by_name($node->name))) { // The use of empty() is mandatory in the context of usernames // as the empty string denotes the anonymous user. In case we // are dealing with an anonymous user we set the user ID to 0. @@ -973,7 +973,7 @@ function node_submit($node) { if (user_access('administer nodes')) { // Populate the "authored by" field. - if ($account = user_load(array('name' => $node->name))) { + if ($account = user_load_by_name($node->name)) { $node->uid = $account->uid; } else { @@ -1204,7 +1204,7 @@ function node_build_content($node, $teas // Allow modules to make their own additions to the node. node_invoke_nodeapi($node, 'view', $teaser, $page); - + // Allow modules to modify the structured node. drupal_alter('node_view', $node, $teaser, $page); @@ -2995,7 +2995,7 @@ function node_list_permissions($type) { */ function node_elements() { $type['node_links'] = array(); - + return $type; } Index: modules/node/node.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.pages.inc,v retrieving revision 1.47 diff -u -p -r1.47 node.pages.inc --- modules/node/node.pages.inc 16 Dec 2008 22:05:51 -0000 1.47 +++ modules/node/node.pages.inc 23 Dec 2008 16:02:27 -0000 @@ -348,7 +348,7 @@ function node_preview($node) { if (isset($node->name)) { // The use of isset() is mandatory in the context of user IDs, because // user ID 0 denotes the anonymous user. - if ($user = user_load(array('name' => $node->name))) { + if ($user = user_load_by_name($node->name)) { $node->uid = $user->uid; $node->picture = $user->picture; } @@ -357,7 +357,7 @@ function node_preview($node) { } } elseif ($node->uid) { - $user = user_load(array('uid' => $node->uid)); + $user = user_load($node->uid); $node->name = $user->name; $node->picture = $user->picture; } Index: modules/profile/profile.module =================================================================== RCS file: /cvs/drupal/drupal/modules/profile/profile.module,v retrieving revision 1.248 diff -u -p -r1.248 profile.module --- modules/profile/profile.module 16 Dec 2008 23:57:33 -0000 1.248 +++ modules/profile/profile.module 23 Dec 2008 16:02:28 -0000 @@ -203,13 +203,6 @@ function profile_block_view($delta = '') } /** - * Implementation of hook_user_load(). - */ -function profile_user_load(&$edit, &$user, $category = NULL) { - return profile_load_profile($user); -} - -/** * Implementation of hook_user_register(). */ function profile_user_register(&$edit, &$user, $category = NULL) { @@ -265,11 +258,14 @@ function profile_user_delete(&$edit, &$u db_query('DELETE FROM {profile_value} WHERE uid = %d', $user->uid); } -function profile_load_profile(&$user) { - $result = db_query('SELECT f.name, f.type, v.value FROM {profile_field} f INNER JOIN {profile_value} v ON f.fid = v.fid WHERE uid = %d', $user->uid); - while ($field = db_fetch_object($result)) { - if (empty($user->{$field->name})) { - $user->{$field->name} = _profile_field_serialize($field->type) ? unserialize($field->value) : $field->value; +/** + * Implementation of hook_user_load(). + */ +function profile_user_load($users) { + $result = db_query('SELECT f.name, f.type, v.uid, v.value FROM {profile_field} f INNER JOIN {profile_value} v ON f.fid = v.fid WHERE uid IN (' . db_placeholders(array_keys($users)) . ')', array_keys($users)); + foreach ($result as $record) { + if (empty($users[$record->uid]->{$record->name})) { + $users[$record->uid]->{$record->name} = _profile_field_serialize($record->type) ? unserialize($record->value) : $record->value; } } } @@ -336,7 +332,7 @@ function profile_view_field($user, $fiel function profile_view_profile(&$user) { - profile_load_profile($user); + $user = user_load($user->uid); // Show private fields to administrators and people viewing their own account. if (user_access('administer users') || $GLOBALS['user']->uid == $user->uid) { Index: modules/profile/profile.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/profile/profile.pages.inc,v retrieving revision 1.10 diff -u -p -r1.10 profile.pages.inc --- modules/profile/profile.pages.inc 5 Dec 2008 12:50:28 -0000 1.10 +++ modules/profile/profile.pages.inc 23 Dec 2008 16:02:28 -0000 @@ -55,11 +55,13 @@ function profile_browse() { } // Extract the affected users: - $result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_value} v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access != 0 AND u.status != 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments); + $result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_value} v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access != 0 AND u.status != 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments)->fetchAllAssoc('uid'); + + // Load the users. + $users = user_load_multiple(array_keys($result)); $content = ''; - while ($account = db_fetch_object($result)) { - $account = user_load(array('uid' => $account->uid)); + foreach ($users as $account) { $profile = _profile_update_user_fields($fields, $account); $content .= theme('profile_listing', $account, $profile); } @@ -88,11 +90,10 @@ function profile_browse() { } // Extract the affected users: - $result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL); - + $result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL)->fetchAllAssoc('uid'); + $users = user_load_multiple(array_keys($result)); $content = ''; - while ($account = db_fetch_object($result)) { - $account = user_load(array('uid' => $account->uid)); + foreach ($users as $account) { $profile = _profile_update_user_fields($fields, $account); $content .= theme('profile_listing', $account, $profile); } Index: modules/simpletest/drupal_web_test_case.php =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v retrieving revision 1.76 diff -u -p -r1.76 drupal_web_test_case.php --- modules/simpletest/drupal_web_test_case.php 20 Dec 2008 18:24:39 -0000 1.76 +++ modules/simpletest/drupal_web_test_case.php 23 Dec 2008 16:02:31 -0000 @@ -824,7 +824,7 @@ class DrupalWebTestCase { // Log in with a clean $user. $this->originalUser = $user; drupal_save_session(FALSE); - $user = user_load(array('uid' => 1)); + $user = user_load(1); // Restore necessary variables. variable_set('install_profile', 'default'); Index: modules/simpletest/tests/file.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/file.test,v retrieving revision 1.14 diff -u -p -r1.14 file.test --- modules/simpletest/tests/file.test 27 Nov 2008 08:41:45 -0000 1.14 +++ modules/simpletest/tests/file.test 23 Dec 2008 16:02:31 -0000 @@ -259,7 +259,7 @@ class FileValidatorTest extends DrupalWe drupal_save_session(FALSE); // Run these test as uid = 1. - $user = user_load(array('uid' => 1)); + $user = user_load(1); $file = new stdClass(); $file->filesize = 999999; Index: modules/statistics/statistics.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/statistics/statistics.pages.inc,v retrieving revision 1.6 diff -u -p -r1.6 statistics.pages.inc --- modules/statistics/statistics.pages.inc 13 Oct 2008 00:33:04 -0000 1.6 +++ modules/statistics/statistics.pages.inc 23 Dec 2008 16:02:31 -0000 @@ -40,7 +40,7 @@ function statistics_node_tracker() { } function statistics_user_tracker() { - if ($account = user_load(array('uid' => arg(1)))) { + if ($account = user_load(arg(1))) { $header = array( array('data' => t('Timestamp'), 'field' => 'timestamp', 'sort' => 'desc'), Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.652 diff -u -p -r1.652 system.module --- modules/system/system.module 20 Dec 2008 05:20:20 -0000 1.652 +++ modules/system/system.module 23 Dec 2008 16:02:33 -0000 @@ -1981,7 +1981,7 @@ function system_send_email_action($objec if (isset($node)) { if (!isset($account)) { - $account = user_load(array('uid' => $node->uid)); + $account = user_load($node->uid); } if ($recipient == '%author') { $recipient = $account->mail; Index: modules/trigger/trigger.module =================================================================== RCS file: /cvs/drupal/drupal/modules/trigger/trigger.module,v retrieving revision 1.24 diff -u -p -r1.24 trigger.module --- modules/trigger/trigger.module 18 Dec 2008 23:07:50 -0000 1.24 +++ modules/trigger/trigger.module 23 Dec 2008 16:02:34 -0000 @@ -195,7 +195,7 @@ function _trigger_normalize_node_context // An action that works on users is being called in a node context. // Load the user object of the node's author. case 'user': - return user_load(array('uid' => $node->uid)); + return user_load($node->uid); } } @@ -298,7 +298,7 @@ function _trigger_normalize_comment_cont // An action that works on users is being called in a comment context. case 'user': - return user_load(array('uid' => is_array($comment) ? $comment['uid'] : $comment->uid)); + return user_load(is_array($comment) ? $comment['uid'] : $comment->uid); } } Index: modules/update/update.fetch.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/update/update.fetch.inc,v retrieving revision 1.13 diff -u -p -r1.13 update.fetch.inc --- modules/update/update.fetch.inc 24 Oct 2008 19:23:59 -0000 1.13 +++ modules/update/update.fetch.inc 23 Dec 2008 16:02:34 -0000 @@ -122,7 +122,7 @@ function _update_cron_notify() { if (!empty($notify_list)) { $default_language = language_default(); foreach ($notify_list as $target) { - if ($target_user = user_load(array('mail' => $target))) { + if ($target_user = user_load_by_mail($target)) { $target_language = user_preferred_language($target_user); } else { Index: modules/user/user.api.php =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.api.php,v retrieving revision 1.1 diff -u -p -r1.1 user.api.php --- modules/user/user.api.php 25 Nov 2008 02:37:33 -0000 1.1 +++ modules/user/user.api.php 23 Dec 2008 16:02:34 -0000 @@ -86,6 +86,25 @@ function hook_user($op, &$edit, &$accoun return $form; } } +/** + * Act on user objects when loaded from the database. + * + * Due to the static cache in user_load_multiple() you should not use this + * hook to modify the user properties returned by the {users} table itself + * since this may result in unreliable results when loading from cache. + * + * @param $users + * An array of user objects, indexed by uid. + * + * @see user_load_multiple() + * @see profile_user_load() + */ +function hook_user_load($users) { + $result = db_query('SELECT * FROM {my_table} WHERE uid IN (' . db_placeholders(array_keys($users)) . ')', array_keys($users)); + foreach ($result as $record) { + $users[$record->uid]->foo = $result->foo; + } +} /** * Add mass user operations. Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.949 diff -u -p -r1.949 user.module --- modules/user/user.module 23 Dec 2008 14:18:31 -0000 1.949 +++ modules/user/user.module 23 Dec 2008 16:02:36 -0000 @@ -133,65 +133,191 @@ function user_external_login($account, $ } /** - * Fetch a user object. - * - * @param $array - * An associative array of attributes to search for in selecting the - * user, such as user name or e-mail address. + * Load multiple users based on certain conditions. * + * This function should be used whenever you need to load more than one user + * from the database. Users are loaded into memory and will not require + * database access if loaded again during the same page request. + * + * @param $uids + * An array of user IDs. + * @param $conditions + * An array of conditions to match against the {users} table. These + * should be supplied in the form array('field_name' => 'field_value'). + * @param $reset + * A boolean indicating that the internal cache should be reset. * @return - * A fully-loaded $user object upon successful user load or FALSE if user - * cannot be loaded. + * An array of user objects, indexed by uid. + * + * @see user_load() + * @see user_load_by_mail() + * @see user_load_by_name() */ -function user_load($array = array()) { - // Dynamically compose a SQL query: - $query = array(); - $params = array(); - - if (is_numeric($array)) { - $array = array('uid' => $array); - } - elseif (!is_array($array)) { - return FALSE; - } - - foreach ($array as $key => $value) { - if ($key == 'uid' || $key == 'status') { - $query[] = "$key = %d"; - $params[] = $value; - } - elseif ($key == 'pass') { - $query[] = "pass = '%s'"; - $params[] = $value; +function user_load_multiple($uids = array(), $conditions = array(), $reset = FALSE) { + static $user_cache = array(); + if ($reset) { + $user_cache = array(); + } + + $users = array(); + + // Create a new variable which is either a prepared version of the $uids + // array for later comparison with the user cache, or FALSE if no $uids were + // passed. The $uids array is reduced as items are loaded from cache, and we + // need to know if it's empty for this reason to avoid querying the database + // when all requested users are loaded from cache. + $passed_uids = !empty($uids) ? array_flip($uids) : FALSE; + + // Load any available users from the internal cache. + if ($user_cache) { + if ($uids) { + $users += array_intersect_key($user_cache, $passed_uids); + // If any users were loaded, remove them from the $uids still to load. + $uids = array_keys(array_diff_key($passed_uids, $users)); } - else { - $query[]= "LOWER($key) = LOWER('%s')"; - $params[] = $value; + // If only conditions is passed, load all users from the cache. Users + // which don't match conditions will be removed later. + elseif ($conditions) { + $users = $user_cache; + } + } + + // Remove any loaded users from the array if they don't match $conditions. + if ($conditions) { + foreach ($users as $user) { + $user_values = (array) $user; + if (isset($conditions['name']) && drupal_strtolower($conditions['name']) != drupal_strtolower($user_values['name'])) { + unset($users[$user->uid]); + } + if (isset($conditions['mail']) && drupal_strtolower($conditions['mail']) != drupal_strtolower($user_values['mail'])) { + unset($users[$user->uid]); + } + elseif (array_diff_assoc($conditions, $user_values)) { + unset($users[$user->uid]); + } } } - $result = db_query('SELECT * FROM {users} u WHERE ' . implode(' AND ', $query), $params); - if ($user = db_fetch_object($result)) { - $user = drupal_unpack($user); + // Load any remaining users from the database, this is necessary if we have + // $uids still to load, or if $conditions was passed without $uids. + if ($uids || ($conditions && !$passed_uids)) { + $query = db_select('users', 'u')->fields('u'); - $user->roles = array(); - if ($user->uid) { - $user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user'; + // If the $uids array is populated, add those to the query. + if ($uids) { + $query->condition('u.uid', $uids, 'IN'); } - else { - $user->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user'; + // If the conditions array is populated, add those to the query. + if ($conditions) { + // Using LIKE() to get a case insensitive comparison because Crell and + // chx promise that dbtng will map it to ILIKE in postgres. + if (isset($conditions['name'])) { + $query->condition('u.name', $conditions['name'], 'LIKE'); + unset($conditions['name']); + } + if (isset($conditions['mail'])) { + $query->condition('u.mail', $conditions['mail'], 'LIKE'); + unset($conditions['mail']); + } + foreach ($conditions as $field => $value) { + $query->condition('u.' . $field, $value); + } } - $result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $user->uid); - while ($role = db_fetch_object($result)) { - $user->roles[$role->rid] = $role->name; + $result = $query->execute(); + + $queried_users = array(); + foreach ($result as $record) { + $queried_users[$record->uid] = drupal_unpack($record); + $queried_users[$record->uid]->roles = array(); + if ($record->uid) { + $queried_users[$record->uid]->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user'; + } + else { + $queried_users[$record->uid]->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user'; + } + } + + if (!empty($queried_users)) { + // Add any additional roles from the database. + $result = db_query('SELECT r.rid, r.name, ur.uid FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid IN (' . db_placeholders(array_keys($queried_users)) . ')', array_keys($queried_users)); + foreach ($result as $record) { + $queried_users[$record->uid]->roles[$record->rid] = $record->name; + } + + // Invoke hook_user_load() on the users loaded from the database + // and add them to the static cache. + foreach (module_implements('user_load') as $module) { + $function = $module . '_user_load'; + $function($queried_users); + } + $users += $queried_users; + $user_cache += $queried_users; } - user_module_invoke('load', $array, $user); } - else { - $user = FALSE; + + // Ensure that the returned array is ordered the same as the original $uids + // array if this was passed in and remove any invalid uids. + if ($passed_uids) { + // Remove any invalid uids from the array. + $passed_uids = array_intersect_key($passed_uids, $users); + foreach ($users as $user) { + $passed_uids[$user->uid] = $user; + } + $users = $passed_uids; } - return $user; + return $users; +} + + +/** + * Fetch a user object. + * + * @param $uid + * Integer specifying the user id. + * @param $reset + * A boolean indicating that the internal cache should be reset. + * @return + * A fully-loaded $user object upon successful user load or FALSE if user + * cannot be loaded. + * + * @see user_load_multiple() + */ +function user_load($uid, $reset = FALSE) { + $users = user_load_multiple(array($uid), array(), $reset); + return reset($users); +} + +/** + * Fetch a user object by email address. + * + * @param $mail + * String with the account's e-mail address. + * @return + * A fully-loaded $user object upon successful user load or FALSE if user + * cannot be loaded. + * + * @see user_load_multiple() + */ +function user_load_by_mail($mail) { + $users = user_load_multiple(array(), array('mail' => $mail)); + return reset($users); +} + +/** + * Fetch a user object by account name. + * + * @param $name + * String with the account's user name. + * @return + * A fully-loaded $user object upon successful user load or FALSE if user + * cannot be loaded. + * + * @see user_load_multiple() + */ +function user_load_by_name($name) { + $users = user_load_multiple(array(), array('name' => $name)); + return reset($users); } /** @@ -288,7 +414,7 @@ function user_save($account, $edit = arr } // Refresh user object. - $user = user_load(array('uid' => $account->uid)); + $user = user_load($account->uid, TRUE); // Send emails after we have the new user object. if (isset($edit['status']) && $edit['status'] != $account->status) { @@ -318,7 +444,7 @@ function user_save($account, $edit = arr } // Build the initial user object. - $user = user_load(array('uid' => $edit['uid'])); + $user = user_load($edit['uid']); user_module_invoke('insert', $edit, $user, $category); @@ -346,7 +472,7 @@ function user_save($account, $edit = arr } // Build the finished user object. - $user = user_load(array('uid' => $edit['uid'])); + $user = user_load($edit['uid'], TRUE); } return $user; @@ -1361,8 +1487,8 @@ function user_authenticate($form_values db_query("UPDATE {users} SET pass = '%s' WHERE uid = %d", $new_hash, $account->uid); } } - $account = user_load(array('uid' => $account->uid, 'status' => 1)); - $user = $account; + $users = user_load_multiple(array($account->uid), array('status' => '1')); + $user = reset($users); user_authenticate_finalize($form_values); return $user; } @@ -1415,7 +1541,7 @@ function user_login_submit($form, &$form function user_external_login_register($name, $module) { global $user; - $existing_user = user_load(array('name' => $name)); + $existing_user = user_load_by_name($name); if (isset($existing_user->uid)) { $user = $existing_user; } @@ -1601,7 +1727,7 @@ function _user_edit_submit($account, &$e * @param $uid The user ID of the user to delete. */ function user_delete($edit, $uid) { - $account = user_load(array('uid' => $uid)); + $account = user_load($uid); drupal_session_destroy_uid($uid); _user_mail_notify('status_deleted', $account); module_invoke_all('user_delete', $edit, $account); @@ -1813,7 +1939,7 @@ function user_user_operations($form_stat */ function user_user_operations_unblock($accounts) { foreach ($accounts as $uid) { - $account = user_load(array('uid' => (int)$uid)); + $account = user_load($uid); // Skip unblocking user if they are already unblocked. if ($account !== FALSE && $account->status == 0) { user_save($account, array('status' => 1)); @@ -1826,7 +1952,7 @@ function user_user_operations_unblock($a */ function user_user_operations_block($accounts) { foreach ($accounts as $uid) { - $account = user_load(array('uid' => (int)$uid)); + $account = user_load($uid); // Skip blocking user if they are already blocked. if ($account !== FALSE && $account->status == 1) { user_save($account, array('status' => 0)); @@ -1845,7 +1971,7 @@ function user_multiple_role_edit($accoun switch ($operation) { case 'add_role': foreach ($accounts as $uid) { - $account = user_load(array('uid' => (int)$uid)); + $account = user_load($uid); // Skip adding the role to the user if they already have it. if ($account !== FALSE && !isset($account->roles[$rid])) { $roles = $account->roles + array($rid => $role_name); @@ -1855,7 +1981,7 @@ function user_multiple_role_edit($accoun break; case 'remove_role': foreach ($accounts as $uid) { - $account = user_load(array('uid' => (int)$uid)); + $account = user_load($uid); // Skip removing the role from the user if they already don't have it. if ($account !== FALSE && isset($account->roles[$rid])) { $roles = array_diff($account->roles, array($rid => $role_name)); Index: modules/user/user.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.pages.inc,v retrieving revision 1.24 diff -u -p -r1.24 user.pages.inc --- modules/user/user.pages.inc 24 Nov 2008 00:40:45 -0000 1.24 +++ modules/user/user.pages.inc 23 Dec 2008 16:02:37 -0000 @@ -44,10 +44,12 @@ function user_pass() { function user_pass_validate($form, &$form_state) { $name = trim($form_state['values']['name']); // Try to load by email. - $account = user_load(array('mail' => $name, 'status' => 1)); + $users = user_load_multiple(array(), array('mail' => $name, 'status' => '1')); + $account = reset($users); if (!$account) { // No success, try to load by name. - $account = user_load(array('name' => $name, 'status' => 1)); + $users = user_load_multiple(array(), array('name' => $name, 'status' => '1')); + $account = reset($users); } if (isset($account->uid)) { form_set_value(array('#parents' => array('account')), $account, $form_state); @@ -86,7 +88,8 @@ function user_pass_reset(&$form_state, $ $timeout = 86400; $current = REQUEST_TIME; // Some redundant checks for extra security ? - if ($timestamp < $current && $account = user_load(array('uid' => $uid, 'status' => 1)) ) { + $users = user_load_multiple(array($uid), array('status' => '1')); + if ($timestamp < $current && $account = reset($users)) { // No time out for first time login. if ($account->login && $current - $timestamp > $timeout) { drupal_set_message(t('You have tried to use a one-time login link that has expired. Please request a new one using the form below.')); Index: modules/user/user.test =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.test,v retrieving revision 1.23 diff -u -p -r1.23 user.test --- modules/user/user.test 16 Dec 2008 23:57:33 -0000 1.23 +++ modules/user/user.test 23 Dec 2008 16:02:37 -0000 @@ -31,7 +31,8 @@ class UserRegistrationTestCase extends D $this->assertText(t('Your password and further instructions have been sent to your e-mail address.'), t('User registered successfully.')); // Check database for created user. - $user = user_load($edit); + $users = user_load_multiple(array(), array('name' => $name, 'mail' => $mail)); + $user = reset($users); $this->assertTrue($user, t('User found in database.')); $this->assertTrue($user->uid > 0, t('User has valid user id.')); @@ -53,9 +54,12 @@ class UserRegistrationTestCase extends D $edit['pass'] = 'foo'; $this->drupalPost('user', $edit, t('Log in')); $this->assertText(t('Sorry, unrecognized username or password. Have you forgotten your password?'), t('Invalid login attempt failed.')); +$this->assertTrue(1, var_export($edit, 1)); +$this->assertTrue(1, var_export($user, 1)); // Login using password reset page. $url = user_pass_reset_url($user); +$this->assertTrue(1, var_export($url, 1)); sleep(1); // TODO Find better way. $this->drupalGet($url); $this->assertText(t('This login can be used only once.'), t('Login can be used only once.')); @@ -74,7 +78,7 @@ class UserRegistrationTestCase extends D // Make sure password changes are present in database. require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc'); - $user = user_load(array('uid' => $user->uid)); + $user = user_load($user->uid, TRUE); $this->assertTrue(user_check_password($new_pass, $user), t('Correct password in database.')); // Logout of user account. @@ -169,12 +173,13 @@ class UserDeleteTestCase extends DrupalW variable_set('user_register', 1); $edit = array(); - $edit['name'] = $this->randomName(); - $edit['mail'] = $edit['name'] . '@example.com'; + $edit['name'] = $name = $this->randomName(); + $edit['mail'] = $mail = $edit['name'] . '@example.com'; $this->drupalPost('user/register', $edit, t('Create new account')); $this->assertText(t('Your password and further instructions have been sent to your e-mail address.'), t('User registered successfully.')); - $user = user_load($edit); + $users = user_load_multiple(array(), array('name' => $name, 'mail' => $mail)); + $user = reset($users); // Create admin user to delete registered user. $admin_user = $this->drupalCreateUser(array('administer users')); @@ -189,7 +194,7 @@ class UserDeleteTestCase extends DrupalW // Confirm deletion. $this->drupalPost(NULL, NULL, t('Delete')); $this->assertRaw(t('%name has been deleted.', array('%name' => $user->name)), t('User deleted')); - $this->assertFalse(user_load($edit), t('User is not found in the database')); + $this->assertFalse(user_load($user->uid), t('User is not found in the database')); } } @@ -498,13 +503,13 @@ class UserAdminTestCase extends DrupalWe $this->assertText($user_c->name, t('Found user C on filtered by perm admin users page')); // Test blocking of a user. - $account = user_load(array('name' => $user_b->name)); + $account = user_load($user_b->uid); $this->assertEqual($account->status, 1, 'User B not blocked'); $edit = array(); $edit['operation'] = 'block'; $edit['accounts['. $account->uid .']'] = TRUE; $this->drupalPost('admin/user/user', $edit, t('Update')); - $account = user_load(array('name' => $user_b->name)); + $account = user_load($user_b->uid, TRUE); $this->assertEqual($account->status, 0, 'User B blocked'); } }