Skip to content

Commit

Permalink
MDL-40402 libraries: Replace get_system_context() with context_system…
Browse files Browse the repository at this point in the history
…::instance() in core
  • Loading branch information
ankitagarwal committed Jul 4, 2013
1 parent 85b2e46 commit 0601e0e
Show file tree
Hide file tree
Showing 40 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion admin/tool/capability/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function print_report_tree($contextid, $contexts, $allroles) {

// Start the list item, and print the context name as a link to the place to
// make changes.
if ($contextid == get_system_context()->id) {
if ($contextid == context_system::instance()->id) {
$url = "$CFG->wwwroot/$CFG->admin/roles/manage.php";
$title = get_string('changeroles', 'tool_capability');
} else {
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/customlang/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/customlang/filter_form.php');

require_login(SITEID, false);
require_capability('tool/customlang:edit', get_system_context());
require_capability('tool/customlang:edit', context_system::instance());

$lng = required_param('lng', PARAM_LANG);
$currentpage = optional_param('p', 0, PARAM_INT);
Expand Down
8 changes: 4 additions & 4 deletions admin/tool/customlang/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
require_once($CFG->libdir.'/adminlib.php');

require_login(SITEID, false);
require_capability('tool/customlang:view', get_system_context());
require_capability('tool/customlang:view', context_system::instance());

$action = optional_param('action', '', PARAM_ALPHA);
$confirm = optional_param('confirm', false, PARAM_BOOL);
Expand All @@ -42,7 +42,7 @@
// pre-output actions
if ($action === 'checkout') {
require_sesskey();
require_capability('tool/customlang:edit', get_system_context());
require_capability('tool/customlang:edit', context_system::instance());
if (empty($lng)) {
print_error('missingparameter');
}
Expand All @@ -66,7 +66,7 @@

if ($action === 'checkin') {
require_sesskey();
require_capability('tool/customlang:edit', get_system_context());
require_capability('tool/customlang:edit', context_system::instance());
if (empty($lng)) {
print_error('missingparameter');
}
Expand Down Expand Up @@ -119,7 +119,7 @@
}

$menu = array();
if (has_capability('tool/customlang:edit', get_system_context())) {
if (has_capability('tool/customlang:edit', context_system::instance())) {
$menu['checkout'] = array(
'title' => get_string('checkout', 'tool_customlang'),
'url' => new moodle_url($PAGE->url, array('action' => 'checkout', 'lng' => $lng)),
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/generator/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}

$PAGE->set_url('/admin/tool/generator/index.php');
$PAGE->set_context(get_system_context());
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('base');
$generator = new generator_web();
$generator->setup();
Expand Down
2 changes: 1 addition & 1 deletion auth/mnet/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function start_jump_session($mnethostid, $wantsurl, $wantsurlbackhere=false) {
}

// check remote login permissions
if (! has_capability('moodle/site:mnetlogintoremote', get_system_context())
if (! has_capability('moodle/site:mnetlogintoremote', context_system::instance())
or is_mnet_remote_user($USER)
or isguestuser()
or !isloggedin()) {
Expand Down
2 changes: 1 addition & 1 deletion cache/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ public static function get_definition_actions(context $context, array $definitio
*/
public static function get_store_instance_actions($name, array $storedetails) {
$actions = array();
if (has_capability('moodle/site:config', get_system_context())) {
if (has_capability('moodle/site:config', context_system::instance())) {
$baseurl = new moodle_url('/cache/admin.php', array('store' => $name, 'sesskey' => sesskey()));
if (empty($storedetails['default'])) {
$actions[] = array(
Expand Down
4 changes: 2 additions & 2 deletions calendar/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false) {
}
}
if ($group === false) {
if (!empty($CFG->calendar_adminseesall) && has_any_capability($allgroupscaps, get_system_context())) {
if (!empty($CFG->calendar_adminseesall) && has_any_capability($allgroupscaps, context_system::instance())) {
$group = true;
} else if ($isloggedin) {
$groupids = array();
Expand Down Expand Up @@ -1790,7 +1790,7 @@ function calendar_set_event_type_display($type, $display = null, $user = null) {
function calendar_get_allowed_types(&$allowed, $course = null) {
global $USER, $CFG, $DB;
$allowed = new stdClass();
$allowed->user = has_capability('moodle/calendar:manageownentries', get_system_context());
$allowed->user = has_capability('moodle/calendar:manageownentries', context_system::instance());
$allowed->groups = false; // This may change just below
$allowed->courses = false; // This may change just below
$allowed->site = has_capability('moodle/calendar:manageentries', context_course::instance(SITEID));
Expand Down
2 changes: 1 addition & 1 deletion course/editcategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
}
$context = context_coursecat::instance($parent);
} else {
$context = get_system_context();
$context = context_system::instance();
}
$PAGE->set_context($context);
$category = new stdClass();
Expand Down
2 changes: 1 addition & 1 deletion course/editcategory_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function definition() {

// get list of categories to use as parents, with site as the first one
$options = array();
if (has_capability('moodle/category:manage', get_system_context()) || $category->parent == 0) {
if (has_capability('moodle/category:manage', context_system::instance()) || $category->parent == 0) {
$options[0] = get_string('top');
}
if ($category->id) {
Expand Down
2 changes: 1 addition & 1 deletion enrol/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public static function get_enrolled_users($courseid, $options = array()) {
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
$coursecontext = context_course::instance($courseid, IGNORE_MISSING);
if ($courseid == SITEID) {
$context = get_system_context();
$context = context_system::instance();
} else {
$context = $coursecontext;
}
Expand Down
2 changes: 1 addition & 1 deletion error/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
$PAGE->set_url('/error/');
$PAGE->set_title($site->fullname .':Error');
$PAGE->set_heading($site->fullname .': Error 404');
$PAGE->set_context(get_system_context());
$PAGE->set_context(context_system::instance());
$PAGE->navbar->add('Error 404 - File not Found');
echo $OUTPUT->header();
echo $OUTPUT->box(get_string('pagenotexist', 'error'). '<br />'.s($requesturi), 'generalbox boxaligncenter');
Expand Down
2 changes: 1 addition & 1 deletion files/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function get_files($contextid, $component, $filearea, $itemid, $fi
$browser = get_file_browser();

if (empty($fileinfo['contextid'])) {
$context = get_system_context();
$context = context_system::instance();
} else {
$context = context::instance_by_id($fileinfo['contextid']);
}
Expand Down
2 changes: 1 addition & 1 deletion grade/grading/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*
* @category grading
* @example $manager = get_grading_manager($areaid);
* @example $manager = get_grading_manager(get_system_context());
* @example $manager = get_grading_manager(context_system::instance());
* @example $manager = get_grading_manager($context, 'mod_assignment', 'submission');
* @param stdClass|int|null $context_or_areaid if $areaid is passed, no other parameter is needed
* @param string|null $component the frankenstyle name of the component
Expand Down
4 changes: 2 additions & 2 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6959,7 +6959,7 @@ public function output_html($data, $query='') {
// Calculate number of instances in order to display them for the Moodle administrator
if (!empty($instanceoptionnames)) {
$params = array();
$params['context'] = array(get_system_context());
$params['context'] = array(context_system::instance());
$params['onlyvisible'] = false;
$params['type'] = $typename;
$admininstancenumber = count(repository::static_function($typename, 'get_instances', $params));
Expand Down Expand Up @@ -7117,7 +7117,7 @@ private function set_protocol_cap($status) {
$assign = true;
}
if (!empty($assign)) {
$systemcontext = get_system_context();
$systemcontext = context_system::instance();
assign_capability('webservice/xmlrpc:use', $permission, $CFG->defaultuserroleid, $systemcontext->id, true);
assign_capability('webservice/rest:use', $permission, $CFG->defaultuserroleid, $systemcontext->id, true);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ protected function add_category(stdClass $category, navigation_node $parent, $no
$categoryname = format_string($category->name, true, array('context' => $context));
$categorynode = $parent->add($categoryname, $url, $nodetype, $categoryname, $category->id);
if (empty($category->visible)) {
if (has_capability('moodle/category:viewhiddencategories', get_system_context())) {
if (has_capability('moodle/category:viewhiddencategories', context_system::instance())) {
$categorynode->hidden = true;
} else {
$categorynode->display = false;
Expand Down Expand Up @@ -2484,7 +2484,7 @@ public function add_front_page_course_essentials(navigation_node $coursenode, st
$coursenode->add('frontpageloaded', null, self::TYPE_CUSTOM, null, 'frontpageloaded')->display = false;

//Participants
if (has_capability('moodle/course:viewparticipants', get_system_context())) {
if (has_capability('moodle/course:viewparticipants', context_system::instance())) {
$coursenode->add(get_string('participants'), new moodle_url('/user/index.php?id='.$course->id), self::TYPE_CUSTOM, get_string('participants'), 'participants');
}

Expand Down Expand Up @@ -3913,7 +3913,7 @@ protected function generate_user_settings($courseid, $userid, $gstitle='usercurr
}

$coursecontext = context_course::instance($course->id); // Course context
$systemcontext = get_system_context();
$systemcontext = context_system::instance();
$currentuser = ($USER->id == $userid);

if ($currentuser) {
Expand Down Expand Up @@ -4059,7 +4059,7 @@ protected function generate_user_settings($courseid, $userid, $gstitle='usercurr
$enablemanagetokens = true;
} else if (!is_siteadmin($USER->id)
&& !empty($CFG->enablewebservices)
&& has_capability('moodle/webservice:createtoken', get_system_context()) ) {
&& has_capability('moodle/webservice:createtoken', context_system::instance()) ) {
$enablemanagetokens = true;
}
// Security keys
Expand Down
2 changes: 1 addition & 1 deletion lib/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ function stripslashes_deep($value) {
// define SYSCONTEXTID in config.php if you want to save some queries,
// after install it must match the system context record id.
if (!defined('SYSCONTEXTID')) {
get_system_context();
context_system::instance();
}

// Defining the site - aka frontpage course
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/accesslib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,7 @@ public function test_permission_evaluation() {
// =================================================================
// note: watch out, the fake site might be pretty borked already

$this->assertSame(get_system_context(), context_system::instance());
$this->assertSame(context_system::instance(), context_system::instance());

foreach ($DB->get_records('context') as $contextid=>$record) {
$context = context::instance_by_id($contextid);
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/moodlelib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2283,7 +2283,7 @@ public function test_convert_to_array() {
$this->assertEquals(convert_to_array($obj), (array)$obj);

// check that context object (with iterator) is converted to array properly
$obj = get_system_context();
$obj = context_system::instance();
$ar = array(
'id' => $obj->id,
'contextlevel' => $obj->contextlevel,
Expand Down
4 changes: 2 additions & 2 deletions login/token.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@
if (count($tokens) > 0) {
$token = array_pop($tokens);
} else {
if ( ($serviceshortname == MOODLE_OFFICIAL_MOBILE_SERVICE and has_capability('moodle/webservice:createmobiletoken', get_system_context()))
if ( ($serviceshortname == MOODLE_OFFICIAL_MOBILE_SERVICE and has_capability('moodle/webservice:createmobiletoken', context_system::instance()))
//Note: automatically token generation is not available to admin (they must create a token manually)
or (!is_siteadmin($user) && has_capability('moodle/webservice:createtoken', get_system_context()))) {
or (!is_siteadmin($user) && has_capability('moodle/webservice:createtoken', context_system::instance()))) {
// if service doesn't exist, dml will throw exception
$service_record = $DB->get_record('external_services', array('shortname'=>$serviceshortname, 'enabled'=>1), '*', MUST_EXIST);
// create a new token
Expand Down
2 changes: 1 addition & 1 deletion mnet/service/enrol/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
die();
}

$roamingusers = get_users_by_capability(get_system_context(), 'moodle/site:mnetlogintoremote', 'u.id');
$roamingusers = get_users_by_capability(context_system::instance(), 'moodle/site:mnetlogintoremote', 'u.id');
if (empty($roamingusers)) {
$capname = get_string('site:mnetlogintoremote', 'role');
$url = new moodle_url('/admin/roles/manage.php');
Expand Down
2 changes: 1 addition & 1 deletion mnet/service/enrol/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public function __construct($name, $options) {
public function find_users($search) {
global $CFG, $DB;

$systemcontext = get_system_context();
$systemcontext = context_system::instance();
$userids = get_users_by_capability($systemcontext, 'moodle/site:mnetlogintoremote', 'u.id');

if (empty($userids)) {
Expand Down
2 changes: 1 addition & 1 deletion mod/assign/adminmanageplugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// Create the class for this controller.
$pluginmanager = new assign_plugin_manager(required_param('subtype', PARAM_PLUGIN));

$PAGE->set_context(get_system_context());
$PAGE->set_context(context_system::instance());

// Execute the controller.
$pluginmanager->execute(optional_param('action', null, PARAM_PLUGIN),
Expand Down
2 changes: 1 addition & 1 deletion mod/data/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function xmldb_data_upgrade($oldversion) {
// Get directory contents.
$userfolders = new DirectoryIterator($oldpresetdir);
// Store the system context, these are site wide presets.
$context = get_system_context();
$context = context_system::instance();
// Create file storage object.
$fs = get_file_storage();
// Create array of accepted files.
Expand Down
4 changes: 2 additions & 2 deletions mod/feedback/delete_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
}

if ($template->ispublic) {
$systemcontext = get_system_context();
$systemcontext = context_system::instance();
require_capability('mod/feedback:createpublictemplate', $systemcontext);
require_capability('mod/feedback:deletetemplate', $systemcontext);
}
Expand Down Expand Up @@ -164,7 +164,7 @@
echo $OUTPUT->box_end();
}
//now we get the public templates if it is permitted
$systemcontext = get_system_context();
$systemcontext = context_system::instance();
if (has_capability('mod/feedback:createpublictemplate', $systemcontext) AND
has_capability('mod/feedback:deletetemplate', $systemcontext)) {
$templates = feedback_get_template_list($course, 'public');
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
$savereturn = 'notsaved_name';
} else {
//If the feedback is located on the frontpage then templates can be public.
if (has_capability('mod/feedback:createpublictemplate', get_system_context())) {
if (has_capability('mod/feedback:createpublictemplate', context_system::instance())) {
$create_template_formdata->ispublic = isset($create_template_formdata->ispublic) ? 1 : 0;
} else {
$create_template_formdata->ispublic = 0;
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function set_form_elements() {
get_string('name', 'feedback'),
array('size'=>'40', 'maxlength'=>'200'));

if (has_capability('mod/feedback:createpublictemplate', get_system_context())) {
if (has_capability('mod/feedback:createpublictemplate', context_system::instance())) {
$elementgroup[] = $mform->createElement('checkbox',
'ispublic',
get_string('public', 'feedback'),
Expand Down
2 changes: 1 addition & 1 deletion mod/feedback/item/label/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function print_item($item) {
if (!$item->feedback AND $item->template) {
$template = $DB->get_record('feedback_template', array('id'=>$item->template));
if ($template->ispublic) {
$context = get_system_context();
$context = context_system::instance();
} else {
$context = context_course::instance($template->course);
}
Expand Down
6 changes: 3 additions & 3 deletions mod/feedback/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ function feedback_save_as_template($feedback, $name, $ispublic = 0) {
//if the template is public the files are in the system context
//files in the feedback_item are in the feedback_context of the feedback
if ($ispublic) {
$s_context = get_system_context();
$s_context = context_system::instance();
} else {
$s_context = context_course::instance($newtempl->course);
}
Expand Down Expand Up @@ -1223,7 +1223,7 @@ function feedback_items_from_template($feedback, $templateid, $deleteold = false
//files in the template_item are in the context of the current course
//files in the feedback_item are in the feedback_context of the feedback
if ($template->ispublic) {
$s_context = get_system_context();
$s_context = context_system::instance();
} else {
$s_context = context_course::instance($feedback->course);
}
Expand Down Expand Up @@ -1526,7 +1526,7 @@ function feedback_delete_item($itemid, $renumber = true, $template = false) {

if ($template) {
if ($template->ispublic) {
$context = get_system_context();
$context = context_system::instance();
} else {
$context = context_course::instance($template->course);
}
Expand Down
4 changes: 2 additions & 2 deletions mod/forum/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
// Make sure the user has not been deleted
if ($user->deleted) {
$PAGE->set_title(get_string('userdeleted'));
$PAGE->set_context(get_system_context());
$PAGE->set_context(context_system::instance());
echo $OUTPUT->header();
echo $OUTPUT->heading($PAGE->title);
echo $OUTPUT->footer();
Expand Down Expand Up @@ -110,7 +110,7 @@
// We are going to search for all of the users posts in all courses!
// a general require login here as we arn't actually within any course.
require_login();
$PAGE->set_context(get_system_context());
$PAGE->set_context(context_system::instance());

// Now we need to get all of the courses to search.
// All courses where the user has posted within a forum will be returned.
Expand Down
2 changes: 1 addition & 1 deletion portfolio/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
$callerformats = optional_param('callerformats', null, PARAM_TAGLIST); // Comma separated list of formats the specific place exporting content supports.

require_login(); // this is selectively called again with $course later when we know for sure which one we're in.
$PAGE->set_context(get_system_context());
$PAGE->set_context(context_system::instance());
$PAGE->set_url('/portfolio/add.php', array('id' => $dataid, 'sesskey' => sesskey()));
$PAGE->set_pagelayout('standard');
$exporter = null;
Expand Down
2 changes: 1 addition & 1 deletion repository/draftfiles_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
require_once($CFG->libdir.'/filelib.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->dirroot.'/repository/lib.php');
$PAGE->set_context(get_system_context());
$PAGE->set_context(context_system::instance());
require_login();
if (isguestuser()) {
print_error('noguest');
Expand Down
2 changes: 1 addition & 1 deletion repository/filepicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
default:
case 'plugins':
$params = array();
$params['context'] = array($user_context, get_system_context());
$params['context'] = array($user_context, context_system::instance());
$params['currentcontext'] = $PAGE->context;
$params['return_types'] = FILE_INTERNAL;

Expand Down
Loading

0 comments on commit 0601e0e

Please sign in to comment.