Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-31053 fix invalid context preloading in get_user_capability_course()

  • Loading branch information...
commit 182f5cc6f61f43e665db9ef1803e8d477b460c99 1 parent f70f6e9
@skodak skodak authored
Showing with 9 additions and 10 deletions.
  1. +9 −10 lib/accesslib.php
View
19 lib/accesslib.php
@@ -3859,22 +3859,21 @@ function get_user_capability_course($capability, $userid = null, $doanything = t
// Note the result can be used directly as a context (we are going to), the course
// fields are just appended.
+ $contextpreload = context_helper::get_preload_record_columns_sql('x');
+
$courses = array();
- $rs = $DB->get_recordset_sql("SELECT x.*, c.id AS courseid $fieldlist
+ $rs = $DB->get_recordset_sql("SELECT c.id $fieldlist, $contextpreload
FROM {course} c
- INNER JOIN {context} x
- ON (c.id=x.instanceid AND x.contextlevel=".CONTEXT_COURSE.")
+ JOIN {context} x ON (c.id=x.instanceid AND x.contextlevel=".CONTEXT_COURSE.")
$orderby");
// Check capability for each course in turn
- foreach ($rs as $coursecontext) {
- if (has_capability($capability, $coursecontext, $userid, $doanything)) {
+ foreach ($rs as $course) {
+ context_helper::preload_from_record($course);
+ $context = context_course::instance($course->id);
+ if (has_capability($capability, $context, $userid, $doanything)) {
// We've got the capability. Make the record look like a course record
// and store it
- $coursecontext->id = $coursecontext->courseid;
- unset($coursecontext->courseid);
- unset($coursecontext->contextlevel);
- unset($coursecontext->instanceid);
- $courses[] = $coursecontext;
+ $courses[] = $course;
}
}
$rs->close();
Please sign in to comment.
Something went wrong with that request. Please try again.