-
Bug
-
Resolution: Fixed
-
Minor
-
2.2.3, 2.3
-
None
-
MOODLE_22_STABLE, MOODLE_23_STABLE
-
MOODLE_22_STABLE, MOODLE_23_STABLE
-
w27_
MDL-33876_m24_delenrol -
When running the database enrolment sync script:
/usr/bin/php enrol/database/cli/sync.php
I get the following exception:
Default exception handler: Coding error detected, it must be fixed by a programmer: User ID does not exist or is deleted! Debug: userid:2183
- line 1595 of /lib/accesslib.php: coding_exception thrown
- line 1267 of /lib/enrollib.php: call to role_assign()
- line 458 of /enrol/database/lib.php: call to enrol_plugin->enrol_user()
- line 79 of /enrol/database/cli/sync.php: call to enrol_database_plugin->sync_enrolments()
!!! Coding error detected, it must be fixed by a programmer: User ID does not exist or is deleted! !!!
If the external enrolments table includes enrolments for a Moodle user that has been deleted this exception is thrown.
My external enrolment table looks like this:
course_id | contact_id | role
-----------------------------------
100000109 | 100005005 | editingteacher
100000250 | 100005005 | editingteacher
The relevant mdl_user record is:
id | idnumber | deleted
----------------------
2183 | 100005005 | 1
Relevent database enrolment plugin settings are:
Remote user field: contact_id
Local user field: idnumber
There appears to be a bug in the enrol/database/lib.php sync_enrolments(). Looking at that function around line 413 in Moodle 2.2 (look for usersearch) from what I can tell if the localuserfield is set to username then users that have been deleted are ignored. I suspect I'm hitting this error because I'm matching on the idnumber field instead. I can't see anywhere where deleted users are being excluded if searching on that field. So a fix should be pretty simple. Instead of:
if ($localuserfield === 'username') {
$usersearch = array('mnethostid'=>$CFG->mnet_localhost_id, 'deleted' =>0);
}
while ($fields = $rs->FetchRow()) {
That block of code should look like this:
if ($localuserfield === 'username') {
$usersearch = array('mnethostid'=>$CFG->mnet_localhost_id, 'deleted' =>0);
} else {
$usersearch = array('deleted' => 0);
}
while ($fields = $rs->FetchRow()) {