Skip to content
Snippets Groups Projects
Commit 764db39e authored by Alexander Bias's avatar Alexander Bias
Browse files

Adopt code changes in Moodle 3.3 core auth_ldap: Sync user profile fields

parent eaf63bbc
Branches
Tags
No related merge requests found
......@@ -6,6 +6,7 @@ Changes
### Unreleased
* 2018-02-02 - Adopt code changes in Moodle 3.3 core auth_ldap: Sync user profile fields
* 2018-02-02 - Adopt code changes in Moodle 3.3 core auth_ldap: Convert auth plugins to use settings.php. Please double-check your plugin settings after upgrading to this version.
* 2017-12-12 - Prepare compatibility for Moodle 3.3, no functionality change.
* 2017-12-05 - Added Workaround to travis.yml for fixing Behat tests with TravisCI.
......
......@@ -331,23 +331,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
/// User Updates - time-consuming (optional)
if ($do_updates) {
// Narrow down what fields we need to update
$all_keys = array_keys(get_object_vars($this->config));
$updatekeys = array();
foreach ($all_keys as $key) {
if (preg_match('/^field_updatelocal_(.+)$/', $key, $match)) {
// If we have a field to update it from
// and it must be updated 'onlogin' we
// update it on cron
if (!empty($this->config->{'field_map_'.$match[1]})
and $this->config->{$match[0]} === 'onlogin') {
array_push($updatekeys, $match[1]); // the actual key name
}
}
}
if ($this->config->suspended_attribute && $this->config->sync_suspended) {
$updatekeys[] = 'suspended';
}
unset($all_keys); unset($key);
$updatekeys = $this->get_profile_keys();
} else {
mtrace(get_string('noupdatestobedone', 'auth_ldap'));
}
......@@ -458,29 +442,8 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
}
// Save custom profile fields.
$profilefields = array();
foreach ($user as $key => $value) {
if (preg_match('/^profile_field_(.*)$/', $key, $match)) {
$field = $match[1];
$profilefields[$field] = $user->$key;
}
}
// Now, save the profile fields if the user has any.
if ($fields = $DB->get_records('user_info_field')) {
foreach ($fields as $field) {
if (isset($profilefields[$field->shortname])) {
$conditions = array('fieldid' => $field->id, 'userid' => $euser->id);
$id = $DB->get_field('user_info_data', 'id', $conditions);
$data = $profilefields[$field->shortname];
if ($id) {
$DB->set_field('user_info_data', 'data', $data, array('id' => $id));
} else {
$record = array('fieldid' => $field->id, 'userid' => $euser->id, 'data' => $data);
$DB->insert_record('user_info_data', $record);
}
}
}
}
$updatekeys = $this->get_profile_keys(true);
$this->update_user_record($user->username, $updatekeys, false);
}
$transaction->allow_commit();
unset($add_users); // free mem
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment