Skip to content
Browse files

MDL-34549 libraries: Changing strictness of context::instance_by_id()…

… when required
  • Loading branch information...
1 parent d197ea4 commit 5fbe2118bc60ee7611684e4029a50a71b2bbc27a @ankitagarwal ankitagarwal committed Aug 21, 2012
View
2 blocks/html/block_html.php
@@ -104,7 +104,7 @@ function instance_delete() {
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
View
2 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
View
2 comment/locallib.php
@@ -114,7 +114,7 @@ private function setup_course($courseid) {
*/
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;
}
View
4 enrol/externallib.php
@@ -381,7 +381,7 @@ public static function assign_roles($assignments) {
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 @@ public static function unassign_roles($unassignments) {
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);
View
2 lib/filebrowser/file_info_context_course.php
@@ -401,7 +401,7 @@ public function get_children() {
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);
}
}
View
2 lib/filebrowser/file_info_context_coursecat.php
@@ -195,7 +195,7 @@ public function get_children() {
*/
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);
}
}
View
2 lib/filebrowser/file_info_context_module.php
@@ -283,7 +283,7 @@ public function get_children() {
*/
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);
}
}
View
2 lib/tests/accesslib_test.php
@@ -2271,7 +2271,7 @@ public function test_permission_evaluation() {
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) {
View
2 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;
}
View
2 question/type/questiontypebase.php
@@ -1023,7 +1023,7 @@ public function generate_test($name, $courseid=null) {
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;
}
View
2 repository/lib.php
@@ -1175,7 +1175,7 @@ public function get_reference_details($reference, $filestatus = 0) {
$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']);

0 comments on commit 5fbe211

Please sign in to comment.
Something went wrong with that request. Please try again.