Skip to content
Snippets Groups Projects
Commit 6d8da3b3 authored by Dennis Ahrens's avatar Dennis Ahrens
Browse files

Fix #30 by backporting MDL-58395

auth_ldap: User sync now brings problem details and continue
It does not include the error messages, which will appear with
moodle 4.0.
Nevertheless this version should work with moodle 3.11 as well,
but with ugly log messages.
parent c385b5e9
No related branches found
No related tags found
No related merge requests found
......@@ -432,6 +432,7 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
if (!empty($add_users)) {
mtrace(get_string('userentriestoadd', 'auth_ldap', count($add_users)));
$errors = 0;
$transaction = $DB->start_delegated_transaction();
foreach ($add_users as $user) {
......@@ -457,6 +458,14 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
}
$id = user_create_user($user, false);
try {
$id = user_create_user($user, false);
} catch (Exception $e) {
print_string('invaliduserexception', 'auth_ldap', print_r($user, true) . $e->getMessage());
$errors++;
continue;
}
mtrace("\t".get_string('auth_dbinsertuser', 'auth_db', array('name'=>$user->username, 'id'=>$id)));
$euser = $DB->get_record('user', array('id' => $id));
......@@ -470,6 +479,11 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap {
// Add roles if needed.
$this->sync_roles($euser);
}
// Display number of user creation errors, if any.
if ($errors) {
print_string('invalidusererrors', 'auth_ldap', $errors);
}
$transaction->allow_commit();
unset($add_users); // free mem
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment