From f01cff47d2bc00641506ac6117cba032b59210cb Mon Sep 17 00:00:00 2001 From: cescobedo Date: Wed, 21 Jul 2021 07:55:03 +0200 Subject: [PATCH] MDL-63207 auth_ldap: Update user profile if field is empty --- auth/ldap/auth.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index 8ab37e4660e..a0b118fd789 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -1228,18 +1228,18 @@ class auth_plugin_ldap extends auth_plugin_base { empty($nuvalue) ? $nuvalue = array() : $nuvalue; $ouvalue = core_text::convert($oldvalue, 'utf-8', $this->config->ldapencoding); foreach ($ldapkeys as $ldapkey) { - // Skip update if $ldapkey does not exist in LDAP. - if (!isset($user_entry[$ldapkey][0])) { - $success = false; - error_log($this->errorlogtag.get_string('updateremfailfield', 'auth_ldap', - array('ldapkey' => $ldapkey, - 'key' => $key, - 'ouvalue' => $ouvalue, - 'nuvalue' => $nuvalue))); - continue; + // If the field is empty in LDAP there are two options: + // 1. We get the LDAP field using ldap_first_attribute. + // 2. LDAP don't send the field using ldap_first_attribute. + // So, for option 1 we check the if the field is retrieve it. + // And get the original value of field in LDAP if the field. + // Otherwise, let value in blank and delegate the check in ldap_modify. + if (isset($user_entry[$ldapkey][0])) { + $ldapvalue = $user_entry[$ldapkey][0]; + } else { + $ldapvalue = ''; } - $ldapvalue = $user_entry[$ldapkey][0]; if (!$ambiguous) { // Skip update if the values already match if ($nuvalue !== $ldapvalue) {