MDL-40425 libraries: Remove context_instance_preload() from core

This commit is contained in:
Ankit Agarwal 2013-07-05 11:48:36 +08:00
parent c5dcd25d5f
commit db314f34fb
14 changed files with 27 additions and 27 deletions

View File

@ -42,7 +42,7 @@ while(!feof($fd)) {
list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
$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));
context_instance_preload($course);
context_helper::preload_from_record($course);
$user = $DB->get_record("user", array("id"=>$log->userid));
$subject = get_string('virusfoundsubject','moodle',format_string($site->fullname));

View File

@ -48,7 +48,7 @@ function online_assignment_cleanup($output=false) {
/// cycle through each course
foreach ($courses as $course) {
context_instance_preload($course);
context_helper::preload_from_record($course);
$context = context_course::instance($course->id);
if (empty($course->fullname)) {

View File

@ -191,7 +191,7 @@ abstract class restore_search_base implements renderable {
while ($totalcourses > $offs and $this->totalcount < $this->maxresults) {
$resultset = $DB->get_records_sql($sql, $params, $offs, $blocksz);
foreach ($resultset as $result) {
context_instance_preload($result);
context_helper::preload_from_record($result);
$classname = context_helper::get_class_for_level($contextlevel);
$context = $classname::instance($result->id);
if (count($requiredcaps) > 0) {

View File

@ -467,7 +467,7 @@ class core_enrol_external extends external_api {
$enrolledusers = $DB->get_recordset_sql($sql, $enrolledparams, $limitfrom, $limitnumber);
$users = array();
foreach ($enrolledusers as $user) {
context_instance_preload($user);
context_helper::preload_from_record($user);
if ($userdetails = user_get_user_details($user, $course, $userfields)) {
$users[] = $userdetails;
}

View File

@ -7232,7 +7232,7 @@ class context_block extends context {
// completely.
/**
* Preloads context information together with instances.
* Use context_instance_preload() to strip the context info from the record and cache the context instance.
* 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'

View File

@ -630,7 +630,7 @@ class block_manager {
$this->birecordsbyregion = $this->prepare_per_region_arrays();
$unknown = array();
foreach ($blockinstances as $bi) {
context_instance_preload($bi);
context_helper::preload_from_record($bi);
if ($this->is_known_region($bi->region)) {
$this->birecordsbyregion[$bi->region][] = $bi;
} else {

View File

@ -2034,7 +2034,7 @@ class course_in_list implements IteratorAggregate {
* context preloading
*/
public function __construct(stdClass $record) {
context_instance_preload($record);
context_helper::preload_from_record($record);
$this->record = new stdClass();
foreach ($record as $key => $value) {
$this->record->$key = $value;

View File

@ -632,7 +632,7 @@ function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")
// loop throught them
foreach ($courses as $course) {
context_instance_preload($course);
context_helper::preload_from_record($course);
if (isset($course->visible) && $course->visible <= 0) {
// for hidden courses, require visibility check
if (has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
@ -699,7 +699,7 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c
$rs = $DB->get_recordset_sql($sql, $params);
// iteration will have to be done inside loop to keep track of the limitfrom and limitnum
foreach($rs as $course) {
context_instance_preload($course);
context_helper::preload_from_record($course);
if ($course->visible <= 0) {
// for hidden courses, require visibility check
if (has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
@ -811,7 +811,7 @@ function get_courses_search($searchterms, $sort, $page, $recordsperpage, &$total
foreach($rs as $course) {
if (!$course->visible) {
// preload contexts only for hidden courses or courses we need to return
context_instance_preload($course);
context_helper::preload_from_record($course);
$coursecontext = context_course::instance($course->id);
if (!has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
continue;

View File

@ -599,7 +599,7 @@ function get_recent_enrolments($courseid, $timestart) {
* This allows us to SELECT from major tables JOINing with
* context at no cost, saving a ton of context lookups...
*
* Use context_instance_preload() instead.
* Use context_helper::preload_from_record() instead.
*
* @deprecated since 2.0
* @param object $rec
@ -612,7 +612,7 @@ function make_context_subobj($rec) {
/**
* Do some basic, quick checks to see whether $rec->context looks like a valid context object.
*
* Use context_instance_preload() instead.
* Use context_helper::preload_from_record() instead.
*
* @deprecated since 2.0
* @param object $rec a think that has a context, for example a course,
@ -632,7 +632,7 @@ function is_context_subobj_valid($rec, $contextlevel) {
* or may not, have come from a place that does make_context_subobj, you can use
* this method to ensure that $rec->context is present and correct before you continue.
*
* Use context_instance_preload() instead.
* Use context_helper::preload_from_record() instead.
*
* @deprecated since 2.0
* @param object $rec a thing that has an associated context.
@ -4069,7 +4069,7 @@ function get_categories($parent='none', $sort=NULL, $shallow=true) {
$rs = $DB->get_recordset_sql($sql, $params);
foreach($rs as $cat) {
context_instance_preload($cat);
context_helper::preload_from_record($cat);
$catcontext = context_coursecat::instance($cat->id);
if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) {
$categories[$cat->id] = $cat;
@ -4301,7 +4301,7 @@ function get_course_category_tree($id = 0, $depth = 0) {
if ($course->id == SITEID) {
continue;
}
context_instance_preload($course);
context_helper::preload_from_record($course);
if (!empty($course->visible) || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
$categoryids[$course->category]->courses[$course->id] = $course;
}
@ -4605,7 +4605,7 @@ function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=a
// the context, and prepping data to fetch the
// managers efficiently later...
foreach ($courses as $k => $course) {
context_instance_preload($course);
context_helper::preload_from_record($course);
$coursecontext = context_course::instance($course->id);
$courses[$k] = $course;
$courses[$k]->managers = array();

View File

@ -596,7 +596,7 @@ function enrol_get_my_courses($fields = NULL, $sort = 'visible DESC,sortorder AS
// preload contexts and check visibility
foreach ($courses as $id=>$course) {
context_instance_preload($course);
context_helper::preload_from_record($course);
if (!$course->visible) {
if (!$context = context_course::instance($id, IGNORE_MISSING)) {
unset($courses[$id]);
@ -692,7 +692,7 @@ function enrol_get_users_courses($userid, $onlyactive = false, $fields = NULL, $
// preload contexts and check visibility
if ($onlyactive) {
foreach ($courses as $id=>$course) {
context_instance_preload($course);
context_helper::preload_from_record($course);
if (!$course->visible) {
if (!$context = context_course::instance($id)) {
unset($courses[$id]);

View File

@ -1445,7 +1445,7 @@ class global_navigation extends navigation_node {
if (!$this->can_add_more_courses_to_category($course->category)) {
continue;
}
context_instance_preload($course);
context_helper::preload_from_record($course);
if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
continue;
}
@ -1481,7 +1481,7 @@ class global_navigation extends navigation_node {
if (!$this->can_add_more_courses_to_category($course->category)) {
break;
}
context_instance_preload($course);
context_helper::preload_from_record($course);
if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
continue;
}
@ -1509,7 +1509,7 @@ class global_navigation extends navigation_node {
// Don't include the currentcourse in this nodelist - it's displayed in the Current course node
continue;
}
context_instance_preload($course);
context_helper::preload_from_record($course);
if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
continue;
}

View File

@ -58,7 +58,7 @@ $rs = $DB->get_recordset_sql($sql);
foreach ($rs as $backuprow) {
// Cache the course context
context_instance_preload($backuprow);
context_helper::preload_from_record($backuprow);
// Prepare a cell to display the status of the entry
if ($backuprow->laststatus == backup_cron_automated_helper::BACKUP_STATUS_OK) {

View File

@ -691,7 +691,7 @@ class core_user_external extends external_api {
if (!empty($user->deleted)) {
continue;
}
context_instance_preload($user);
context_helper::preload_from_record($user);
$usercontext = context_user::instance($user->id, IGNORE_MISSING);
self::validate_context($usercontext);
$currentuser = ($user->id == $USER->id);
@ -786,7 +786,7 @@ class core_user_external extends external_api {
$rs = $DB->get_recordset_sql($coursesql, $params);
foreach ($rs as $course) {
// adding course contexts to cache
context_instance_preload($course);
context_helper::preload_from_record($course);
// cache courses
$courses[$course->id] = $course;
}
@ -803,7 +803,7 @@ class core_user_external extends external_api {
if (!empty($user->deleted)) {
continue;
}
context_instance_preload($user);
context_helper::preload_from_record($user);
$course = $courses[$courseids[$user->id]];
$context = context_course::instance($courseids[$user->id], IGNORE_MISSING);
self::validate_context($context);

View File

@ -583,7 +583,7 @@
}
$usersprinted[] = $user->id; /// Add new user to the array of users printed
context_instance_preload($user);
context_helper::preload_from_record($user);
$context = context_course::instance($course->id);
$usercontext = context_user::instance($user->id);
@ -705,7 +705,7 @@
}
$usersprinted[] = $user->id; /// Add new user to the array of users printed
context_instance_preload($user);
context_helper::preload_from_record($user);
if ($user->lastaccess) {
$lastaccess = format_time(time() - $user->lastaccess, $datestring);