MDL-46931 roles: retrieve distinct users in sub-query.

Prevents duplicate key column warning when a user is enrolled in
a course via multiple enrolment methods.
This commit is contained in:
Paul Holden 2019-03-08 14:40:41 +00:00
parent a713ed3ba6
commit 47e466c958

View File

@ -69,8 +69,11 @@ class core_role_check_users_selector extends user_selector_base {
if ($coursecontext and $coursecontext != SITEID) {
$sql1 = " FROM {user} u
JOIN {user_enrolments} ue ON (ue.userid = u.id)
JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid1)
JOIN (SELECT DISTINCT subu.id
FROM {user} subu
JOIN {user_enrolments} ue ON (ue.userid = subu.id)
JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid1)
) subq ON subq.id = u.id
WHERE $wherecondition";
$params['courseid1'] = $coursecontext->instanceid;