mirror of
https://github.com/moodle/moodle.git
synced 2025-02-13 12:34:28 +01:00
MDL-31053 fix invalid context preloading in get_user_capability_course()
This commit is contained in:
parent
a75386fba6
commit
5c2abc463f
@ -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
|
// Note the result can be used directly as a context (we are going to), the course
|
||||||
// fields are just appended.
|
// fields are just appended.
|
||||||
|
|
||||||
|
$contextpreload = context_helper::get_preload_record_columns_sql('x');
|
||||||
|
|
||||||
$courses = array();
|
$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
|
FROM {course} c
|
||||||
INNER JOIN {context} x
|
JOIN {context} x ON (c.id=x.instanceid AND x.contextlevel=".CONTEXT_COURSE.")
|
||||||
ON (c.id=x.instanceid AND x.contextlevel=".CONTEXT_COURSE.")
|
|
||||||
$orderby");
|
$orderby");
|
||||||
// Check capability for each course in turn
|
// Check capability for each course in turn
|
||||||
foreach ($rs as $coursecontext) {
|
foreach ($rs as $course) {
|
||||||
if (has_capability($capability, $coursecontext, $userid, $doanything)) {
|
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
|
// We've got the capability. Make the record look like a course record
|
||||||
// and store it
|
// and store it
|
||||||
$coursecontext->id = $coursecontext->courseid;
|
$courses[] = $course;
|
||||||
unset($coursecontext->courseid);
|
|
||||||
unset($coursecontext->contextlevel);
|
|
||||||
unset($coursecontext->instanceid);
|
|
||||||
$courses[] = $coursecontext;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$rs->close();
|
$rs->close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user