From 2a8f28520d6597669ae8e0e963dd36c1ee730516 Mon Sep 17 00:00:00 2001 From: cescobedo Date: Wed, 20 Jun 2018 11:43:28 +0200 Subject: [PATCH] MDL-61296 auth_ldap: remove PHP notices when field does not exist. --- auth/ldap/auth.php | 13 +++++++++++-- auth/ldap/lang/en/auth_ldap.php | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index 024fe2f53fa..4c0ca9e4d05 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -1187,9 +1187,18 @@ class auth_plugin_ldap extends auth_plugin_base { $nuvalue = core_text::convert($newvalue, 'utf-8', $this->config->ldapencoding); empty($nuvalue) ? $nuvalue = array() : $nuvalue; $ouvalue = core_text::convert($oldvalue, 'utf-8', $this->config->ldapencoding); - foreach ($ldapkeys as $ldapkey) { - $ldapkey = $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; + } + $ldapvalue = $user_entry[$ldapkey][0]; if (!$ambiguous) { // Skip update if the values already match diff --git a/auth/ldap/lang/en/auth_ldap.php b/auth/ldap/lang/en/auth_ldap.php index 237423e1f24..5040996dfc1 100644 --- a/auth/ldap/lang/en/auth_ldap.php +++ b/auth/ldap/lang/en/auth_ldap.php @@ -149,6 +149,7 @@ $string['start_tls'] = 'Use regular LDAP service (port 389) with TLS encryption' $string['start_tls_key'] = 'Use TLS'; $string['updateremfail'] = 'Error updating LDAP record. Error code: {$a->errno}; Error string: {$a->errstring}
Key ({$a->key}) - old moodle value: \'{$a->ouvalue}\' new value: \'{$a->nuvalue}\''; $string['updateremfailamb'] = 'Failed to update LDAP with ambiguous field {$a->key}; old moodle value: \'{$a->ouvalue}\', new value: \'{$a->nuvalue}\''; +$string['updateremfailfield'] = 'Failed to update LDAP with non-existent field (\'{$a->ldapkey}\'). Key ({$a->key}) - old moodle value: \'{$a->ouvalue}\' new value: \'{$a->nuvalue}\''; $string['updatepasserror'] = 'Error in user_update_password(). Error code: {$a->errno}; Error string: {$a->errstring}'; $string['updatepasserrorexpire'] = 'Error in user_update_password() when reading password expiry time. Error code: {$a->errno}; Error string: {$a->errstring}'; $string['updatepasserrorexpiregrace'] = 'Error in user_update_password() when modifying expirationtime and/or gracelogins. Error code: {$a->errno}; Error string: {$a->errstring}';