]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-4207 Don't overwrite modified user profile values with empty LDAP values when...
authoriarenaza <iarenaza>
Sat, 31 May 2008 13:30:22 +0000 (13:30 +0000)
committeriarenaza <iarenaza>
Sat, 31 May 2008 13:30:22 +0000 (13:30 +0000)
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

lib/moodlelib.php

index 4587df3394710ca36388adafdab85984ff97d95f..cc829ff790c3431eb2e0e610b1c3bd6c95d9b505 100644 (file)
@@ -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");
+                }
             }
         }
     }