mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 02:16:41 +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
|
@ -7231,21 +7231,6 @@ class context_block extends context {
|
|||
// 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
|
||||
// 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
|
||||
|
|
|
@ -580,9 +580,11 @@ class block_manager {
|
|||
list($pagetypepatterntest, $pagetypepatternparams) =
|
||||
$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(
|
||||
'contextlevel' => CONTEXT_BLOCK,
|
||||
'subpage1' => $this->page->subpage,
|
||||
'subpage2' => $this->page->subpage,
|
||||
'contextid1' => $context->id,
|
||||
|
|
|
@ -619,7 +619,9 @@ function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")
|
|||
|
||||
$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
|
||||
FROM {course} c
|
||||
|
@ -681,7 +683,9 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c
|
|||
$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;
|
||||
if (!$limitfrom) {
|
||||
|
@ -799,7 +803,10 @@ function get_courses_search($searchterms, $sort, $page, $recordsperpage, &$total
|
|||
$limitfrom = $page * $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'));
|
||||
$sql = "SELECT c.".join(',c.',$fields)." $ccselect
|
||||
FROM {course} c
|
||||
|
|
|
@ -4306,4 +4306,33 @@ function get_courseid_from_context(context $context) {
|
|||
} else {
|
||||
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 = '';
|
||||
$ctxjoin = '';
|
||||
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
|
||||
|
@ -572,7 +574,9 @@ function enrol_get_my_courses($fields = NULL, $sort = 'visible DESC,sortorder AS
|
|||
}
|
||||
|
||||
$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);
|
||||
|
||||
//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);
|
||||
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
|
||||
$sql = "SELECT $coursefields $ccselect
|
||||
|
|
|
@ -1423,8 +1423,10 @@ class global_navigation extends navigation_node {
|
|||
if (count($fullfetch)) {
|
||||
// First up fetch all of the courses in categories where we know that we are going to
|
||||
// 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');
|
||||
$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
|
||||
FROM {course} c
|
||||
$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
|
||||
// proportion of the courses.
|
||||
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
|
||||
FROM {course} c
|
||||
$ccjoin
|
||||
WHERE c.category = :categoryid
|
||||
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);
|
||||
foreach ($coursesrs as $course) {
|
||||
if ($course->id == $SITE->id) {
|
||||
|
@ -1492,8 +1495,10 @@ class global_navigation extends navigation_node {
|
|||
}
|
||||
} else {
|
||||
// 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);
|
||||
$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
|
||||
FROM {course} c
|
||||
$ccjoin
|
||||
|
|
|
@ -2428,6 +2428,9 @@ class accesslib_testcase extends advanced_testcase {
|
|||
|
||||
context_helper::reset_caches();
|
||||
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";
|
||||
$records = $DB->get_records_sql($sql);
|
||||
foreach ($records as $record) {
|
||||
|
|
|
@ -22,6 +22,7 @@ Accesslib:
|
|||
* context_moved() -> context::update_moved()
|
||||
* preload_course_contexts() -> context_helper::preload_course()
|
||||
* 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()
|
||||
* create_contexts() -> context_helper::create_instances()
|
||||
* cleanup_contexts() -> context_helper::cleanup_instances()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue