mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-34549 libraries: Changing strictness of context::instance_by_id() when required
This commit is contained in:
parent
d197ea4300
commit
5fbe2118bc
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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']);
|
||||
|
Loading…
x
Reference in New Issue
Block a user