--- moodlelib.php.moodle_198 2010-10-20 12:28:31.000000000 -0700 +++ moodlelib.php.my 2010-10-20 12:46:51.000000000 -0700 @@ -2992,9 +2992,11 @@ * @return user A {@link $USER} object */ function update_user_record($username, $authplugin) { + global $CFG; + $username = trim(moodle_strtolower($username)); /// just in case check text case - $oldinfo = get_record('user', 'username', $username, '','','','', 'username, auth'); + $oldinfo = get_record('user', 'mnethostid', $CFG->mnet_localhost_id, 'username', $username, '', '', 'id, username, auth'); $userauth = get_auth_plugin($oldinfo->auth); if ($newinfo = $userauth->get_userinfo($username)) { @@ -3018,11 +3020,15 @@ // nothing_ for this field. Thus it makes sense to let this value // stand in until LDAP is giving a value for this field. if (!(empty($value) && $lockval === 'unlockedifempty')) { - set_field('user', $key, $value, 'username', $username) - || error_log("Error updating $key for $username"); + $updateinfo[$key] = $value; } } } + + if (isset($oldinfo->id) && isset($updateinfo) && count($updateinfo) > 0) { + $updateinfo['id'] = $oldinfo->id; + update_record('user', (object) $updateinfo) || error_log("Error updating record for $username"); + } } return get_complete_user_data('username', $username);