Dear Inaki,
Thank you for your support to this community!
Recently I have upgraded our site to moodle 3.1.1 from moodle 2.5.3. earlier our LDAP Sync script used to run perfectly and after upgrading first time it ran correctly, however from second run it throws following error. Even we tried the scheduled task it is not running.
I found there is a cleanup activity happening in the username field during the first run, when it runs for 2nd time it considers the cleaned up users as new users and once again it tries to sync those users and do the clean up again and tries to insert the user again and so it throws this error.
Kindly suggest a workaround for this issue.
Thanks &Regards
Saravanan P
[AUTH LDAP] The users sync cron has been deprecated. Please use the scheduled task instead.
Connecting to LDAP server...
Creating temporary table tmp_extuser
...........................................................................................................................Got 123 records from LDAP
No updates to be done
User entries to be added: 5
++ The property 'username' has invalid data and has been cleaned. ++
* line 94 of /user/lib.php: call to debugging()
* line 957 of /auth/ldap/auth.php: call to user_create_user()
* line 72 of /auth/ldap/cli/sync_users.php: call to auth_plugin_ldap->sync_users()
Database transaction aborted automatically in /var/www/html/moodle/auth/ldap/cli/sync_users.php
Default exception handler: Error writing to database Debug: Duplicate entry '1-sandeepverma' for key 'mdl_user_mneuse_uix'
INSERT INTO mdl_user (firstname,lastname,email,username,confirmed,auth,mnethostid,suspended,lang,calendartype,maildisplay,mailformat,maildigest,autosubscribe,trackforums,timecreated,timemodified) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
[array (
0 => 'Sandeep Verma',
1 => 'Sandeep Verma',
2 => 'accenture1@corp.com',
3 => 'sandeepverma',
4 => 1,
5 => 'ldap',
6 => '1',
7 => 0,
8 => 'en',
9 => 'gregorian',
10 => '2',
11 => '1',
12 => '0',
13 => '1',
14 => '0',
15 => 1477373787,
16 => 1477373787,
)]
Error code: dmlwriteexception
* line 477 of /lib/dml/moodle_database.php: dml_write_exception thrown
* line 1172 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
* line 1218 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
* line 100 of /user/lib.php: call to mysqli_native_moodle_database->insert_record()
* line 957 of /auth/ldap/auth.php: call to user_create_user()
* line 72 of /auth/ldap/cli/sync_users.php: call to auth_plugin_ldap->sync_users()
!!! Error writing to database !!!
!! Duplicate entry '1-sandeepverma' for key 'mdl_user_mneuse_uix'