Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.6, 3.5.4, 3.6.2, 3.7
-
MOODLE_26_STABLE, MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE
-
MOODLE_35_STABLE, MOODLE_36_STABLE
-
- Run vendor/bin/phpunit lib/tests/accesslib_test.php
- Confirm testcase passes
Description
For system roles, where the users can be assigned from different sources, the count field is sometimes incorrect as it counts the same user multiple times.
Following diff seemed to fix it here:
accesslib.php |
diff --git a/lib/accesslib.php b/lib/accesslib.php
|
index 45f07b4..5d3876e 100644
|
--- a/lib/accesslib.php
|
+++ b/lib/accesslib.php
|
@@ -3371,7 +3371,7 @@ function get_assignable_roles(context $context, $rolenamedisplay = ROLENAME_ALIA
|
$extrafields = '';
|
|
if ($withusercounts) {
|
- $extrafields = ', (SELECT count(u.id)
|
+ $extrafields = ', (SELECT count(DISTINCT u.id)
|
FROM {role_assignments} cra JOIN {user} u ON cra.userid = u.id
|
WHERE cra.roleid = r.id AND cra.contextid = :conid AND u.deleted = 0
|
) AS usercount';
|
Attachments
Issue Links
- has a non-specific relationship to
-
MDL-60028 Count enrolled users can count users more than once when users have been enrolled using different enrollment methods
-
- Closed
-
- has been marked as being related by
-
MDL-49613 count_role_users gives unexpected results
-
- Closed
-
- will be (partly) resolved by
-
MDL-45623 Incorrect user assignment count when deleting roles
-
- Closed
-