From: iarenaza Date: Sat, 31 May 2008 13:30:22 +0000 (+0000) Subject: MDL-4207 Don't overwrite modified user profile values with empty LDAP values when... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=6ceb0cd0ddbdb87c1c2f1cca18ba3fff9f974d5c;p=moodle.git MDL-4207 Don't overwrite modified user profile values with empty LDAP values when 'unlocked if empty' is set If user profile values are locked to LDAP, then LDAP should provide those values. But the purpose of the setting 'unlocked if empty' is to allow the user to fill in a value for the selected field _if LDAP is giving nothing_ for this field. Thus it makaes sense to let this value stand in until LDAP is giving a value for this field. Merged from MOODLE_18_STABLE --- diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 4587df3394..cc829ff790 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2878,10 +2878,23 @@ function update_user_record($username, $authplugin) { if ($newinfo = $userauth->get_userinfo($username)) { $newinfo = truncate_userinfo($newinfo); foreach ($newinfo as $key => $value){ - $confkey = 'field_updatelocal_' . $key; - if (!empty($userauth->config->$confkey) and $userauth->config->$confkey === 'onlogin') { - $DB->set_field('user', $key, $value, array('username'=>$username)) - or error_log("Error updating $key for $username"); + $confval = $userauth->config->{'field_updatelocal_' . $key}; + $lockval = $userauth->config->{'field_lock_' . $key}; + if (empty($confval) || empty($lockval)) { + continue; + } + if ($confval === 'onlogin') { + $value = addslashes(stripslashes($value)); // Just in case + // MDL-4207 Don't overwrite modified user profile values with + // empty LDAP values when 'unlocked if empty' is set. The purpose + // of the setting 'unlocked if empty' is to allow the user to fill + // in a value for the selected field _if LDAP is giving + // 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')) { + $DB->set_field('user', $key, $value, 'username', $username) + || error_log("Error updating $key for $username"); + } } } }