Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Avoid "some" ra's duplicates. MDL-14817

  • Loading branch information...
commit 9f00b6e8b4d88d8916fd0bc3a2d197e53381622a 1 parent 4be2bb4
stronk7 authored

Showing 1 changed file with 13 additions and 6 deletions. Show diff stats Hide diff stats

  1. +13 6 lib/accesslib.php
19 lib/accesslib.php
@@ -1096,7 +1096,7 @@ function get_user_access_sitewide($userid) {
1096 1096 LEFT OUTER JOIN {$CFG->prefix}role_capabilities rc
1097 1097 ON (rc.roleid=ra.roleid AND rc.contextid=ra.contextid)
1098 1098 WHERE ra.userid = $userid AND ctx.contextlevel <= ".CONTEXT_COURSE."
1099   - ORDER BY ctx.depth, ctx.path";
  1099 + ORDER BY ctx.depth, ctx.path, ra.roleid";
1100 1100 $rs = get_recordset_sql($sql);
1101 1101 //
1102 1102 // raparents collects paths & roles we need to walk up
@@ -1269,19 +1269,26 @@ function load_subcontext($userid, $context, &$accessdata) {
1269 1269 ON ra.contextid=ctx.id
1270 1270 WHERE ra.userid = $userid
1271 1271 AND (ctx.path = '{$context->path}' OR ctx.path LIKE '{$context->path}/%')
1272   - ORDER BY ctx.depth, ctx.path";
  1272 + ORDER BY ctx.depth, ctx.path, ra.roleid";
1273 1273 $rs = get_recordset_sql($sql);
1274 1274
1275   - //
1276   - // Read in the RAs
  1275 + //
  1276 + // Read in the RAs, preventing duplicates
1277 1277 //
1278 1278 $localroles = array();
  1279 + $lastseen = '';
1279 1280 while ($ra = rs_fetch_next_record($rs)) {
1280 1281 if (!isset($accessdata['ra'][$ra->path])) {
1281 1282 $accessdata['ra'][$ra->path] = array();
1282 1283 }
1283   - array_push($accessdata['ra'][$ra->path], $ra->roleid);
1284   - array_push($localroles, $ra->roleid);
  1284 + // only add if is not a repeat caused
  1285 + // by capability join...
  1286 + // (this check is cheaper than in_array())
  1287 + if ($lastseen !== $ra->path.':'.$ra->roleid) {
  1288 + $lastseen = $ra->path.':'.$ra->roleid;
  1289 + array_push($accessdata['ra'][$ra->path], $ra->roleid);
  1290 + array_push($localroles, $ra->roleid);
  1291 + }
1285 1292 }
1286 1293 rs_close($rs);
1287 1294

0 comments on commit 9f00b6e

Please sign in to comment.
Something went wrong with that request. Please try again.