From 4bd73eceb8d155c76cec3b160233ae7ea77da16c Mon Sep 17 00:00:00 2001 From: cescobedo Date: Fri, 27 Aug 2021 18:07:42 +0200 Subject: [PATCH] MDL-63207 auth_ldap: Update user profile if field is empty --- auth/ldap/auth.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index 8ab37e4660e..1209debecc3 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -1228,15 +1228,16 @@ 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];