Skip to content

Commit

Permalink
MDL-34549 libraries: Changing strictness of context::instance_by_id()…
Browse files Browse the repository at this point in the history
… when required
  • Loading branch information
ankitagarwal committed Aug 24, 2012
1 parent d197ea4 commit 5fbe211
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion blocks/html/block_html.php
Expand Up @@ -104,7 +104,7 @@ function instance_delete() {
function content_is_trusted() { function content_is_trusted() {
global $SCRIPT; global $SCRIPT;


if (!$context = context::instance_by_id($this->instance->parentcontextid)) { if (!$context = context::instance_by_id($this->instance->parentcontextid, IGNORE_MISSING)) {
return false; return false;
} }
//find out if this block is on the profile page //find out if this block is on the profile page
Expand Down
2 changes: 1 addition & 1 deletion blocks/html/lib.php
Expand Up @@ -53,7 +53,7 @@ function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $a
send_file_not_found(); 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) { if ($parentcontext->contextlevel == CONTEXT_USER) {
// force download on all personal pages including /my/ // force download on all personal pages including /my/
//because we do not have reliable way to find out from where this is used //because we do not have reliable way to find out from where this is used
Expand Down
2 changes: 1 addition & 1 deletion comment/locallib.php
Expand Up @@ -114,7 +114,7 @@ private function setup_course($courseid) {
*/ */
private function setup_plugin($comment) { private function setup_plugin($comment) {
global $DB; global $DB;
$this->context = context::instance_by_id($comment->contextid); $this->context = context::instance_by_id($comment->contextid, IGNORE_MISSING);
if (!$this->context) { if (!$this->context) {
return false; return false;
} }
Expand Down
4 changes: 2 additions & 2 deletions enrol/externallib.php
Expand Up @@ -381,7 +381,7 @@ public static function assign_roles($assignments) {


foreach ($params['assignments'] as $assignment) { foreach ($params['assignments'] as $assignment) {
// Ensure the current user is allowed to run this function in the enrolment context // 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); self::validate_context($context);
require_capability('moodle/role:assign', $context); require_capability('moodle/role:assign', $context);


Expand Down Expand Up @@ -445,7 +445,7 @@ public static function unassign_roles($unassignments) {


foreach ($params['unassignments'] as $unassignment) { foreach ($params['unassignments'] as $unassignment) {
// Ensure the current user is allowed to run this function in the unassignment context // 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); self::validate_context($context);
require_capability('moodle/role:assign', $context); require_capability('moodle/role:assign', $context);


Expand Down
2 changes: 1 addition & 1 deletion lib/filebrowser/file_info_context_course.php
Expand Up @@ -401,7 +401,7 @@ public function get_children() {
public function get_parent() { public function get_parent() {
//TODO: error checking if get_parent_contextid() returns false //TODO: error checking if get_parent_contextid() returns false
$pcid = get_parent_contextid($this->context); $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); return $this->browser->get_file_info($parent);
} }
} }
Expand Down
2 changes: 1 addition & 1 deletion lib/filebrowser/file_info_context_coursecat.php
Expand Up @@ -195,7 +195,7 @@ public function get_children() {
*/ */
public function get_parent() { public function get_parent() {
$cid = get_parent_contextid($this->context); $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); return $this->browser->get_file_info($parent);
} }
} }
2 changes: 1 addition & 1 deletion lib/filebrowser/file_info_context_module.php
Expand Up @@ -283,7 +283,7 @@ public function get_children() {
*/ */
public function get_parent() { public function get_parent() {
$pcid = get_parent_contextid($this->context); $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); return $this->browser->get_file_info($parent);
} }
} }
2 changes: 1 addition & 1 deletion lib/tests/accesslib_test.php
Expand Up @@ -2271,7 +2271,7 @@ public function test_permission_evaluation() {


foreach ($DB->get_records('context') as $contextid=>$record) { foreach ($DB->get_records('context') as $contextid=>$record) {
$context = context::instance_by_id($contextid); $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_context_instance($record->contextlevel, $record->instanceid), $context);
$this->assertSame(get_parent_contexts($context), $context->get_parent_context_ids()); $this->assertSame(get_parent_contexts($context), $context->get_parent_context_ids());
if ($context->id == SYSCONTEXTID) { if ($context->id == SYSCONTEXTID) {
Expand Down
2 changes: 1 addition & 1 deletion question/editlib.php
Expand Up @@ -1717,7 +1717,7 @@ function question_get_display_preference($param, $default, $type, $thispageurl)
function require_login_in_context($contextorid = null){ function require_login_in_context($contextorid = null){
global $DB, $CFG; global $DB, $CFG;
if (!is_object($contextorid)){ if (!is_object($contextorid)){
$context = context::instance_by_id($contextorid); $context = context::instance_by_id($contextorid, IGNORE_MISSING);
} else { } else {
$context = $contextorid; $context = $contextorid;
} }
Expand Down
2 changes: 1 addition & 1 deletion question/type/questiontypebase.php
Expand Up @@ -1023,7 +1023,7 @@ public function generate_test($name, $courseid=null) {
protected function get_context_by_category_id($category) { protected function get_context_by_category_id($category) {
global $DB; global $DB;
$contextid = $DB->get_field('question_categories', 'contextid', array('id'=>$category)); $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; return $context;
} }


Expand Down
2 changes: 1 addition & 1 deletion repository/lib.php
Expand Up @@ -1175,7 +1175,7 @@ public function get_reference_details($reference, $filestatus = 0) {
$fileinfo = null; $fileinfo = null;
$params = file_storage::unpack_reference($reference, true); $params = file_storage::unpack_reference($reference, true);
if (is_array($params)) { if (is_array($params)) {
$context = context::instance_by_id($params['contextid']); $context = context::instance_by_id($params['contextid'], IGNORE_MISSING);
if ($context) { if ($context) {
$browser = get_file_browser(); $browser = get_file_browser();
$fileinfo = $browser->get_file_info($context, $params['component'], $params['filearea'], $params['itemid'], $params['filepath'], $params['filename']); $fileinfo = $browser->get_file_info($context, $params['component'], $params['filearea'], $params['itemid'], $params['filepath'], $params['filename']);
Expand Down

0 comments on commit 5fbe211

Please sign in to comment.