MDL-46931 roles: retrieve distinct users in sub-query.
authorPaul Holden <pholden@greenhead.ac.uk>
Fri, 8 Mar 2019 14:40:41 +0000 (14:40 +0000)
committerPaul Holden <pholden@greenhead.ac.uk>
Fri, 8 Mar 2019 14:40:41 +0000 (14:40 +0000)
Prevents duplicate key column warning when a user is enrolled in
a course via multiple enrolment methods.

admin/roles/classes/check_users_selector.php

index 5ac4c26..31929bd 100644 (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;