MDL-63207 auth_ldap: Update user profile if field is empty

This commit is contained in:
cescobedo
2021-09-07 22:57:02 +02:00
parent 3e6900105a
commit f01cff47d2
+10 -10
View File
@@ -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) {