Permalink
Browse files

MDL-34469 - lib - replacement of the deprecated get_context_instance …

…and get_context_by_id functions (group 15)
  • Loading branch information...
1 parent 55a568f commit a689cd1def7d6bc774f86de33439b306068f5021 @abgreeve abgreeve committed Jul 24, 2012
Showing with 80 additions and 79 deletions.
  1. +3 −3 backup/backup.php
  2. +1 −1 backup/backupfilesedit.php
  3. +1 −1 backup/converter/imscc11/backuplib.php
  4. +2 −2 backup/import.php
  5. +1 −1 backup/log.php
  6. +1 −1 backup/moodle2/backup_activity_task.class.php
  7. +2 −2 backup/moodle2/backup_block_task.class.php
  8. +1 −1 backup/moodle2/backup_course_task.class.php
  9. +1 −1 backup/moodle2/backup_final_task.class.php
  10. +1 −1 backup/moodle2/backup_section_task.class.php
  11. +5 −5 backup/moodle2/backup_stepslib.php
  12. +1 −1 backup/moodle2/restore_course_task.class.php
  13. +1 −1 backup/moodle2/restore_section_task.class.php
  14. +8 −8 backup/moodle2/restore_stepslib.php
  15. +4 −4 backup/restorefile.php
  16. +2 −2 backup/util/checks/backup_check.class.php
  17. +1 −1 backup/util/checks/restore_check.class.php
  18. +3 −3 backup/util/dbops/backup_plan_dbops.class.php
  19. +10 −10 backup/util/dbops/restore_dbops.class.php
  20. +2 −2 backup/util/helper/backup_cron_helper.class.php
  21. +5 −5 backup/util/helper/backup_helper.class.php
  22. +1 −1 backup/util/helper/restore_prechecks_helper.class.php
  23. +1 −1 backup/util/plan/restore_structure_step.class.php
  24. +2 −2 backup/util/ui/backup_ui_stage.class.php
  25. +5 −5 backup/util/ui/renderer.php
  26. +2 −1 backup/util/ui/restore_ui_components.php
  27. +3 −3 backup/util/ui/restore_ui_stage.class.php
  28. +2 −2 login/change_password.php
  29. +1 −1 login/confirm.php
  30. +1 −1 login/forgot_password.php
  31. +1 −1 login/index.php
  32. +1 −1 login/logout.php
  33. +1 −1 login/signup.php
  34. +3 −3 login/token.php
