mirror of
https://github.com/moodle/moodle.git
synced 2025-08-03 08:09:47 +02:00
Merge branch 'MDL-40424-master' of git://github.com/FMCorz/moodle
Conflicts: admin/oacleanup.php
This commit is contained in:
commit
fb1788c598
18 changed files with 105 additions and 46 deletions
|
@ -39,9 +39,10 @@ while(!feof($fd)) {
|
||||||
$action = clam_handle_infected_file($file,$log->userid,true);
|
$action = clam_handle_infected_file($file,$log->userid,true);
|
||||||
clam_replace_infected_file($file);
|
clam_replace_infected_file($file);
|
||||||
|
|
||||||
list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
$ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
$sql = "SELECT c.id, c.fullname $ctxselect FROM {course} c $ctxjoin WHERE c.id = :courseid";
|
$sql = "SELECT c.id, c.fullname $ctxselect FROM {course} c $ctxjoin WHERE c.id = :courseid";
|
||||||
$course = $DB->get_record_sql($sql, array('courseid' => $log->course));
|
$course = $DB->get_record_sql($sql, array('courseid' => $log->course, 'contextlevel' => CONTEXT_COURSE));
|
||||||
context_helper::preload_from_record($course);
|
context_helper::preload_from_record($course);
|
||||||
|
|
||||||
$user = $DB->get_record("user", array("id"=>$log->userid));
|
$user = $DB->get_record("user", array("id"=>$log->userid));
|
||||||
|
|
|
@ -277,8 +277,10 @@ class restore_course_search extends restore_search_base {
|
||||||
protected function get_searchsql() {
|
protected function get_searchsql() {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
$ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
$params = array(
|
$params = array(
|
||||||
|
'contextlevel' => CONTEXT_COURSE,
|
||||||
'fullnamesearch' => '%'.$this->get_search().'%',
|
'fullnamesearch' => '%'.$this->get_search().'%',
|
||||||
'shortnamesearch' => '%'.$this->get_search().'%',
|
'shortnamesearch' => '%'.$this->get_search().'%',
|
||||||
'siteid' => SITEID
|
'siteid' => SITEID
|
||||||
|
@ -326,8 +328,10 @@ class restore_category_search extends restore_search_base {
|
||||||
protected function get_searchsql() {
|
protected function get_searchsql() {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSECAT, 'ctx');
|
$ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
$params = array(
|
$params = array(
|
||||||
|
'contextlevel' => CONTEXT_COURSECAT,
|
||||||
'namesearch' => '%'.$this->get_search().'%',
|
'namesearch' => '%'.$this->get_search().'%',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1568,13 +1568,14 @@ function calendar_get_default_courses() {
|
||||||
|
|
||||||
$courses = array();
|
$courses = array();
|
||||||
if (!empty($CFG->calendar_adminseesall) && has_capability('moodle/calendar:manageentries', context_system::instance())) {
|
if (!empty($CFG->calendar_adminseesall) && has_capability('moodle/calendar:manageentries', context_system::instance())) {
|
||||||
list ($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
$select = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$join = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
$sql = "SELECT c.* $select
|
$sql = "SELECT c.* $select
|
||||||
FROM {course} c
|
FROM {course} c
|
||||||
$join
|
$join
|
||||||
WHERE EXISTS (SELECT 1 FROM {event} e WHERE e.courseid = c.id)
|
WHERE EXISTS (SELECT 1 FROM {event} e WHERE e.courseid = c.id)
|
||||||
";
|
";
|
||||||
$courses = $DB->get_records_sql($sql, null, 0, 20);
|
$courses = $DB->get_records_sql($sql, array('contextlevel' => CONTEXT_COURSE), 0, 20);
|
||||||
foreach ($courses as $course) {
|
foreach ($courses as $course) {
|
||||||
context_helper::preload_from_record($course);
|
context_helper::preload_from_record($course);
|
||||||
}
|
}
|
||||||
|
|
|
@ -458,8 +458,9 @@ class core_enrol_external extends external_api {
|
||||||
}
|
}
|
||||||
|
|
||||||
list($enrolledsql, $enrolledparams) = get_enrolled_sql($coursecontext, $withcapability, $groupid, $onlyactive);
|
list($enrolledsql, $enrolledparams) = get_enrolled_sql($coursecontext, $withcapability, $groupid, $onlyactive);
|
||||||
list($ctxselect, $ctxjoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx');
|
$ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
$sqlparams['courseid'] = $courseid;
|
$ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
$enrolledparams['contextlevel'] = CONTEXT_USER;
|
||||||
$sql = "SELECT u.* $ctxselect
|
$sql = "SELECT u.* $ctxselect
|
||||||
FROM {user} u $ctxjoin
|
FROM {user} u $ctxjoin
|
||||||
WHERE u.id IN ($enrolledsql)
|
WHERE u.id IN ($enrolledsql)
|
||||||
|
|
|
@ -40,9 +40,10 @@ class enrol_meta_addinstance_form extends moodleform {
|
||||||
|
|
||||||
// TODO: this has to be done via ajax or else it will fail very badly on large sites!
|
// TODO: this has to be done via ajax or else it will fail very badly on large sites!
|
||||||
$courses = array('' => get_string('choosedots'));
|
$courses = array('' => get_string('choosedots'));
|
||||||
list ($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
$select = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$join = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
$sql = "SELECT c.id, c.fullname, c.shortname, c.visible $select FROM {course} c $join ORDER BY c.sortorder ASC";
|
$sql = "SELECT c.id, c.fullname, c.shortname, c.visible $select FROM {course} c $join ORDER BY c.sortorder ASC";
|
||||||
$rs = $DB->get_recordset_sql($sql);
|
$rs = $DB->get_recordset_sql($sql, array('contextlevel' => CONTEXT_COURSE));
|
||||||
foreach ($rs as $c) {
|
foreach ($rs as $c) {
|
||||||
if ($c->id == SITEID or $c->id == $course->id or isset($existing[$c->id])) {
|
if ($c->id == SITEID or $c->id == $course->id or isset($existing[$c->id])) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -7231,21 +7231,6 @@ class context_block extends context {
|
||||||
// before removing devs will be warned with a debugging message first,
|
// before removing devs will be warned with a debugging message first,
|
||||||
// then we will add error message and only after that we can remove the functions
|
// then we will add error message and only after that we can remove the functions
|
||||||
// completely.
|
// completely.
|
||||||
/**
|
|
||||||
* Preloads context information together with instances.
|
|
||||||
* Use context_helper::preload_from_record() to strip the context info from the record and cache the context instance.
|
|
||||||
*
|
|
||||||
* @deprecated since 2.2
|
|
||||||
* @param string $joinon for example 'u.id'
|
|
||||||
* @param string $contextlevel context level of instance in $joinon
|
|
||||||
* @param string $tablealias context table alias
|
|
||||||
* @return array with two values - select and join part
|
|
||||||
*/
|
|
||||||
function context_instance_preload_sql($joinon, $contextlevel, $tablealias) {
|
|
||||||
$select = ", ".context_helper::get_preload_record_columns_sql($tablealias);
|
|
||||||
$join = "LEFT JOIN {context} $tablealias ON ($tablealias.instanceid = $joinon AND $tablealias.contextlevel = $contextlevel)";
|
|
||||||
return array($select, $join);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs get_records select on context table and returns the result
|
* Runs get_records select on context table and returns the result
|
||||||
|
|
|
@ -580,9 +580,11 @@ class block_manager {
|
||||||
list($pagetypepatterntest, $pagetypepatternparams) =
|
list($pagetypepatterntest, $pagetypepatternparams) =
|
||||||
$DB->get_in_or_equal($pagetypepatterns, SQL_PARAMS_NAMED, 'pagetypepatterntest');
|
$DB->get_in_or_equal($pagetypepatterns, SQL_PARAMS_NAMED, 'pagetypepatterntest');
|
||||||
|
|
||||||
list($ccselect, $ccjoin) = context_instance_preload_sql('bi.id', CONTEXT_BLOCK, 'ctx');
|
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = bi.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
|
'contextlevel' => CONTEXT_BLOCK,
|
||||||
'subpage1' => $this->page->subpage,
|
'subpage1' => $this->page->subpage,
|
||||||
'subpage2' => $this->page->subpage,
|
'subpage2' => $this->page->subpage,
|
||||||
'contextid1' => $context->id,
|
'contextid1' => $context->id,
|
||||||
|
|
|
@ -619,7 +619,9 @@ function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")
|
||||||
|
|
||||||
$visiblecourses = array();
|
$visiblecourses = array();
|
||||||
|
|
||||||
list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
$params['contextlevel'] = CONTEXT_COURSE;
|
||||||
|
|
||||||
$sql = "SELECT $fields $ccselect
|
$sql = "SELECT $fields $ccselect
|
||||||
FROM {course} c
|
FROM {course} c
|
||||||
|
@ -681,7 +683,9 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c
|
||||||
$categoryselect = "";
|
$categoryselect = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
$params['contextlevel'] = CONTEXT_COURSE;
|
||||||
|
|
||||||
$totalcount = 0;
|
$totalcount = 0;
|
||||||
if (!$limitfrom) {
|
if (!$limitfrom) {
|
||||||
|
@ -799,7 +803,10 @@ function get_courses_search($searchterms, $sort, $page, $recordsperpage, &$total
|
||||||
$limitfrom = $page * $recordsperpage;
|
$limitfrom = $page * $recordsperpage;
|
||||||
$limitto = $limitfrom + $recordsperpage;
|
$limitto = $limitfrom + $recordsperpage;
|
||||||
|
|
||||||
list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
$params['contextlevel'] = CONTEXT_COURSE;
|
||||||
|
|
||||||
$fields = array_diff(array_keys($DB->get_columns('course')), array('modinfo', 'sectioncache'));
|
$fields = array_diff(array_keys($DB->get_columns('course')), array('modinfo', 'sectioncache'));
|
||||||
$sql = "SELECT c.".join(',c.',$fields)." $ccselect
|
$sql = "SELECT c.".join(',c.',$fields)." $ccselect
|
||||||
FROM {course} c
|
FROM {course} c
|
||||||
|
|
|
@ -4306,4 +4306,33 @@ function get_courseid_from_context(context $context) {
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preloads context information together with instances.
|
||||||
|
* Use context_instance_preload() to strip the context info from the record and cache the context instance.
|
||||||
|
*
|
||||||
|
* If you are using this methid, you should have something like this:
|
||||||
|
*
|
||||||
|
* list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
||||||
|
*
|
||||||
|
* To prevent the use of this deprecated function, replace the line above with something similar to this:
|
||||||
|
*
|
||||||
|
* $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
* ^
|
||||||
|
* $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
* ^ ^ ^ ^
|
||||||
|
* $params = array('contextlevel' => CONTEXT_COURSE);
|
||||||
|
* ^
|
||||||
|
* @see context_helper:;get_preload_record_columns_sql()
|
||||||
|
* @deprecated since 2.2
|
||||||
|
* @param string $joinon for example 'u.id'
|
||||||
|
* @param string $contextlevel context level of instance in $joinon
|
||||||
|
* @param string $tablealias context table alias
|
||||||
|
* @return array with two values - select and join part
|
||||||
|
*/
|
||||||
|
function context_instance_preload_sql($joinon, $contextlevel, $tablealias) {
|
||||||
|
debugging('context_instance_preload_sql() is deprecated, please use context_helper::get_preload_record_columns_sql() instead.', DEBUG_DEVELOPER);
|
||||||
|
$select = ", " . context_helper::get_preload_record_columns_sql($tablealias);
|
||||||
|
$join = "LEFT JOIN {context} $tablealias ON ($tablealias.instanceid = $joinon AND $tablealias.contextlevel = $contextlevel)";
|
||||||
|
return array($select, $join);
|
||||||
}
|
}
|
||||||
|
|
|
@ -276,7 +276,9 @@ function enrol_get_shared_courses($user1, $user2, $preloadcontexts = false, $che
|
||||||
$ctxselect = '';
|
$ctxselect = '';
|
||||||
$ctxjoin = '';
|
$ctxjoin = '';
|
||||||
if ($preloadcontexts) {
|
if ($preloadcontexts) {
|
||||||
list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
$ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
$params['contextlevel'] = CONTEXT_COURSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT c.* $ctxselect
|
$sql = "SELECT c.* $ctxselect
|
||||||
|
@ -572,7 +574,9 @@ function enrol_get_my_courses($fields = NULL, $sort = 'visible DESC,sortorder AS
|
||||||
}
|
}
|
||||||
|
|
||||||
$coursefields = 'c.' .join(',c.', $fields);
|
$coursefields = 'c.' .join(',c.', $fields);
|
||||||
list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
$params['contextlevel'] = CONTEXT_COURSE;
|
||||||
$wheres = implode(" AND ", $wheres);
|
$wheres = implode(" AND ", $wheres);
|
||||||
|
|
||||||
//note: we can not use DISTINCT + text fields due to Oracle and MS limitations, that is why we have the subselect there
|
//note: we can not use DISTINCT + text fields due to Oracle and MS limitations, that is why we have the subselect there
|
||||||
|
@ -830,7 +834,9 @@ function enrol_get_all_users_courses($userid, $onlyactive = false, $fields = NUL
|
||||||
}
|
}
|
||||||
|
|
||||||
$coursefields = 'c.' .join(',c.', $fields);
|
$coursefields = 'c.' .join(',c.', $fields);
|
||||||
list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
$params['contextlevel'] = CONTEXT_COURSE;
|
||||||
|
|
||||||
//note: we can not use DISTINCT + text fields due to Oracle and MS limitations, that is why we have the subselect there
|
//note: we can not use DISTINCT + text fields due to Oracle and MS limitations, that is why we have the subselect there
|
||||||
$sql = "SELECT $coursefields $ccselect
|
$sql = "SELECT $coursefields $ccselect
|
||||||
|
|
|
@ -1423,8 +1423,10 @@ class global_navigation extends navigation_node {
|
||||||
if (count($fullfetch)) {
|
if (count($fullfetch)) {
|
||||||
// First up fetch all of the courses in categories where we know that we are going to
|
// First up fetch all of the courses in categories where we know that we are going to
|
||||||
// need the majority of courses.
|
// need the majority of courses.
|
||||||
list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
|
||||||
list($categoryids, $categoryparams) = $DB->get_in_or_equal($fullfetch, SQL_PARAMS_NAMED, 'lcategory');
|
list($categoryids, $categoryparams) = $DB->get_in_or_equal($fullfetch, SQL_PARAMS_NAMED, 'lcategory');
|
||||||
|
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
$categoryparams['contextlevel'] = CONTEXT_COURSE;
|
||||||
$sql = "SELECT c.id, c.sortorder, c.visible, c.fullname, c.shortname, c.category $ccselect
|
$sql = "SELECT c.id, c.sortorder, c.visible, c.fullname, c.shortname, c.category $ccselect
|
||||||
FROM {course} c
|
FROM {course} c
|
||||||
$ccjoin
|
$ccjoin
|
||||||
|
@ -1458,13 +1460,14 @@ class global_navigation extends navigation_node {
|
||||||
// Next we will work our way through the categories where we will likely only need a small
|
// Next we will work our way through the categories where we will likely only need a small
|
||||||
// proportion of the courses.
|
// proportion of the courses.
|
||||||
foreach ($partfetch as $categoryid) {
|
foreach ($partfetch as $categoryid) {
|
||||||
list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
$sql = "SELECT c.id, c.sortorder, c.visible, c.fullname, c.shortname, c.category $ccselect
|
$sql = "SELECT c.id, c.sortorder, c.visible, c.fullname, c.shortname, c.category $ccselect
|
||||||
FROM {course} c
|
FROM {course} c
|
||||||
$ccjoin
|
$ccjoin
|
||||||
WHERE c.category = :categoryid
|
WHERE c.category = :categoryid
|
||||||
ORDER BY c.sortorder ASC";
|
ORDER BY c.sortorder ASC";
|
||||||
$courseparams = array('categoryid' => $categoryid);
|
$courseparams = array('categoryid' => $categoryid, 'contextlevel' => CONTEXT_COURSE);
|
||||||
$coursesrs = $DB->get_recordset_sql($sql, $courseparams, 0, $limit * 5);
|
$coursesrs = $DB->get_recordset_sql($sql, $courseparams, 0, $limit * 5);
|
||||||
foreach ($coursesrs as $course) {
|
foreach ($coursesrs as $course) {
|
||||||
if ($course->id == $SITE->id) {
|
if ($course->id == $SITE->id) {
|
||||||
|
@ -1492,8 +1495,10 @@ class global_navigation extends navigation_node {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Prepare the SQL to load the courses and their contexts
|
// Prepare the SQL to load the courses and their contexts
|
||||||
list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
|
||||||
list($courseids, $courseparams) = $DB->get_in_or_equal(array_keys($this->addedcourses), SQL_PARAMS_NAMED, 'lc', false);
|
list($courseids, $courseparams) = $DB->get_in_or_equal(array_keys($this->addedcourses), SQL_PARAMS_NAMED, 'lc', false);
|
||||||
|
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
$courseparams['contextlevel'] = CONTEXT_COURSE;
|
||||||
$sql = "SELECT c.id, c.sortorder, c.visible, c.fullname, c.shortname, c.category $ccselect
|
$sql = "SELECT c.id, c.sortorder, c.visible, c.fullname, c.shortname, c.category $ccselect
|
||||||
FROM {course} c
|
FROM {course} c
|
||||||
$ccjoin
|
$ccjoin
|
||||||
|
|
|
@ -2428,6 +2428,9 @@ class accesslib_testcase extends advanced_testcase {
|
||||||
|
|
||||||
context_helper::reset_caches();
|
context_helper::reset_caches();
|
||||||
list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSECAT, 'ctx');
|
list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSECAT, 'ctx');
|
||||||
|
$this->assertDebuggingCalled('context_instance_preload_sql() is deprecated, please use context_helper::get_preload_record_columns_sql() instead.', DEBUG_DEVELOPER);
|
||||||
|
$this->assertEquals(', ' . context_helper::get_preload_record_columns_sql('ctx'), $select);
|
||||||
|
$this->assertEquals('LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = ' . CONTEXT_COURSECAT . ')', $join);
|
||||||
$sql = "SELECT c.id $select FROM {course_categories} c $join";
|
$sql = "SELECT c.id $select FROM {course_categories} c $join";
|
||||||
$records = $DB->get_records_sql($sql);
|
$records = $DB->get_records_sql($sql);
|
||||||
foreach ($records as $record) {
|
foreach ($records as $record) {
|
||||||
|
|
|
@ -22,6 +22,7 @@ Accesslib:
|
||||||
* context_moved() -> context::update_moved()
|
* context_moved() -> context::update_moved()
|
||||||
* preload_course_contexts() -> context_helper::preload_course()
|
* preload_course_contexts() -> context_helper::preload_course()
|
||||||
* context_instance_preload() -> context_helper::preload_from_record()
|
* context_instance_preload() -> context_helper::preload_from_record()
|
||||||
|
* context_instance_preload_sql()-> context_helper::get_preload_record_columns_sql()
|
||||||
* get_contextlevel_name() -> context_helper::get_level_name()
|
* get_contextlevel_name() -> context_helper::get_level_name()
|
||||||
* create_contexts() -> context_helper::create_instances()
|
* create_contexts() -> context_helper::create_instances()
|
||||||
* cleanup_contexts() -> context_helper::cleanup_instances()
|
* cleanup_contexts() -> context_helper::cleanup_instances()
|
||||||
|
|
|
@ -8186,7 +8186,9 @@ function forum_get_courses_user_posted_in($user, $discussionsonly = false, $incl
|
||||||
|
|
||||||
// Join to the context table so that we can preload contexts if required.
|
// Join to the context table so that we can preload contexts if required.
|
||||||
if ($includecontexts) {
|
if ($includecontexts) {
|
||||||
list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
$ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
$params['contextlevel'] = CONTEXT_COURSE;
|
||||||
} else {
|
} else {
|
||||||
$ctxselect = '';
|
$ctxselect = '';
|
||||||
$ctxjoin = '';
|
$ctxjoin = '';
|
||||||
|
|
|
@ -791,15 +791,17 @@ class rating_manager {
|
||||||
$modulename = $options->modulename;
|
$modulename = $options->modulename;
|
||||||
$moduleid = intval($options->moduleid);
|
$moduleid = intval($options->moduleid);
|
||||||
|
|
||||||
//going direct to the db for the context id seems wrong
|
// Going direct to the db for the context id seems wrong.
|
||||||
list($ctxselect, $ctxjoin) = context_instance_preload_sql('cm.id', CONTEXT_MODULE, 'ctx');
|
$ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = cm.id AND ctx.contextlevel = :contextlevel)";
|
||||||
$sql = "SELECT cm.* $ctxselect
|
$sql = "SELECT cm.* $ctxselect
|
||||||
FROM {course_modules} cm
|
FROM {course_modules} cm
|
||||||
LEFT JOIN {modules} mo ON mo.id = cm.module
|
LEFT JOIN {modules} mo ON mo.id = cm.module
|
||||||
LEFT JOIN {{$modulename}} m ON m.id = cm.instance $ctxjoin
|
LEFT JOIN {{$modulename}} m ON m.id = cm.instance $ctxjoin
|
||||||
WHERE mo.name=:modulename AND
|
WHERE mo.name=:modulename AND
|
||||||
m.id=:moduleid";
|
m.id=:moduleid";
|
||||||
$contextrecord = $DB->get_record_sql($sql, array('modulename'=>$modulename, 'moduleid'=>$moduleid), '*', MUST_EXIST);
|
$params = array('modulename' => $modulename, 'moduleid' => $moduleid, 'contextlevel' => CONTEXT_MODULE);
|
||||||
|
$contextrecord = $DB->get_record_sql($sql, $params, '*', MUST_EXIST);
|
||||||
$contextid = $contextrecord->ctxid;
|
$contextid = $contextrecord->ctxid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,12 +49,13 @@ $strunfinished = get_string("unfinished");
|
||||||
$strskipped = get_string("skipped");
|
$strskipped = get_string("skipped");
|
||||||
$strwarning = get_string("warning");
|
$strwarning = get_string("warning");
|
||||||
|
|
||||||
list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
$select = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$join = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
$sql = "SELECT bc.*, c.fullname $select
|
$sql = "SELECT bc.*, c.fullname $select
|
||||||
FROM {backup_courses} bc
|
FROM {backup_courses} bc
|
||||||
JOIN {course} c ON c.id = bc.courseid
|
JOIN {course} c ON c.id = bc.courseid
|
||||||
$join";
|
$join";
|
||||||
$rs = $DB->get_recordset_sql($sql);
|
$rs = $DB->get_recordset_sql($sql, array('contextlevel' => CONTEXT_COURSE));
|
||||||
foreach ($rs as $backuprow) {
|
foreach ($rs as $backuprow) {
|
||||||
|
|
||||||
// Cache the course context
|
// Cache the course context
|
||||||
|
|
|
@ -678,8 +678,10 @@ class core_user_external extends external_api {
|
||||||
$params = self::validate_parameters(self::get_users_by_id_parameters(),
|
$params = self::validate_parameters(self::get_users_by_id_parameters(),
|
||||||
array('userids'=>$userids));
|
array('userids'=>$userids));
|
||||||
|
|
||||||
list($uselect, $ujoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx');
|
|
||||||
list($sqluserids, $params) = $DB->get_in_or_equal($userids);
|
list($sqluserids, $params) = $DB->get_in_or_equal($userids);
|
||||||
|
$uselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ujoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
$params['contextlevel'] = CONTEXT_USER;
|
||||||
$usersql = "SELECT u.* $uselect
|
$usersql = "SELECT u.* $uselect
|
||||||
FROM {user} u $ujoin
|
FROM {user} u $ujoin
|
||||||
WHERE u.id $sqluserids";
|
WHERE u.id $sqluserids";
|
||||||
|
@ -778,8 +780,10 @@ class core_user_external extends external_api {
|
||||||
|
|
||||||
// cache all courses
|
// cache all courses
|
||||||
$courses = array();
|
$courses = array();
|
||||||
list($cselect, $cjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
|
||||||
list($sqlcourseids, $params) = $DB->get_in_or_equal(array_unique($courseids));
|
list($sqlcourseids, $params) = $DB->get_in_or_equal(array_unique($courseids));
|
||||||
|
$cselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$cjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
$params['contextlevel'] = CONTEXT_COURSE;
|
||||||
$coursesql = "SELECT c.* $cselect
|
$coursesql = "SELECT c.* $cselect
|
||||||
FROM {course} c $cjoin
|
FROM {course} c $cjoin
|
||||||
WHERE c.id $sqlcourseids";
|
WHERE c.id $sqlcourseids";
|
||||||
|
@ -792,8 +796,10 @@ class core_user_external extends external_api {
|
||||||
}
|
}
|
||||||
$rs->close();
|
$rs->close();
|
||||||
|
|
||||||
list($uselect, $ujoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx');
|
|
||||||
list($sqluserids, $params) = $DB->get_in_or_equal($userids);
|
list($sqluserids, $params) = $DB->get_in_or_equal($userids);
|
||||||
|
$uselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ujoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
$params['contextlevel'] = CONTEXT_USER;
|
||||||
$usersql = "SELECT u.* $uselect
|
$usersql = "SELECT u.* $uselect
|
||||||
FROM {user} u $ujoin
|
FROM {user} u $ujoin
|
||||||
WHERE u.id $sqluserids";
|
WHERE u.id $sqluserids";
|
||||||
|
|
|
@ -401,7 +401,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// performance hacks - we preload user contexts together with accounts
|
// performance hacks - we preload user contexts together with accounts
|
||||||
list($ccselect, $ccjoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx');
|
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
|
||||||
|
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)";
|
||||||
|
$params['contextlevel'] = CONTEXT_USER;
|
||||||
$select .= $ccselect;
|
$select .= $ccselect;
|
||||||
$joins[] = $ccjoin;
|
$joins[] = $ccjoin;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue