Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Duplicate
-
2.1.3
-
None
-
None
-
Any
-
MOODLE_21_STABLE
-
-
Description
When a user logs onto a Moodle site that uses the database enrolment plugin, the sync_user_enrolments()-method of the enrol_database_plugin-class is called for that user.
This method fetches the user's enrolments from the external database and stores them in an array, $enrols. The array-key is courseid, and the corresponding value is an array of roleids that the user has in the given course.
A foreach-call is used to go through $enrols, and each courseid is processed as follows:
An enrolment is reactivated or created, if necessary.
Relevant role assignments of the user on the course context are fetched from Moodle database and stored in $current.
The role assignments in $current are then compared to $roles, which is an array containing all roles that the user should have on the current course, according to the external database source. This is where things go wrong.
The code reads (from https://github.com/moodle/moodle/blob/master/enrol/database/lib.php#L187 ):
foreach ($current as $r) {
|
if (in_array($r->id, $roles)) {
|
$existing[$r->roleid] = $r->roleid;
|
} else {
|
role_unassign($r->roleid, $user->id, $context->id, 'enrol_database', $instance->id);
|
}
|
}
|
Instead of checking whether the current roleid ($r->roleid) is found in $roles (from the external db), it checks whether the role assignment id ($r->id) is found in $roles. This will rarely be the same id, so the role is unassigned at this point.
Afterwards, we loop through $roles to perform the necessary role assignments for the current course. As no role assignments have been registered as existing, all roles are reassigned.
This bug is not fatal, as the users will always see their courses, but it can put a lot of unnecessary strain on the database.
Attachments
Issue Links
- duplicates
-
MDL-30528 External database enrolment plugin is recreating role_assignments on every login attempt for each user.
-
- Closed
-