View
@@ -56,11 +56,11 @@
switch ($type) {
case backup::TYPE_1COURSE :
- require_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $course->id));
+ require_capability('moodle/backup:backupcourse', context_course::instance($course->id));
$heading = get_string('backupcourse', 'backup', $course->shortname);
break;
case backup::TYPE_1SECTION :
- $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
+ $coursecontext = context_course::instance($course->id);
require_capability('moodle/backup:backupsection', $coursecontext);
if ((string)$section->name !== '') {
$sectionname = format_string($section->name, true, array('context' => $coursecontext));
@@ -72,7 +72,7 @@
}
break;
case backup::TYPE_1ACTIVITY :
- require_capability('moodle/backup:backupactivity', get_context_instance(CONTEXT_MODULE, $cm->id));
+ require_capability('moodle/backup:backupactivity', context_module::instance($cm->id));
$heading = get_string('backupactivity', 'backup', $cm->name);
break;
default :
@@ -36,7 +36,7 @@
$returnurl = optional_param('returnurl', null, PARAM_URL);
list($context, $course, $cm) = get_context_info_array($currentcontext);
-$filecontext = get_context_instance_by_id($contextid);
+$filecontext = context::instance_by_id($contextid, IGNORE_MISSING);
$url = new moodle_url('/backup/backupfilesedit.php', array('currentcontext'=>$currentcontext, 'contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea));
@@ -76,7 +76,7 @@ protected function define_execution() {
$id = $dinfo[0]->id; // Id of activity/section/course (depends of type)
$courseid = $dinfo[0]->courseid; // Id of the course
- $ctxid = get_context_instance(CONTEXT_USER, $userid)->id;
+ $ctxid = context_user::instance($userid)->id;
$component = 'user';
$filearea = 'backup';
$itemid = 0;
View
@@ -16,7 +16,7 @@
// Load the course and context
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
-$context = get_context_instance(CONTEXT_COURSE, $courseid);
+$context = context_course::instance($courseid);
// Must pass login
require_login($course);
@@ -50,7 +50,7 @@
// Load the course +context to import from
$importcourse = $DB->get_record('course', array('id'=>$importcourseid), '*', MUST_EXIST);
-$importcontext = get_context_instance(CONTEXT_COURSE, $importcourseid);
+$importcontext = context_course::instance($importcourseid);
// Make sure the user can backup from that course
require_capability('moodle/backup:backuptargetimport', $importcontext);
View
@@ -6,6 +6,6 @@
require_login();
- require_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_SYSTEM));
+ require_capability('moodle/backup:backupcourse', context_system::instance());
redirect("$CFG->wwwroot/report/backups/index.php", '', 'admin', 1);
@@ -64,7 +64,7 @@ public function __construct($name, $moduleid, $plan = null) {
$this->sectionid = $coursemodule->section;
$this->modulename = $coursemodule->modname;
$this->activityid = $coursemodule->instance;
- $this->contextid = get_context_instance(CONTEXT_MODULE, $this->moduleid)->id;
+ $this->contextid = context_module::instance($this->moduleid)->id;
parent::__construct($name, $plan);
}
@@ -53,7 +53,7 @@ public function __construct($name, $blockid, $moduleid = null, $plan = null) {
$this->blockid = $blockid;
$this->blockname = $block->blockname;
- $this->contextid = get_context_instance(CONTEXT_BLOCK, $this->blockid)->id;
+ $this->contextid = context_block::instance($this->blockid)->id;
$this->moduleid = $moduleid;
$this->modulename = null;
$this->parentcontextid = null;
@@ -71,7 +71,7 @@ public function __construct($name, $blockid, $moduleid = null, $plan = null) {
$this->moduleid = $moduleid;
$this->modulename = $coursemodule->modname;
- $this->parentcontextid = get_context_instance(CONTEXT_MODULE, $this->moduleid)->id;
+ $this->parentcontextid = context_module::instance($this->moduleid)->id;
}
parent::__construct($name, $plan);
@@ -42,7 +42,7 @@ class backup_course_task extends backup_task {
public function __construct($name, $courseid, $plan = null) {
$this->courseid = $courseid;
- $this->contextid = get_context_instance(CONTEXT_COURSE, $this->courseid)->id;
+ $this->contextid = context_course::instance($this->courseid)->id;
parent::__construct($name, $plan);
}
@@ -43,7 +43,7 @@ public function build() {
global $CFG;
// Set the backup::VAR_CONTEXTID setting to course context as far as next steps require that
- $coursectxid = get_context_instance(CONTEXT_COURSE, $this->get_courseid())->id;
+ $coursectxid = context_course::instance($this->get_courseid())->id;
$this->add_setting(new backup_activity_generic_setting(backup::VAR_CONTEXTID, base_setting::IS_INTEGER, $coursectxid));
// Set the backup::VAR_COURSEID setting to course, we'll need that in some steps
@@ -71,7 +71,7 @@ public function get_taskbasepath() {
public function build() {
// Set the backup::VAR_CONTEXTID setting to course context as far as next steps require that
- $coursectxid = get_context_instance(CONTEXT_COURSE, $this->get_courseid())->id;
+ $coursectxid = context_course::instance($this->get_courseid())->id;
$this->add_setting(new backup_activity_generic_setting(backup::VAR_CONTEXTID, base_setting::IS_INTEGER, $coursectxid));
// Add some extra settings that related processors are going to need
@@ -667,7 +667,7 @@ protected function define_structure() {
AND bi.itemname = 'scalefinal'", array(backup::VAR_BACKUPID));
// Annotate scale files (they store files in system context, so pass it instead of default one)
- $scale->annotate_files('grade', 'scale', 'id', get_context_instance(CONTEXT_SYSTEM)->id);
+ $scale->annotate_files('grade', 'scale', 'id', context_system::instance()->id);
// Return main element (scalesdef)
return $scalesdef;
@@ -704,7 +704,7 @@ protected function define_structure() {
AND bi.itemname = 'outcomefinal'", array(backup::VAR_BACKUPID));
// Annotate outcome files (they store files in system context, so pass it instead of default one)
- $outcome->annotate_files('grade', 'outcome', 'id', get_context_instance(CONTEXT_SYSTEM)->id);
+ $outcome->annotate_files('grade', 'outcome', 'id', context_system::instance()->id);
// Return main element (outcomesdef)
return $outcomesdef;
@@ -1470,8 +1470,8 @@ protected function define_structure() {
$info['original_course_fullname'] = $originalcourseinfo->fullname;
$info['original_course_shortname'] = $originalcourseinfo->shortname;
$info['original_course_startdate'] = $originalcourseinfo->startdate;
- $info['original_course_contextid'] = get_context_instance(CONTEXT_COURSE, $this->get_courseid())->id;
- $info['original_system_contextid'] = get_context_instance(CONTEXT_SYSTEM)->id;
+ $info['original_course_contextid'] = context_course::instance($this->get_courseid())->id;
+ $info['original_system_contextid'] = context_system::instance()->id;
// Get more information from controller
list($dinfo, $cinfo, $sinfo) = backup_controller_dbops::get_moodle_backup_information($this->get_backupid());
@@ -1835,7 +1835,7 @@ protected function define_execution() {
'backupid' => $this->get_backupid(), 'itemname' => 'userfinal'));
foreach ($rs as $record) {
$userid = $record->itemid;
- $userctx = get_context_instance(CONTEXT_USER, $userid);
+ $userctx = context_user::instance($userid);
if (!$userctx) {
continue; // User has not context, sure it's a deleted user, so cannot have files
}
@@ -64,7 +64,7 @@ public function get_contextid() {
public function build() {
// Define the task contextid (the course one)
- $this->contextid = get_context_instance(CONTEXT_COURSE, $this->get_courseid())->id;
+ $this->contextid = context_course::instance($this->get_courseid())->id;
// Executed conditionally if restoring to new course or if overwrite_conf setting is enabled
if ($this->get_target() == backup::TARGET_NEW_COURSE || $this->get_setting_value('overwrite_conf') == true) {
@@ -74,7 +74,7 @@ public function get_sectionid() {
public function build() {
// Define the task contextid (the course one)
- $this->contextid = get_context_instance(CONTEXT_COURSE, $this->get_courseid())->id;
+ $this->contextid = context_course::instance($this->get_courseid())->id;
// We always try to restore as much info from sections as possible, no matter of the type
// of restore (new, existing, deleting, import...). MDL-27764
@@ -42,11 +42,11 @@ protected function define_execution() {
}
// Create the old-course-ctxid to new-course-ctxid mapping, we need that available since the beginning
$itemid = $this->task->get_old_contextid();
- $newitemid = get_context_instance(CONTEXT_COURSE, $this->get_courseid())->id;
+ $newitemid = context_course::instance($this->get_courseid())->id;
restore_dbops::set_backup_ids_record($this->get_restoreid(), 'context', $itemid, $newitemid);
// Create the old-system-ctxid to new-system-ctxid mapping, we need that available since the beginning
$itemid = $this->task->get_old_system_contextid();
- $newitemid = get_context_instance(CONTEXT_SYSTEM)->id;
+ $newitemid = context_system::instance()->id;
restore_dbops::set_backup_ids_record($this->get_restoreid(), 'context', $itemid, $newitemid);
// Create the old-course-id to new-course-id mapping, we need that available since the beginning
$itemid = $this->task->get_old_courseid();
@@ -268,7 +268,7 @@ protected function process_grade_letter($data) {
$data = (object)$data;
$oldid = $data->id;
- $data->contextid = get_context_instance(CONTEXT_COURSE, $this->get_courseid())->id;
+ $data->contextid = context_course::instance($this->get_courseid())->id;
$newitemid = $DB->insert_record('grade_letters', $data);
$this->set_mapping('grade_letter', $oldid, $newitemid);
@@ -888,7 +888,7 @@ protected function process_scale($data) {
$data->courseid = $data->courseid ? $this->get_courseid() : 0;
// If global scale (course=0), check the user has perms to create it
// falling to course scale if not
- $systemctx = get_context_instance(CONTEXT_SYSTEM);
+ $systemctx = context_system::instance();
if ($data->courseid == 0 && !has_capability('moodle/course:managescales', $systemctx , $this->task->get_userid())) {
$data->courseid = $this->get_courseid();
}
@@ -950,7 +950,7 @@ protected function process_outcome($data) {
$data->courseid = $data->courseid ? $this->get_courseid() : null;
// If global outcome (course=null), check the user has perms to create it
// falling to course outcome if not
- $systemctx = get_context_instance(CONTEXT_SYSTEM);
+ $systemctx = context_system::instance();
if (is_null($data->courseid) && !has_capability('moodle/grade:manageoutcomes', $systemctx , $this->task->get_userid())) {
$data->courseid = $this->get_courseid();
}
@@ -1275,7 +1275,7 @@ public function process_course($data) {
$data->fullname = $fullname;
$data->shortname= $shortname;
- $context = get_context_instance_by_id($this->task->get_contextid());
+ $context = context::instance_by_id($this->task->get_contextid());
if (has_capability('moodle/course:changeidnumber', $context, $this->task->get_userid())) {
$data->idnumber = '';
} else {
@@ -2484,7 +2484,7 @@ public function process_block($data) {
// Save the mapping (with restorefiles support)
$this->set_mapping('block_instance', $oldid, $newitemid, true);
// Create the block context
- $newcontextid = get_context_instance(CONTEXT_BLOCK, $newitemid)->id;
+ $newcontextid = context_block::instance($newitemid)->id;
// Save the block contexts mapping and sent it to task
$this->set_mapping('context', $oldcontextid, $newcontextid);
$this->task->set_contextid($newcontextid);
@@ -2619,7 +2619,7 @@ protected function process_module($data) {
// set the new course_module id in the task
$this->task->set_moduleid($newitemid);
// we can now create the context safely
- $ctxid = get_context_instance(CONTEXT_MODULE, $newitemid)->id;
+ $ctxid = context_module::instance($newitemid)->id;
// set the new context id in the task
$this->task->set_contextid($ctxid);
// update sequence field in course_section
@@ -43,7 +43,7 @@
// will be used when restore
if (!empty($filecontextid)) {
- $filecontext = get_context_instance_by_id($filecontextid);
+ $filecontext = context::instance_by_id($filecontextid);
}
$url = new moodle_url('/backup/restorefile.php', array('contextid'=>$contextid));
@@ -116,7 +116,7 @@
echo $OUTPUT->heading_with_help(get_string('choosefilefromactivitybackup', 'backup'), 'choosefilefromuserbackup', 'backup');
echo $OUTPUT->container_start();
$treeview_options = array();
- $user_context = get_context_instance(CONTEXT_USER, $USER->id);
+ $user_context = context_user::instance($USER->id);
$treeview_options['filecontext'] = $context;
$treeview_options['currentcontext'] = $context;
$treeview_options['component'] = 'backup';
@@ -142,7 +142,7 @@
echo $OUTPUT->heading_with_help(get_string('choosefilefromuserbackup', 'backup'), 'choosefilefromuserbackup', 'backup');
echo $OUTPUT->container_start();
$treeview_options = array();
-$user_context = get_context_instance(CONTEXT_USER, $USER->id);
+$user_context = context_user::instance($USER->id);
$treeview_options['filecontext'] = $user_context;
$treeview_options['currentcontext'] = $context;
$treeview_options['component'] = 'user';
@@ -157,7 +157,7 @@
echo $OUTPUT->heading_with_help(get_string('choosefilefromautomatedbackup', 'backup'), 'choosefilefromautomatedbackup', 'backup');
echo $OUTPUT->container_start();
$treeview_options = array();
- $user_context = get_context_instance(CONTEXT_USER, $USER->id);
+ $user_context = context_user::instance($USER->id);
$treeview_options['filecontext'] = $context;
$treeview_options['currentcontext'] = $context;
$treeview_options['component'] = 'backup';
@@ -95,7 +95,7 @@ public static function check_security($backup_controller, $apply) {
$type = $backup_controller->get_type();
$mode = $backup_controller->get_mode();
$courseid = $backup_controller->get_courseid();
- $coursectx= get_context_instance(CONTEXT_COURSE, $courseid);
+ $coursectx= context_course::instance($courseid);
$userid = $backup_controller->get_userid();
$id = $backup_controller->get_id(); // courseid / sectionid / cmid
@@ -118,7 +118,7 @@ public static function check_security($backup_controller, $apply) {
break;
case backup::TYPE_1ACTIVITY :
get_coursemodule_from_id(null, $id, $courseid, false, MUST_EXIST); // cm exists
- $modulectx = get_context_instance(CONTEXT_MODULE, $id);
+ $modulectx = context_module::instance($id);
$typecapstocheck['moodle/backup:backupactivity'] = $modulectx;
break;
default :
@@ -62,7 +62,7 @@ public static function check_security($restore_controller, $apply) {
$type = $restore_controller->get_type();
$mode = $restore_controller->get_mode();
$courseid = $restore_controller->get_courseid();
- $coursectx= get_context_instance(CONTEXT_COURSE, $courseid);
+ $coursectx= context_course::instance($courseid);
$userid = $restore_controller->get_userid();
// Note: all the checks along the function MUST be performed for $userid, that
@@ -39,7 +39,7 @@ public static function get_blockids_from_moduleid($moduleid) {
global $DB;
// Get the context of the module
- $contextid = get_context_instance(CONTEXT_MODULE, $moduleid)->id;
+ $contextid = context_module::instance($moduleid)->id;
// Get all the block instances which parentcontextid is the module contextid
$blockids = array();
@@ -57,7 +57,7 @@ public static function get_blockids_from_courseid($courseid) {
global $DB;
// Get the context of the course
- $contextid = get_context_instance(CONTEXT_COURSE, $courseid)->id;
+ $contextid = context_course::instance($courseid)->id;
// Get all the block instances which parentcontextid is the course contextid
$blockids = array();
@@ -214,7 +214,7 @@ public static function get_default_backup_filename($format, $type, $id, $users,
switch ($type) {
case backup::TYPE_1COURSE:
$shortname = $DB->get_field('course', 'shortname', array('id' => $id));
- $context = get_context_instance(CONTEXT_COURSE, $id);
+ $context = context_course::instance($id);
$shortname = format_string($shortname, true, array('context' => $context));
break;
case backup::TYPE_1SECTION:
Oops, something went wrong.

0 comments on commit a689cd1

Please sign in to comment.