Permalink
Browse files

MDL-24699 minimalistic fix for the missing mnet host id when updating…

… local user records, thanks
  • Loading branch information...
1 parent 1929455 commit 7eef6309577a767c474c2be130176f4ada646234 @skodak skodak committed Nov 24, 2010
Showing with 9 additions and 7 deletions.
  1. +9 −7 lib/moodlelib.php
View
@@ -2978,7 +2978,7 @@ function create_user_record($username, $password, $auth='manual') {
$newuser->mnethostid = $CFG->mnet_localhost_id;
if (insert_record('user', $newuser)) {
- $user = get_complete_user_data('username', $newuser->username);
+ $user = get_complete_user_data('username', $newuser->username, $CFG->mnet_localhost_id);
if(!empty($CFG->{'auth_'.$newuser->auth.'_forcechangepassword'})){
set_user_preference('auth_forcepasswordchange', 1, $user->id);
}
@@ -2995,17 +2995,19 @@ function create_user_record($username, $password, $auth='manual') {
* @param string $username New user's username to add to record
* @return user A {@link $USER} object
*/
-function update_user_record($username, $authplugin) {
+function update_user_record($username, $unused) {
+ 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', 'username', $username, 'mnethostid', $CFG->mnet_localhost_id, '','', 'id, username, auth');
$userauth = get_auth_plugin($oldinfo->auth);
if ($newinfo = $userauth->get_userinfo($username)) {
$newinfo = truncate_userinfo($newinfo);
foreach ($newinfo as $key => $value){
- if ($key === 'username') {
- // 'username' is not a mapped updateable/lockable field, so skip it.
+ if ($key === 'username' or $key === 'id' or $key === 'auth' or $key === 'mnethostid' or $key === 'deleted') {
+ // these fields must not be changed
continue;
}
$confval = $userauth->config->{'field_updatelocal_' . $key};
@@ -3022,14 +3024,14 @@ function update_user_record($username, $authplugin) {
// 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)
+ set_field('user', $key, $value, 'id', $oldinfo->id)
|| error_log("Error updating $key for $username");
}
}
}
}
- return get_complete_user_data('username', $username);
+ return get_complete_user_data('username', $username, $CFG->mnet_localhost_id);
}
function truncate_userinfo($info) {

0 comments on commit 7eef630

Please sign in to comment.