From d197ea4300083cfa6c4f09613f9fb1f98ce2e69a Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Tue, 21 Aug 2012 14:20:30 +0800 Subject: [PATCH 1/2] MDL-34549 libraries: Replace get_context_instance_by_id() by context::instance_by_id() --- admin/roles/lib.php | 8 ++++---- admin/user/user_bulk_cohortadd.php | 2 +- blocks/community/block_community.php | 4 ++-- blocks/edit_form.php | 2 +- blocks/html/block_html.php | 2 +- blocks/html/lib.php | 2 +- blocks/quiz_results/block_quiz_results.php | 2 +- cohort/assign.php | 2 +- cohort/edit.php | 4 ++-- cohort/edit_form.php | 2 +- cohort/index.php | 2 +- comment/lib.php | 2 +- comment/locallib.php | 2 +- draftfile.php | 2 +- enrol/category/locallib.php | 8 ++++---- enrol/cohort/addinstance_form.php | 2 +- enrol/cohort/lib.php | 2 +- enrol/cohort/locallib.php | 6 +++--- enrol/externallib.php | 4 ++-- files/externallib.php | 4 ++-- files/renderer.php | 2 +- grade/grading/lib.php | 2 +- grade/grading/manage.php | 2 +- lib/blocklib.php | 2 +- lib/externallib.php | 2 +- lib/filebrowser/file_info_context_course.php | 2 +- lib/filebrowser/file_info_context_coursecat.php | 2 +- lib/filebrowser/file_info_context_module.php | 2 +- lib/questionlib.php | 4 ++-- lib/setuplib.php | 2 +- lib/tests/accesslib_test.php | 2 +- lib/weblib.php | 4 ++-- mod/data/lib.php | 2 +- mod/forum/lib.php | 2 +- mod/glossary/lib.php | 2 +- mod/quiz/edit.php | 2 +- mod/quiz/editlib.php | 2 +- mod/wiki/edit_form.php | 2 +- question/addquestion.php | 2 +- question/category.php | 2 +- question/category_class.php | 8 ++++---- question/editlib.php | 8 ++++---- question/engine/questionusage.php | 2 +- question/format.php | 6 +++--- question/import.php | 2 +- question/preview.php | 2 +- question/question.php | 6 +++--- question/type/calculated/datasetdefinitions_form.php | 2 +- question/type/calculated/datasetitems_form.php | 2 +- question/type/edit_question_form.php | 4 ++-- question/type/questiontypebase.php | 2 +- report/security/locallib.php | 4 ++-- repository/coursefiles/lib.php | 4 ++-- repository/draftfiles_ajax.php | 2 +- repository/lib.php | 6 +++--- repository/local/lib.php | 2 +- repository/manage_instances.php | 4 ++-- repository/recent/lib.php | 2 +- repository/repository_ajax.php | 4 ++-- user/index.php | 2 +- webservice/lib.php | 2 +- 61 files changed, 92 insertions(+), 92 deletions(-) diff --git a/admin/roles/lib.php b/admin/roles/lib.php index 43eb7f530b8..df537f008da 100644 --- a/admin/roles/lib.php +++ b/admin/roles/lib.php @@ -933,7 +933,7 @@ class override_permissions_table_advanced extends capability_table_with_risks { global $DB; /// Get the capabilities from the parent context, so that can be shown in the interface. - $parentcontext = get_context_instance_by_id(get_parent_contextid($this->context)); + $parentcontext = context::instance_by_id(get_parent_contextid($this->context)); $this->parentpermissions = role_context_capabilities($this->roleid, $parentcontext); } @@ -996,7 +996,7 @@ abstract class role_assign_user_selector_base extends user_selector_base { if (isset($options['context'])) { $this->context = $options['context']; } else { - $this->context = get_context_instance_by_id($options['contextid']); + $this->context = context::instance_by_id($options['contextid']); } $options['accesscontext'] = $this->context; parent::__construct($name, $options); @@ -1230,7 +1230,7 @@ class existing_role_holders extends role_assign_user_selector_base { } protected function parent_con_group_name($search, $contextid) { - $context = get_context_instance_by_id($contextid); + $context = context::instance_by_id($contextid); $contextname = print_context_name($context, true, true); if ($search) { $a = new stdClass; @@ -1477,7 +1477,7 @@ class role_allow_switch_page extends role_allow_role_page { function roles_get_potential_user_selector($context, $name, $options) { $blockinsidecourse = false; if ($context->contextlevel == CONTEXT_BLOCK) { - $parentcontext = get_context_instance_by_id(get_parent_contextid($context)); + $parentcontext = context::instance_by_id(get_parent_contextid($context)); $blockinsidecourse = in_array($parentcontext->contextlevel, array(CONTEXT_MODULE, CONTEXT_COURSE)); } diff --git a/admin/user/user_bulk_cohortadd.php b/admin/user/user_bulk_cohortadd.php index 1e32564fe59..be72d51c26c 100644 --- a/admin/user/user_bulk_cohortadd.php +++ b/admin/user/user_bulk_cohortadd.php @@ -45,7 +45,7 @@ foreach ($allcohorts as $c) { // external cohorts can not be modified continue; } - $context = get_context_instance_by_id($c->contextid); + $context = context::instance_by_id($c->contextid); if (!has_capability('moodle/cohort:assign', $context)) { continue; } diff --git a/blocks/community/block_community.php b/blocks/community/block_community.php index 35e3f2e212d..c211342cc18 100644 --- a/blocks/community/block_community.php +++ b/blocks/community/block_community.php @@ -43,7 +43,7 @@ class block_community extends block_list { function user_can_edit() { // Don't allow people to edit the block if they can't even use it if (!has_capability('moodle/community:add', - get_context_instance_by_id($this->instance->parentcontextid))) { + context::instance_by_id($this->instance->parentcontextid))) { return false; } return parent::user_can_edit(); @@ -52,7 +52,7 @@ class block_community extends block_list { function get_content() { global $CFG, $OUTPUT, $USER; - $coursecontext = get_context_instance_by_id($this->instance->parentcontextid); + $coursecontext = context::instance_by_id($this->instance->parentcontextid); if (!has_capability('moodle/community:add', $coursecontext) or $this->content !== NULL) { diff --git a/blocks/edit_form.php b/blocks/edit_form.php index 9380fa2be72..169c54de4ea 100644 --- a/blocks/edit_form.php +++ b/blocks/edit_form.php @@ -87,7 +87,7 @@ class block_edit_form extends moodleform { $regionoptions = $this->page->theme->get_all_block_regions(); - $parentcontext = get_context_instance_by_id($this->block->instance->parentcontextid); + $parentcontext = context::instance_by_id($this->block->instance->parentcontextid); $mform->addElement('hidden', 'bui_parentcontextid', $parentcontext->id); $mform->addElement('static', 'bui_homecontext', get_string('createdat', 'block'), print_context_name($parentcontext)); diff --git a/blocks/html/block_html.php b/blocks/html/block_html.php index 39040ae47dd..6ca71b30f1b 100644 --- a/blocks/html/block_html.php +++ b/blocks/html/block_html.php @@ -104,7 +104,7 @@ class block_html extends block_base { function content_is_trusted() { global $SCRIPT; - if (!$context = get_context_instance_by_id($this->instance->parentcontextid)) { + if (!$context = context::instance_by_id($this->instance->parentcontextid)) { return false; } //find out if this block is on the profile page diff --git a/blocks/html/lib.php b/blocks/html/lib.php index a2555c3f88e..93fdbb8c8e4 100644 --- a/blocks/html/lib.php +++ b/blocks/html/lib.php @@ -53,7 +53,7 @@ function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $a send_file_not_found(); } - if ($parentcontext = get_context_instance_by_id($birecord_or_cm->parentcontextid)) { + if ($parentcontext = context::instance_by_id($birecord_or_cm->parentcontextid)) { if ($parentcontext->contextlevel == CONTEXT_USER) { // force download on all personal pages including /my/ //because we do not have reliable way to find out from where this is used diff --git a/blocks/quiz_results/block_quiz_results.php b/blocks/quiz_results/block_quiz_results.php index d18af5563c8..8795a687f34 100644 --- a/blocks/quiz_results/block_quiz_results.php +++ b/blocks/quiz_results/block_quiz_results.php @@ -65,7 +65,7 @@ class block_quiz_results extends block_base { if (empty($this->instance->parentcontextid)) { return 0; } - $parentcontext = get_context_instance_by_id($this->instance->parentcontextid); + $parentcontext = context::instance_by_id($this->instance->parentcontextid); if ($parentcontext->contextlevel != CONTEXT_MODULE) { return 0; } diff --git a/cohort/assign.php b/cohort/assign.php index b7f65896a5f..5eaa2a704f5 100644 --- a/cohort/assign.php +++ b/cohort/assign.php @@ -32,7 +32,7 @@ $id = required_param('id', PARAM_INT); require_login(); $cohort = $DB->get_record('cohort', array('id'=>$id), '*', MUST_EXIST); -$context = get_context_instance_by_id($cohort->contextid, MUST_EXIST); +$context = context::instance_by_id($cohort->contextid, MUST_EXIST); require_capability('moodle/cohort:assign', $context); diff --git a/cohort/edit.php b/cohort/edit.php index dc1bd08bb04..721d790ed67 100644 --- a/cohort/edit.php +++ b/cohort/edit.php @@ -40,9 +40,9 @@ require_login(); $category = null; if ($id) { $cohort = $DB->get_record('cohort', array('id'=>$id), '*', MUST_EXIST); - $context = get_context_instance_by_id($cohort->contextid, MUST_EXIST); + $context = context::instance_by_id($cohort->contextid, MUST_EXIST); } else { - $context = get_context_instance_by_id($contextid, MUST_EXIST); + $context = context::instance_by_id($contextid, MUST_EXIST); if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) { print_error('invalidcontext'); } diff --git a/cohort/edit_form.php b/cohort/edit_form.php index 957607171c8..81e7a7cb6c0 100644 --- a/cohort/edit_form.php +++ b/cohort/edit_form.php @@ -103,7 +103,7 @@ class cohort_edit_form extends moodleform { } // always add current - this is not likely, but if the logic gets changed it might be a problem if (!isset($options[$currentcontextid])) { - $context = get_context_instance_by_id($currentcontextid, MUST_EXIST); + $context = context::instance_by_id($currentcontextid, MUST_EXIST); $options[$context->id] = print_context_name($syscontext); } return $options; diff --git a/cohort/index.php b/cohort/index.php index 026bcb855e9..00aab668325 100644 --- a/cohort/index.php +++ b/cohort/index.php @@ -35,7 +35,7 @@ $searchquery = optional_param('search', '', PARAM_RAW); require_login(); if ($contextid) { - $context = get_context_instance_by_id($contextid, MUST_EXIST); + $context = context::instance_by_id($contextid, MUST_EXIST); } else { $context = context_system::instance(); } diff --git a/comment/lib.php b/comment/lib.php index 9bf2653a6a0..8954244e826 100644 --- a/comment/lib.php +++ b/comment/lib.php @@ -120,7 +120,7 @@ class comment { $this->contextid = $this->context->id; } else if(!empty($options->contextid)) { $this->contextid = $options->contextid; - $this->context = get_context_instance_by_id($this->contextid); + $this->context = context::instance_by_id($this->contextid); } else { print_error('invalidcontext'); } diff --git a/comment/locallib.php b/comment/locallib.php index 5a8b0d7bf99..25f907f4c16 100644 --- a/comment/locallib.php +++ b/comment/locallib.php @@ -114,7 +114,7 @@ class comment_manager { */ private function setup_plugin($comment) { global $DB; - $this->context = get_context_instance_by_id($comment->contextid); + $this->context = context::instance_by_id($comment->contextid); if (!$this->context) { return false; } diff --git a/draftfile.php b/draftfile.php index ede57069134..821ae576650 100644 --- a/draftfile.php +++ b/draftfile.php @@ -61,7 +61,7 @@ if ($component !== 'user' or $filearea !== 'draft') { send_file_not_found(); } -$context = get_context_instance_by_id($contextid); +$context = context::instance_by_id($contextid); if ($context->contextlevel != CONTEXT_USER) { send_file_not_found(); } diff --git a/enrol/category/locallib.php b/enrol/category/locallib.php index 2c16f766203..9e4ab0c35ee 100644 --- a/enrol/category/locallib.php +++ b/enrol/category/locallib.php @@ -45,8 +45,8 @@ class enrol_category_handler { return true; } - // Only category level roles are interesting. - $parentcontext = get_context_instance_by_id($ra->contextid); + //only category level roles are interesting + $parentcontext = context::instance_by_id($ra->contextid); if ($parentcontext->contextlevel != CONTEXT_COURSECAT) { return true; } @@ -102,8 +102,8 @@ class enrol_category_handler { return true; } - // Only category level roles are interesting. - $parentcontext = get_context_instance_by_id($ra->contextid); + // only category level roles are interesting + $parentcontext = context::instance_by_id($ra->contextid); if ($parentcontext->contextlevel != CONTEXT_COURSECAT) { return true; } diff --git a/enrol/cohort/addinstance_form.php b/enrol/cohort/addinstance_form.php index e9015a2883c..c2094937c0c 100644 --- a/enrol/cohort/addinstance_form.php +++ b/enrol/cohort/addinstance_form.php @@ -46,7 +46,7 @@ class enrol_cohort_addinstance_form extends moodleform { ORDER BY name ASC"; $rs = $DB->get_recordset_sql($sql, $params); foreach ($rs as $c) { - $context = get_context_instance_by_id($c->contextid); + $context = context::instance_by_id($c->contextid); if (!has_capability('moodle/cohort:view', $context)) { continue; } diff --git a/enrol/cohort/lib.php b/enrol/cohort/lib.php index b70b89f2fb1..4ad304eb17b 100644 --- a/enrol/cohort/lib.php +++ b/enrol/cohort/lib.php @@ -92,7 +92,7 @@ class enrol_cohort_plugin extends enrol_plugin { ORDER BY name ASC"; $cohorts = $DB->get_records_sql($sql, $params); foreach ($cohorts as $c) { - $context = get_context_instance_by_id($c->contextid); + $context = context::instance_by_id($c->contextid); if (has_capability('moodle/cohort:view', $context)) { return true; } diff --git a/enrol/cohort/locallib.php b/enrol/cohort/locallib.php index 5ca237a6c29..869e06c4aa2 100644 --- a/enrol/cohort/locallib.php +++ b/enrol/cohort/locallib.php @@ -368,7 +368,7 @@ function enrol_cohort_get_cohorts(course_enrolment_manager $manager) { ORDER BY name ASC"; $rs = $DB->get_recordset_sql($sql, $params); foreach ($rs as $c) { - $context = get_context_instance_by_id($c->contextid); + $context = context::instance_by_id($c->contextid); if (!has_capability('moodle/cohort:view', $context)) { continue; } @@ -394,7 +394,7 @@ function enrol_cohort_can_view_cohort($cohortid) { global $DB; $cohort = $DB->get_record('cohort', array('id' => $cohortid), 'id, contextid'); if ($cohort) { - $context = get_context_instance_by_id($cohort->contextid); + $context = context::instance_by_id($cohort->contextid); if (has_capability('moodle/cohort:view', $context)) { return true; } @@ -457,7 +457,7 @@ function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset // Track offset $offset++; // Check capabilities - $context = get_context_instance_by_id($c->contextid); + $context = context::instance_by_id($c->contextid); if (!has_capability('moodle/cohort:view', $context)) { continue; } diff --git a/enrol/externallib.php b/enrol/externallib.php index 0fd4182d488..e669ca747f7 100644 --- a/enrol/externallib.php +++ b/enrol/externallib.php @@ -381,7 +381,7 @@ class core_role_external extends external_api { foreach ($params['assignments'] as $assignment) { // Ensure the current user is allowed to run this function in the enrolment context - $context = get_context_instance_by_id($assignment['contextid']); + $context = context::instance_by_id($assignment['contextid']); self::validate_context($context); require_capability('moodle/role:assign', $context); @@ -445,7 +445,7 @@ class core_role_external extends external_api { foreach ($params['unassignments'] as $unassignment) { // Ensure the current user is allowed to run this function in the unassignment context - $context = get_context_instance_by_id($unassignment['contextid']); + $context = context::instance_by_id($unassignment['contextid']); self::validate_context($context); require_capability('moodle/role:assign', $context); diff --git a/files/externallib.php b/files/externallib.php index f6001d2e9e6..4d8e3aeb99c 100644 --- a/files/externallib.php +++ b/files/externallib.php @@ -82,7 +82,7 @@ class core_files_external extends external_api { if (empty($fileinfo['contextid'])) { $context = get_system_context(); } else { - $context = get_context_instance_by_id($fileinfo['contextid']); + $context = context::instance_by_id($fileinfo['contextid']); } if (empty($fileinfo['component'])) { $fileinfo['component'] = null; @@ -272,7 +272,7 @@ class core_files_external extends external_api { } if (!empty($fileinfo['contextid'])) { - $context = get_context_instance_by_id($fileinfo['contextid']); + $context = context::instance_by_id($fileinfo['contextid']); } else { $context = get_system_context(); } diff --git a/files/renderer.php b/files/renderer.php index cfa14e08b89..6a648b05792 100644 --- a/files/renderer.php +++ b/files/renderer.php @@ -965,7 +965,7 @@ class files_tree_viewer implements renderable { $this->path = array(); while ($level) { $params = $level->get_params(); - $context = get_context_instance_by_id($params['contextid']); + $context = context::instance_by_id($params['contextid']); // $this->context is current context if ($context->id != $this->context->id or empty($params['filearea'])) { break; diff --git a/grade/grading/lib.php b/grade/grading/lib.php index c6e81864f8a..0a3de68b306 100644 --- a/grade/grading/lib.php +++ b/grade/grading/lib.php @@ -223,7 +223,7 @@ class grading_manager { global $DB; $this->areacache = $DB->get_record('grading_areas', array('id' => $areaid), '*', MUST_EXIST); - $this->context = get_context_instance_by_id($this->areacache->contextid, MUST_EXIST); + $this->context = context::instance_by_id($this->areacache->contextid, MUST_EXIST); $this->component = $this->areacache->component; $this->area = $this->areacache->areaname; } diff --git a/grade/grading/manage.php b/grade/grading/manage.php index 954f91f90a1..c5d90ada8ec 100644 --- a/grade/grading/manage.php +++ b/grade/grading/manage.php @@ -57,7 +57,7 @@ if (!is_null($areaid)) { if (is_null($contextid) or is_null($component) or is_null($area)) { throw new coding_exception('The caller script must identify the gradable area.'); } - $context = get_context_instance_by_id($contextid, MUST_EXIST); + $context = context::instance_by_id($contextid, MUST_EXIST); $manager = get_grading_manager($context, $component, $area); } diff --git a/lib/blocklib.php b/lib/blocklib.php index 79ec70d1856..76ff72884ff 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -1238,7 +1238,7 @@ class block_manager { $systemcontext = context_system::instance(); $frontpagecontext = context_course::instance(SITEID); - $parentcontext = get_context_instance_by_id($data->bui_parentcontextid); + $parentcontext = context::instance_by_id($data->bui_parentcontextid); // Updating stickiness and contexts. See MDL-21375 for details. if (has_capability('moodle/site:manageblocks', $parentcontext)) { // Check permissions in destination diff --git a/lib/externallib.php b/lib/externallib.php index f547850e0f6..0c6e44dbc04 100644 --- a/lib/externallib.php +++ b/lib/externallib.php @@ -520,7 +520,7 @@ function external_generate_token($tokentype, $serviceorid, $userid, $contextorid $service = $serviceorid; } if (!is_object($contextorid)){ - $context = get_context_instance_by_id($contextorid, MUST_EXIST); + $context = context::instance_by_id($contextorid, MUST_EXIST); } else { $context = $contextorid; } diff --git a/lib/filebrowser/file_info_context_course.php b/lib/filebrowser/file_info_context_course.php index 05b34890290..d1e703b7e9d 100644 --- a/lib/filebrowser/file_info_context_course.php +++ b/lib/filebrowser/file_info_context_course.php @@ -401,7 +401,7 @@ class file_info_context_course extends file_info { public function get_parent() { //TODO: error checking if get_parent_contextid() returns false $pcid = get_parent_contextid($this->context); - $parent = get_context_instance_by_id($pcid); + $parent = context::instance_by_id($pcid); return $this->browser->get_file_info($parent); } } diff --git a/lib/filebrowser/file_info_context_coursecat.php b/lib/filebrowser/file_info_context_coursecat.php index 1cded8310f1..47636e6ce06 100644 --- a/lib/filebrowser/file_info_context_coursecat.php +++ b/lib/filebrowser/file_info_context_coursecat.php @@ -195,7 +195,7 @@ class file_info_context_coursecat extends file_info { */ public function get_parent() { $cid = get_parent_contextid($this->context); - $parent = get_context_instance_by_id($cid); + $parent = context::instance_by_id($cid); return $this->browser->get_file_info($parent); } } diff --git a/lib/filebrowser/file_info_context_module.php b/lib/filebrowser/file_info_context_module.php index 0357ee34cde..363f6a0b82f 100644 --- a/lib/filebrowser/file_info_context_module.php +++ b/lib/filebrowser/file_info_context_module.php @@ -283,7 +283,7 @@ class file_info_context_module extends file_info { */ public function get_parent() { $pcid = get_parent_contextid($this->context); - $parent = get_context_instance_by_id($pcid); + $parent = context::instance_by_id($pcid); return $this->browser->get_file_info($parent); } } diff --git a/lib/questionlib.php b/lib/questionlib.php index 149f3514468..fbfab99ab84 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -1106,7 +1106,7 @@ function question_category_options($contexts, $top = false, $currentcat = 0, $categoriesarray = array(); foreach ($pcontexts as $pcontext) { $contextstring = print_context_name( - get_context_instance_by_id($pcontext), true, true); + context::instance_by_id($pcontext), true, true); foreach ($categories as $category) { if ($category->contextid == $pcontext) { $cid = $category->id; @@ -1333,7 +1333,7 @@ function question_has_capability_on($question, $cap, $cachecat = -1) { } } $category = $categories[$question->category]; - $context = get_context_instance_by_id($category->contextid); + $context = context::instance_by_id($category->contextid); if (array_search($cap, $question_questioncaps)!== false) { if (!has_capability('moodle/question:' . $cap . 'all', $context)) { diff --git a/lib/setuplib.php b/lib/setuplib.php index 51f8d827f42..16b2aa3cd9b 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -206,7 +206,7 @@ class required_capability_exception extends moodle_exception { $capabilityname = get_capability_string($capability); if ($context->contextlevel == CONTEXT_MODULE and preg_match('/:view$/', $capability)) { // we can not go to mod/xx/view.php because we most probably do not have cap to view it, let's go to course instead - $paranetcontext = get_context_instance_by_id(get_parent_contextid($context)); + $paranetcontext = context::instance_by_id(get_parent_contextid($context)); $link = get_context_url($paranetcontext); } else { $link = get_context_url($context); diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index 52d700fea28..b8535fd7c98 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -2271,7 +2271,7 @@ class accesslib_testcase extends advanced_testcase { foreach ($DB->get_records('context') as $contextid=>$record) { $context = context::instance_by_id($contextid); - $this->assertSame(get_context_instance_by_id($contextid), $context); + $this->assertSame(context::instance_by_id($contextid), $context); $this->assertSame(get_context_instance($record->contextlevel, $record->instanceid), $context); $this->assertSame(get_parent_contexts($context), $context->get_parent_context_ids()); if ($context->id == SYSCONTEXTID) { diff --git a/lib/weblib.php b/lib/weblib.php index 1295b00182d..b3d7339346b 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1072,7 +1072,7 @@ function format_text($text, $format = FORMAT_MOODLE, $options = NULL, $courseid_ if (is_object($options['context'])) { $context = $options['context']; } else { - $context = get_context_instance_by_id($options['context']); + $context = context::instance_by_id($options['context']); } } else if ($courseid_do_not_use) { // legacy courseid @@ -1281,7 +1281,7 @@ function format_string($string, $striplinks = true, $options = NULL) { // fallback to $PAGE->context this may be problematic in CLI and other non-standard pages :-( $options['context'] = $PAGE->context; } else if (is_numeric($options['context'])) { - $options['context'] = get_context_instance_by_id($options['context']); + $options['context'] = context::instance_by_id($options['context']); } if (!$options['context']) { diff --git a/mod/data/lib.php b/mod/data/lib.php index fa660c0dc50..0cc49b31235 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -1325,7 +1325,7 @@ function data_print_template($template, $records, $data, $search='', $page=0, $r * @return array an associative array of the user's rating permissions */ function data_rating_permissions($contextid, $component, $ratingarea) { - $context = get_context_instance_by_id($contextid, MUST_EXIST); + $context = context::instance_by_id($contextid, MUST_EXIST); if ($component != 'mod_data' || $ratingarea != 'entry') { return null; } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 405bc95df6e..b36bcd66d52 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -3527,7 +3527,7 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa * @return array an associative array of the user's rating permissions */ function forum_rating_permissions($contextid, $component, $ratingarea) { - $context = get_context_instance_by_id($contextid, MUST_EXIST); + $context = context::instance_by_id($contextid, MUST_EXIST); if ($component != 'mod_forum' || $ratingarea != 'post') { // We don't know about this component/ratingarea so just return null to get the // default restrictive permissions. diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 1ddcc56a89b..ab8657a8eef 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -637,7 +637,7 @@ function glossary_rating_permissions($contextid, $component, $ratingarea) { // default restrictive permissions. return null; } - $context = get_context_instance_by_id($contextid); + $context = context::instance_by_id($contextid); return array( 'view' => has_capability('mod/glossary:viewrating', $context), 'viewany' => has_capability('mod/glossary:viewanyrating', $context), diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index ef5e633ead6..1fce2b49eac 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -73,7 +73,7 @@ function module_specific_buttons($cmid, $cmoptions) { function module_specific_controls($totalnumber, $recurse, $category, $cmid, $cmoptions) { global $OUTPUT; $out = ''; - $catcontext = get_context_instance_by_id($category->contextid); + $catcontext = context::instance_by_id($category->contextid); if (has_capability('moodle/question:useall', $catcontext)) { if ($cmoptions->hasattempts) { $disabled = ' disabled="disabled"'; diff --git a/mod/quiz/editlib.php b/mod/quiz/editlib.php index 44f00d6ec89..987a39b3f0a 100644 --- a/mod/quiz/editlib.php +++ b/mod/quiz/editlib.php @@ -183,7 +183,7 @@ function quiz_add_random_questions($quiz, $addonpage, $categoryid, $number, print_error('invalidcategoryid', 'error'); } - $catcontext = get_context_instance_by_id($category->contextid); + $catcontext = context::instance_by_id($category->contextid); require_capability('moodle/question:useall', $catcontext); // Find existing random questions in this category that are diff --git a/mod/wiki/edit_form.php b/mod/wiki/edit_form.php index 9992ddeeeac..2d34a6cf737 100644 --- a/mod/wiki/edit_form.php +++ b/mod/wiki/edit_form.php @@ -59,7 +59,7 @@ class mod_wiki_edit_form extends moodleform { if (isset($this->_customdata['pagetitle'])) { // Page title must be formatted properly here as this is output and not an element. - $pagetitle = get_string('editingpage', 'wiki', format_string($this->_customdata['pagetitle'], true, array('context' => get_context_instance_by_id($contextid, MUST_EXIST)))); + $pagetitle = get_string('editingpage', 'wiki', format_string($this->_customdata['pagetitle'], true, array('context' => context::instance_by_id($contextid, MUST_EXIST)))); } else { $pagetitle = get_string('editing', 'wiki'); } diff --git a/question/addquestion.php b/question/addquestion.php index fa262cdadc9..02e6224280a 100644 --- a/question/addquestion.php +++ b/question/addquestion.php @@ -60,7 +60,7 @@ if ($cmid) { } // Check permissions. -$categorycontext = get_context_instance_by_id($category->contextid); +$categorycontext = context::instance_by_id($category->contextid); require_capability('moodle/question:add', $categorycontext); // Ensure other optional params get passed on to question.php. diff --git a/question/category.php b/question/category.php index 5ad3de94049..b208a469a4b 100644 --- a/question/category.php +++ b/question/category.php @@ -71,7 +71,7 @@ if ($param->delete && ($questionstomove = $DB->count_records("question", array(" if (!$category = $DB->get_record("question_categories", array("id" => $param->delete))) { // security print_error('nocate', 'question', $thispageurl->out(), $param->delete); } - $categorycontext = get_context_instance_by_id($category->contextid); + $categorycontext = context::instance_by_id($category->contextid); $qcobject->moveform = new question_move_form($thispageurl, array('contexts'=>array($categorycontext), 'currentcat'=>$param->delete)); if ($qcobject->moveform->is_cancelled()){ diff --git a/question/category_class.php b/question/category_class.php index fd65dbac81f..79339f29e1c 100644 --- a/question/category_class.php +++ b/question/category_class.php @@ -246,7 +246,7 @@ class question_category_object { $listhtml = $list->to_html(0, array('str'=>$this->str)); if ($listhtml){ echo $OUTPUT->box_start('boxwidthwide boxaligncenter generalbox questioncategories contextlevel' . $list->context->contextlevel); - echo $OUTPUT->heading(get_string('questioncatsfor', 'question', print_context_name(get_context_instance_by_id($context))), 3); + echo $OUTPUT->heading(get_string('questioncatsfor', 'question', print_context_name(context::instance_by_id($context))), 3); echo $listhtml; echo $OUTPUT->box_end(); } @@ -374,7 +374,7 @@ class question_category_object { } list($parentid, $contextid) = explode(',', $newparent); //moodle_form makes sure select element output is legal no need for further cleaning - require_capability('moodle/question:managecategory', get_context_instance_by_id($contextid)); + require_capability('moodle/question:managecategory', context::instance_by_id($contextid)); if ($parentid) { if(!($DB->get_field('question_categories', 'contextid', array('id' => $parentid)) == $contextid)) { @@ -418,12 +418,12 @@ class question_category_object { } // Check permissions. - $fromcontext = get_context_instance_by_id($oldcat->contextid); + $fromcontext = context::instance_by_id($oldcat->contextid); require_capability('moodle/question:managecategory', $fromcontext); // If moving to another context, check permissions some more. if ($oldcat->contextid != $tocontextid) { - $tocontext = get_context_instance_by_id($tocontextid); + $tocontext = context::instance_by_id($tocontextid); require_capability('moodle/question:managecategory', $tocontext); } diff --git a/question/editlib.php b/question/editlib.php index f28b9c2fa60..bb4633f4fd0 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -117,7 +117,7 @@ function question_can_delete_cat($todelete) { print_error('cannotdeletecate', 'question'); } else { $contextid = $DB->get_field('question_categories', 'contextid', array('id' => $todelete)); - require_capability('moodle/question:managecategory', get_context_instance_by_id($contextid)); + require_capability('moodle/question:managecategory', context::instance_by_id($contextid)); } } @@ -1323,7 +1323,7 @@ class question_bank_view { $strdelete = get_string('delete'); list($categoryid, $contextid) = explode(',', $categoryandcontext); - $catcontext = get_context_instance_by_id($contextid); + $catcontext = context::instance_by_id($contextid); $canadd = has_capability('moodle/question:add', $catcontext); $caneditall =has_capability('moodle/question:editall', $catcontext); @@ -1467,7 +1467,7 @@ class question_bank_view { if (! $tocategory = $DB->get_record('question_categories', array('id' => $tocategoryid, 'contextid' => $contextid))) { print_error('cannotfindcate', 'question'); } - $tocontext = get_context_instance_by_id($contextid); + $tocontext = context::instance_by_id($contextid); require_capability('moodle/question:add', $tocontext); $rawdata = (array) data_submitted(); $questionids = array(); @@ -1717,7 +1717,7 @@ function question_get_display_preference($param, $default, $type, $thispageurl) function require_login_in_context($contextorid = null){ global $DB, $CFG; if (!is_object($contextorid)){ - $context = get_context_instance_by_id($contextorid); + $context = context::instance_by_id($contextorid); } else { $context = $contextorid; } diff --git a/question/engine/questionusage.php b/question/engine/questionusage.php index e4de1979502..d6fbae8d639 100644 --- a/question/engine/questionusage.php +++ b/question/engine/questionusage.php @@ -708,7 +708,7 @@ class question_usage_by_activity { } $quba = new question_usage_by_activity($record->component, - get_context_instance_by_id($record->contextid)); + context::instance_by_id($record->contextid)); $quba->set_id_from_database($record->qubaid); $quba->set_preferred_behaviour($record->preferredbehaviour); diff --git a/question/format.php b/question/format.php index e1cc7db6ac0..bf9daca9671 100644 --- a/question/format.php +++ b/question/format.php @@ -128,7 +128,7 @@ class qformat_default { debugging('You shouldn\'t call setCategory after setQuestions'); } $this->category = $category; - $this->importcontext = get_context_instance_by_id($this->category->contextid); + $this->importcontext = context::instance_by_id($this->category->contextid); } /** @@ -500,10 +500,10 @@ class qformat_default { } if ($this->contextfromfile && $contextid !== false) { - $context = get_context_instance_by_id($contextid); + $context = context::instance_by_id($contextid); require_capability('moodle/question:add', $context); } else { - $context = get_context_instance_by_id($this->category->contextid); + $context = context::instance_by_id($this->category->contextid); } $this->importcontext = $context; diff --git a/question/import.php b/question/import.php index 20b6c9a4c73..7110e531b73 100644 --- a/question/import.php +++ b/question/import.php @@ -42,7 +42,7 @@ if (!$category = $DB->get_record("question_categories", array('id' => $catid))) print_error('nocategory', 'question'); } -$categorycontext = get_context_instance_by_id($category->contextid); +$categorycontext = context::instance_by_id($category->contextid); $category->context = $categorycontext; //this page can be called without courseid or cmid in which case //we get the context from the category object. diff --git a/question/preview.php b/question/preview.php index 293876260a4..b8a83ed5c4b 100644 --- a/question/preview.php +++ b/question/preview.php @@ -60,7 +60,7 @@ if ($cmid = optional_param('cmid', 0, PARAM_INT)) { require_login(); $category = $DB->get_record('question_categories', array('id' => $question->category), '*', MUST_EXIST); - $context = get_context_instance_by_id($category->contextid); + $context = context::instance_by_id($category->contextid); $PAGE->set_context($context); // Note that in the other cases, require_login will set the correct page context. } diff --git a/question/question.php b/question/question.php index 63f54ad613e..47a6893b162 100644 --- a/question/question.php +++ b/question/question.php @@ -154,7 +154,7 @@ if (!$category = $DB->get_record('question_categories', array('id' => $question- // Check permissions $question->formoptions = new stdClass(); -$categorycontext = get_context_instance_by_id($category->contextid); +$categorycontext = context::instance_by_id($category->contextid); $addpermission = has_capability('moodle/question:add', $categorycontext); if ($id) { @@ -259,7 +259,7 @@ if ($mform->is_cancelled()) { if ($movecontext) { // We are just moving the question to a different context. list($tocatid, $tocontextid) = explode(',', $fromform->categorymoveto); - require_capability('moodle/question:add', get_context_instance_by_id($tocontextid)); + require_capability('moodle/question:add', context::instance_by_id($tocontextid)); question_move_questions_to_category(array($question->id), $tocatid); } else { @@ -267,7 +267,7 @@ if ($mform->is_cancelled()) { if (!empty($question->id)) { question_require_capability_on($question, 'edit'); } else { - require_capability('moodle/question:add', get_context_instance_by_id($newcontextid)); + require_capability('moodle/question:add', context::instance_by_id($newcontextid)); if (!empty($fromform->makecopy) && !$question->formoptions->cansaveasnew) { print_error('nopermissions', '', '', 'edit'); } diff --git a/question/type/calculated/datasetdefinitions_form.php b/question/type/calculated/datasetdefinitions_form.php index 23a15f30de1..45efea3bcdd 100644 --- a/question/type/calculated/datasetdefinitions_form.php +++ b/question/type/calculated/datasetdefinitions_form.php @@ -65,7 +65,7 @@ class question_dataset_dependent_definitions_form extends question_wizard_form { print_error('categorydoesnotexist', 'question', $returnurl); } $this->category = $category; - $this->categorycontext = get_context_instance_by_id($category->contextid); + $this->categorycontext = context::instance_by_id($category->contextid); parent::__construct($submiturl); } diff --git a/question/type/calculated/datasetitems_form.php b/question/type/calculated/datasetitems_form.php index 3ff97505cc3..aa2156aad44 100644 --- a/question/type/calculated/datasetitems_form.php +++ b/question/type/calculated/datasetitems_form.php @@ -79,7 +79,7 @@ class question_dataset_dependent_items_form extends question_wizard_form { print_error('categorydoesnotexist', 'question', $returnurl); } $this->category = $category; - $this->categorycontext = get_context_instance_by_id($category->contextid); + $this->categorycontext = context::instance_by_id($category->contextid); //get the dataset defintions for this question if (empty($question->id)) { $this->datasetdefs = $this->qtypeobj->get_dataset_definitions( diff --git a/question/type/edit_question_form.php b/question/type/edit_question_form.php index 7428254ebe8..9a2ebeb4157 100644 --- a/question/type/edit_question_form.php +++ b/question/type/edit_question_form.php @@ -101,14 +101,14 @@ abstract class question_edit_form extends question_wizard_form { $record = $DB->get_record('question_categories', array('id' => $question->category), 'contextid'); - $this->context = get_context_instance_by_id($record->contextid); + $this->context = context::instance_by_id($record->contextid); $this->editoroptions = array('subdirs' => 1, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'context' => $this->context); $this->fileoptions = array('subdirs' => 1, 'maxfiles' => -1, 'maxbytes' => -1); $this->category = $category; - $this->categorycontext = get_context_instance_by_id($category->contextid); + $this->categorycontext = context::instance_by_id($category->contextid); parent::__construct($submiturl, null, 'post', '', null, $formeditable); } diff --git a/question/type/questiontypebase.php b/question/type/questiontypebase.php index 50bbe76ee1d..22226da6e3f 100644 --- a/question/type/questiontypebase.php +++ b/question/type/questiontypebase.php @@ -1023,7 +1023,7 @@ class question_type { protected function get_context_by_category_id($category) { global $DB; $contextid = $DB->get_field('question_categories', 'contextid', array('id'=>$category)); - $context = get_context_instance_by_id($contextid); + $context = context::instance_by_id($contextid); return $context; } diff --git a/report/security/locallib.php b/report/security/locallib.php index 65736291ca9..f6021fd2193 100644 --- a/report/security/locallib.php +++ b/report/security/locallib.php @@ -850,7 +850,7 @@ function report_security_check_riskbackup($detailed=false) { $links = array(); foreach ($overriddenroles as $role) { $role->name = $role->localname; - $context = get_context_instance_by_id($role->contextid); + $context = context::instance_by_id($role->contextid); $role->name = role_get_name($role, $context, ROLENAME_BOTH); $role->contextname = print_context_name($context); $role->url = "$CFG->wwwroot/$CFG->admin/roles/override.php?contextid=$role->contextid&roleid=$role->id"; @@ -867,7 +867,7 @@ function report_security_check_riskbackup($detailed=false) { $sqluserinfo ORDER BY u.lastname, u.firstname", $params); foreach ($rs as $user) { - $context = get_context_instance_by_id($user->contextid); + $context = context::instance_by_id($user->contextid); $url = "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=$user->contextid&roleid=$user->roleid"; $a = (object)array('fullname'=>fullname($user), 'url'=>$url, 'email'=>$user->email, 'contextname'=>print_context_name($context)); diff --git a/repository/coursefiles/lib.php b/repository/coursefiles/lib.php index c25be53ca12..ba4891a3edd 100644 --- a/repository/coursefiles/lib.php +++ b/repository/coursefiles/lib.php @@ -67,7 +67,7 @@ class repository_coursefiles extends repository { if (is_array($params)) { $filepath = is_null($params['filepath']) ? NULL : clean_param($params['filepath'], PARAM_PATH);; $filename = is_null($params['filename']) ? NULL : clean_param($params['filename'], PARAM_FILE); - $context = get_context_instance_by_id(clean_param($params['contextid'], PARAM_INT)); + $context = context::instance_by_id(clean_param($params['contextid'], PARAM_INT)); } } else { $filename = null; @@ -158,7 +158,7 @@ class repository_coursefiles extends repository { $filepath = clean_param($params['filepath'], PARAM_PATH);; $filearea = clean_param($params['filearea'], PARAM_AREA); $component = clean_param($params['component'], PARAM_COMPONENT); - $context = get_context_instance_by_id($contextid); + $context = context::instance_by_id($contextid); $file_info = $browser->get_file_info($context, $component, $filearea, $fileitemid, $filepath, $filename); return $file_info->get_url(); diff --git a/repository/draftfiles_ajax.php b/repository/draftfiles_ajax.php index a3ea3aa00b8..43ff97d678c 100644 --- a/repository/draftfiles_ajax.php +++ b/repository/draftfiles_ajax.php @@ -309,7 +309,7 @@ switch ($action) { if (isset($source->original)) { $reffiles = $fs->search_references($source->original); foreach ($reffiles as $reffile) { - $refcontext = get_context_instance_by_id($reffile->get_contextid()); + $refcontext = context::instance_by_id($reffile->get_contextid()); $fileinfo = $browser->get_file_info($refcontext, $reffile->get_component(), $reffile->get_filearea(), $reffile->get_itemid(), $reffile->get_filepath(), $reffile->get_filename()); if (empty($fileinfo)) { $return['references'][] = get_string('undisclosedreference', 'repository'); diff --git a/repository/lib.php b/repository/lib.php index e8a60f4b72e..1a51e8eee1d 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -496,7 +496,7 @@ abstract class repository { if (is_object($context)) { $this->context = $context; } else { - $this->context = get_context_instance_by_id($context); + $this->context = context::instance_by_id($context); } $this->instance = $DB->get_record('repository_instances', array('id'=>$this->id)); $this->readonly = $readonly; @@ -1175,7 +1175,7 @@ abstract class repository { $fileinfo = null; $params = file_storage::unpack_reference($reference, true); if (is_array($params)) { - $context = get_context_instance_by_id($params['contextid']); + $context = context::instance_by_id($params['contextid']); if ($context) { $browser = get_file_browser(); $fileinfo = $browser->get_file_info($context, $params['component'], $params['filearea'], $params['itemid'], $params['filepath'], $params['filename']); @@ -1622,7 +1622,7 @@ abstract class repository { $filepath = clean_param($params['filepath'], PARAM_PATH); $filearea = clean_param($params['filearea'], PARAM_AREA); $component = clean_param($params['component'], PARAM_COMPONENT); - $context = get_context_instance_by_id($contextid); + $context = context::instance_by_id($contextid); $file_info = $browser->get_file_info($context, $component, $filearea, $fileitemid, $filepath, $filename); if (!empty($file_info)) { $filesize = $file_info->get_filesize(); diff --git a/repository/local/lib.php b/repository/local/lib.php index a4c511dcbee..37d214a57a8 100644 --- a/repository/local/lib.php +++ b/repository/local/lib.php @@ -63,7 +63,7 @@ class repository_local extends repository { $itemid = is_null($params['itemid']) ? NULL : clean_param($params['itemid'], PARAM_INT); $filepath = is_null($params['filepath']) ? NULL : clean_param($params['filepath'], PARAM_PATH);; $filename = is_null($params['filename']) ? NULL : clean_param($params['filename'], PARAM_FILE); - $context = get_context_instance_by_id(clean_param($params['contextid'], PARAM_INT)); + $context = context::instance_by_id(clean_param($params['contextid'], PARAM_INT)); } } else { $itemid = null; diff --git a/repository/manage_instances.php b/repository/manage_instances.php index a6b1363798d..43efe2efb53 100644 --- a/repository/manage_instances.php +++ b/repository/manage_instances.php @@ -65,7 +65,7 @@ if ($usercourseid != SITEID) { $url->param('usercourseid', $usercourseid); } -$context = get_context_instance_by_id($contextid); +$context = context::instance_by_id($contextid); $PAGE->set_url($url); $PAGE->set_context($context); @@ -177,7 +177,7 @@ if (!empty($edit) || !empty($new)) { } $success = $instance->set_option($settings); } else { - $success = repository::static_function($plugin, 'create', $plugin, 0, get_context_instance_by_id($contextid), $fromform); + $success = repository::static_function($plugin, 'create', $plugin, 0, context::instance_by_id($contextid), $fromform); $data = data_submitted(); } if ($success) { diff --git a/repository/recent/lib.php b/repository/recent/lib.php index f1265c84add..76cdb69e2a8 100644 --- a/repository/recent/lib.php +++ b/repository/recent/lib.php @@ -122,7 +122,7 @@ class repository_recent extends repository { foreach ($files as $file) { // Check that file exists and accessible, retrieve size/date info $browser = get_file_browser(); - $context = get_context_instance_by_id($file['contextid']); + $context = context::instance_by_id($file['contextid']); $fileinfo = $browser->get_file_info($context, $file['component'], $file['filearea'], $file['itemid'], $file['filepath'], $file['filename']); if ($fileinfo) { diff --git a/repository/repository_ajax.php b/repository/repository_ajax.php index d9f3cea305f..f19738be1b9 100644 --- a/repository/repository_ajax.php +++ b/repository/repository_ajax.php @@ -94,8 +94,8 @@ switch ($action) { // global search case 'gsearch': $params = array(); - $params['context'] = array(get_context_instance_by_id($contextid), get_system_context()); - $params['currentcontext'] = get_context_instance_by_id($contextid); + $params['context'] = array(context::instance_by_id($contextid), get_system_context()); + $params['currentcontext'] = context::instance_by_id($contextid); $repos = repository::get_instances($params); $list = array(); foreach($repos as $repo){ diff --git a/user/index.php b/user/index.php index b30a10b0408..73fe0ee667f 100644 --- a/user/index.php +++ b/user/index.php @@ -34,7 +34,7 @@ 'id' => $courseid)); if ($contextid) { - $context = get_context_instance_by_id($contextid, MUST_EXIST); + $context = context::instance_by_id($contextid, MUST_EXIST); if ($context->contextlevel != CONTEXT_COURSE) { print_error('invalidcontext'); } diff --git a/webservice/lib.php b/webservice/lib.php index 66ed91f8f8e..31e78b9a5cf 100644 --- a/webservice/lib.php +++ b/webservice/lib.php @@ -949,7 +949,7 @@ abstract class webservice_server implements webservice_server_interface { . ' is not supported - check this allowed user'); } - $this->restricted_context = get_context_instance_by_id($token->contextid); + $this->restricted_context = context::instance_by_id($token->contextid); $this->restricted_serviceid = $token->externalserviceid; $user = $DB->get_record('user', array('id'=>$token->userid), '*', MUST_EXIST); From 5fbe2118bc60ee7611684e4029a50a71b2bbc27a Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Tue, 21 Aug 2012 15:02:40 +0800 Subject: [PATCH 2/2] MDL-34549 libraries: Changing strictness of context::instance_by_id() when required --- blocks/html/block_html.php | 2 +- blocks/html/lib.php | 2 +- comment/locallib.php | 2 +- enrol/externallib.php | 4 ++-- lib/filebrowser/file_info_context_course.php | 2 +- lib/filebrowser/file_info_context_coursecat.php | 2 +- lib/filebrowser/file_info_context_module.php | 2 +- lib/tests/accesslib_test.php | 2 +- question/editlib.php | 2 +- question/type/questiontypebase.php | 2 +- repository/lib.php | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/blocks/html/block_html.php b/blocks/html/block_html.php index 6ca71b30f1b..c60c118e9e3 100644 --- a/blocks/html/block_html.php +++ b/blocks/html/block_html.php @@ -104,7 +104,7 @@ class block_html extends block_base { function content_is_trusted() { global $SCRIPT; - if (!$context = context::instance_by_id($this->instance->parentcontextid)) { + if (!$context = context::instance_by_id($this->instance->parentcontextid, IGNORE_MISSING)) { return false; } //find out if this block is on the profile page diff --git a/blocks/html/lib.php b/blocks/html/lib.php index 93fdbb8c8e4..03d58ca27ce 100644 --- a/blocks/html/lib.php +++ b/blocks/html/lib.php @@ -53,7 +53,7 @@ function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $a send_file_not_found(); } - if ($parentcontext = context::instance_by_id($birecord_or_cm->parentcontextid)) { + if ($parentcontext = context::instance_by_id($birecord_or_cm->parentcontextid, IGNORE_MISSING)) { if ($parentcontext->contextlevel == CONTEXT_USER) { // force download on all personal pages including /my/ //because we do not have reliable way to find out from where this is used diff --git a/comment/locallib.php b/comment/locallib.php index 25f907f4c16..c53fa801a20 100644 --- a/comment/locallib.php +++ b/comment/locallib.php @@ -114,7 +114,7 @@ class comment_manager { */ private function setup_plugin($comment) { global $DB; - $this->context = context::instance_by_id($comment->contextid); + $this->context = context::instance_by_id($comment->contextid, IGNORE_MISSING); if (!$this->context) { return false; } diff --git a/enrol/externallib.php b/enrol/externallib.php index e669ca747f7..757362aa694 100644 --- a/enrol/externallib.php +++ b/enrol/externallib.php @@ -381,7 +381,7 @@ class core_role_external extends external_api { foreach ($params['assignments'] as $assignment) { // Ensure the current user is allowed to run this function in the enrolment context - $context = context::instance_by_id($assignment['contextid']); + $context = context::instance_by_id($assignment['contextid'], IGNORE_MISSING); self::validate_context($context); require_capability('moodle/role:assign', $context); @@ -445,7 +445,7 @@ class core_role_external extends external_api { foreach ($params['unassignments'] as $unassignment) { // Ensure the current user is allowed to run this function in the unassignment context - $context = context::instance_by_id($unassignment['contextid']); + $context = context::instance_by_id($unassignment['contextid'], IGNORE_MISSING); self::validate_context($context); require_capability('moodle/role:assign', $context); diff --git a/lib/filebrowser/file_info_context_course.php b/lib/filebrowser/file_info_context_course.php index d1e703b7e9d..0f0816b15e9 100644 --- a/lib/filebrowser/file_info_context_course.php +++ b/lib/filebrowser/file_info_context_course.php @@ -401,7 +401,7 @@ class file_info_context_course extends file_info { public function get_parent() { //TODO: error checking if get_parent_contextid() returns false $pcid = get_parent_contextid($this->context); - $parent = context::instance_by_id($pcid); + $parent = context::instance_by_id($pcid, IGNORE_MISSING); return $this->browser->get_file_info($parent); } } diff --git a/lib/filebrowser/file_info_context_coursecat.php b/lib/filebrowser/file_info_context_coursecat.php index 47636e6ce06..9cab4502f25 100644 --- a/lib/filebrowser/file_info_context_coursecat.php +++ b/lib/filebrowser/file_info_context_coursecat.php @@ -195,7 +195,7 @@ class file_info_context_coursecat extends file_info { */ public function get_parent() { $cid = get_parent_contextid($this->context); - $parent = context::instance_by_id($cid); + $parent = context::instance_by_id($cid, IGNORE_MISSING); return $this->browser->get_file_info($parent); } } diff --git a/lib/filebrowser/file_info_context_module.php b/lib/filebrowser/file_info_context_module.php index 363f6a0b82f..7e8ac7722ac 100644 --- a/lib/filebrowser/file_info_context_module.php +++ b/lib/filebrowser/file_info_context_module.php @@ -283,7 +283,7 @@ class file_info_context_module extends file_info { */ public function get_parent() { $pcid = get_parent_contextid($this->context); - $parent = context::instance_by_id($pcid); + $parent = context::instance_by_id($pcid, IGNORE_MISSING); return $this->browser->get_file_info($parent); } } diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index b8535fd7c98..4542513ba49 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -2271,7 +2271,7 @@ class accesslib_testcase extends advanced_testcase { foreach ($DB->get_records('context') as $contextid=>$record) { $context = context::instance_by_id($contextid); - $this->assertSame(context::instance_by_id($contextid), $context); + $this->assertSame(context::instance_by_id($contextid, IGNORE_MISSING), $context); $this->assertSame(get_context_instance($record->contextlevel, $record->instanceid), $context); $this->assertSame(get_parent_contexts($context), $context->get_parent_context_ids()); if ($context->id == SYSCONTEXTID) { diff --git a/question/editlib.php b/question/editlib.php index bb4633f4fd0..bb563f718f3 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -1717,7 +1717,7 @@ function question_get_display_preference($param, $default, $type, $thispageurl) function require_login_in_context($contextorid = null){ global $DB, $CFG; if (!is_object($contextorid)){ - $context = context::instance_by_id($contextorid); + $context = context::instance_by_id($contextorid, IGNORE_MISSING); } else { $context = $contextorid; } diff --git a/question/type/questiontypebase.php b/question/type/questiontypebase.php index 22226da6e3f..9b51a8b0043 100644 --- a/question/type/questiontypebase.php +++ b/question/type/questiontypebase.php @@ -1023,7 +1023,7 @@ class question_type { protected function get_context_by_category_id($category) { global $DB; $contextid = $DB->get_field('question_categories', 'contextid', array('id'=>$category)); - $context = context::instance_by_id($contextid); + $context = context::instance_by_id($contextid, IGNORE_MISSING); return $context; } diff --git a/repository/lib.php b/repository/lib.php index 1a51e8eee1d..10a8d1c6573 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -1175,7 +1175,7 @@ abstract class repository { $fileinfo = null; $params = file_storage::unpack_reference($reference, true); if (is_array($params)) { - $context = context::instance_by_id($params['contextid']); + $context = context::instance_by_id($params['contextid'], IGNORE_MISSING); if ($context) { $browser = get_file_browser(); $fileinfo = $browser->get_file_info($context, $params['component'], $params['filearea'], $params['itemid'], $params['filepath'], $params['filename']);