Skip to content

Commit

Permalink
MDL-34460 Librairies: Replaced deprecated get_context_instance()
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Jul 26, 2012
1 parent 42b60b2 commit 4373103
Show file tree
Hide file tree
Showing 48 changed files with 106 additions and 106 deletions.
2 changes: 1 addition & 1 deletion rss/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

foreach ($modinfo->instances[$componentname] as $modinstanceid=>$cm) {
if ($modinstanceid==$instanceid) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = context_module::instance($cm->id, IGNORE_MISSING);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tag/coursetags_add.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

require_login();

$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$systemcontext = context_system::instance();
require_capability('moodle/tag:create', $systemcontext);

if (empty($CFG->usetags)) {
Expand Down
4 changes: 2 additions & 2 deletions tag/coursetags_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
}

// Permissions
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
$sitecontext = context_system::instance();
require_login($course);
$canedit = has_capability('moodle/tag:create', $sitecontext);

Expand All @@ -85,7 +85,7 @@
// The title and breadcrumb
$title = get_string('edittitle', $tagslang);
$coursefullname = format_string($course->fullname);
$courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
$PAGE->navbar->add($title);
$PAGE->set_title($title);
$PAGE->set_heading($course->fullname);
Expand Down
6 changes: 3 additions & 3 deletions tag/coursetags_more.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
}

if ($courseid) {
$PAGE->set_context(get_context_instance(CONTEXT_COURSE, $courseid));
$PAGE->set_context(context_course::instance($courseid));
} else {
$PAGE->set_context(get_system_context());
}
Expand All @@ -86,7 +86,7 @@

// The title and breadcrumb
if ($courseid) {
$courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $courseid)));
$courseshortname = format_string($course->shortname, true, array('context' => context_course::instance($courseid)));
$PAGE->navbar->add($courseshortname, new moodle_url('/course/view.php', array('id'=>$courseid)));
}
$PAGE->navbar->add($title);
Expand Down Expand Up @@ -183,7 +183,7 @@
}
}
if ($courseid) {
$fullname = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
$fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
if ($show == 'course') {
$link1 .= ' | <b>'.get_string('moreshowcoursetags', $tagslang, $fullname).'</b>';
} else {
Expand Down
2 changes: 1 addition & 1 deletion tag/coursetagslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ function coursetag_print_cloud($tagcloud, $return=false, $max_size=180, $min_siz

$step = ($max_size - $min_size)/($spread);

$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$systemcontext = context_system::instance();
$can_manage_tags = has_capability('moodle/tag:manage', $systemcontext);

//prints the tag cloud
Expand Down
2 changes: 1 addition & 1 deletion tag/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}

//Editing a tag requires moodle/tag:edit capability
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$systemcontext = context_system::instance();
require_capability('moodle/tag:edit', $systemcontext);

if ($tag_name) {
Expand Down
2 changes: 1 addition & 1 deletion tag/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function definition () {
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);

$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$systemcontext = context_system::instance();

if (has_capability('moodle/tag:manage', $systemcontext)) {
$mform->addElement('text', 'rawname', get_string('name', 'tag'),
Expand Down
2 changes: 1 addition & 1 deletion tag/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
$userpage = optional_param('userpage', 0, PARAM_INT); // which page to show
$perpage = optional_param('perpage', 24, PARAM_INT);

$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$systemcontext = context_system::instance();

if ($tagname) {
$tag = tag_get('name', $tagname, '*');
Expand Down
2 changes: 1 addition & 1 deletion tag/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ function tag_delete($tagids) {
}

$success = true;
$context = get_context_instance(CONTEXT_SYSTEM);
$context = context_system::instance();
foreach ($tagids as $tagid) {
if (is_null($tagid)) { // can happen if tag doesn't exists
continue;
Expand Down
8 changes: 4 additions & 4 deletions tag/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
function tag_print_cloud($nr_of_tags=150, $return=false) {
global $CFG, $DB;

$can_manage_tags = has_capability('moodle/tag:manage', get_context_instance(CONTEXT_SYSTEM));
$can_manage_tags = has_capability('moodle/tag:manage', context_system::instance());

if ( !$tagsincloud = $DB->get_records_sql('SELECT tg.rawname, tg.id, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag
FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid
Expand Down Expand Up @@ -146,7 +146,7 @@ function tag_print_description_box($tag_object, $return=false) {
$options = new stdClass();
$options->para = false;
$options->overflowdiv = true;
$tag_object->description = file_rewrite_pluginfile_urls($tag_object->description, 'pluginfile.php', get_context_instance(CONTEXT_SYSTEM)->id, 'tag', 'description', $tag_object->id);
$tag_object->description = file_rewrite_pluginfile_urls($tag_object->description, 'pluginfile.php', context_system::instance()->id, 'tag', 'description', $tag_object->id);
$output .= format_text($tag_object->description, $tag_object->descriptionformat, $options);
}

Expand Down Expand Up @@ -190,7 +190,7 @@ function tag_print_management_box($tag_object, $return=false) {

if (!isguestuser()) {
$output .= $OUTPUT->box_start('box','tag-management-box');
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$systemcontext = context_system::instance();
$links = array();

// Add a link for users to add/remove this from their interests
Expand Down Expand Up @@ -356,7 +356,7 @@ function tag_print_tagged_users_table($tag_object, $limitfrom='', $limitnum='',
function tag_print_user_box($user, $return=false) {
global $CFG, $OUTPUT;

$usercontext = get_context_instance(CONTEXT_USER, $user->id);
$usercontext = context_user::instance($user->id);
$profilelink = '';

if ($usercontext and (has_capability('moodle/user:viewdetails', $usercontext) || has_coursecontact_role($user->id))) {
Expand Down
4 changes: 2 additions & 2 deletions tag/manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
print_error('tagsaredisabled', 'tag');
}

$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$systemcontext = context_system::instance();
require_capability('moodle/tag:manage', $systemcontext);

$params = array();
Expand Down Expand Up @@ -151,7 +151,7 @@
// tag exists, change the type
tag_type_set($new_otag_id, 'official');
} else {
require_capability('moodle/tag:create', get_context_instance(CONTEXT_SYSTEM));
require_capability('moodle/tag:create', context_system::instance());
tag_add($new_otag, 'official');
}
$notice .= get_string('addedotag', 'tag', $new_otag) .' ';
Expand Down
4 changes: 2 additions & 2 deletions tag/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
$params['perpage'] = $perpage;
}
$PAGE->set_url(new moodle_url('/tag/search.php', $params));
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('standard');

$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$systemcontext = context_system::instance();
$manage_link = '&nbsp;';

$PAGE->set_title(get_string('tags', 'tag'));
Expand Down
10 changes: 5 additions & 5 deletions theme/mymobile/renderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class theme_mymobile_renderer extends plugin_renderer_base {
*/
public function settings_tree(settings_navigation $navigation) {
$content = $this->navigation_node($navigation, array('class' => 'settings'));
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
if (has_capability('moodle/site:config', context_system::instance())) {
// TODO: Work out whether something is missing from here.
}
return $content;
Expand Down Expand Up @@ -326,7 +326,7 @@ public function login_info() {
// $course->id is not defined during installation
return '';
} else if (isloggedin()) {
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$context = context_course::instance($course->id);
$fullname = fullname($USER, true);

// Since Moodle 2.0 this link always goes to the public profile page (not the course profile page)
Expand Down Expand Up @@ -364,7 +364,7 @@ public function login_info() {
} else {
$loggedinas .= get_string('failedloginattemptsall', '', $count);
}
if (file_exists("$CFG->dirroot/report/log/index.php") and has_capability('report/log:view', get_context_instance(CONTEXT_SYSTEM))) {
if (file_exists("$CFG->dirroot/report/log/index.php") and has_capability('report/log:view', context_system::instance())) {
$loggedinas .= ' (<a href="'.$CFG->wwwroot.'/course/report/log/index.php?chooselog=1&amp;id=1&amp;modid=site_errors">'.get_string('logs').'</a>)';
}
$loggedinas .= '</div>';
Expand Down Expand Up @@ -405,7 +405,7 @@ public function login_info_footer() {
// $course->id is not defined during installation
return '';
} else if (isloggedin()) {
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$context = context_course::instance($course->id);

$fullname = fullname($USER, true);
// Since Moodle 2.0 this link always goes to the public profile page (not the course profile page)
Expand Down Expand Up @@ -447,7 +447,7 @@ public function login_info_footer() {
} else {
$loggedinas .= get_string('failedloginattemptsall', '', $count);
}
if (has_capability('report/log:view', get_context_instance(CONTEXT_SYSTEM))) {
if (has_capability('report/log:view', context_system::instance())) {
$loggedinas .= ' (<a href="'.$CFG->wwwroot.'/course/report/log/index.php?chooselog=1&amp;id=1&amp;modid=site_errors">'.get_string('logs').'</a>)';
}
$loggedinas .= '</div>';
Expand Down
2 changes: 1 addition & 1 deletion user/addnote.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
print_error('invalidcourseid');
}

$context = get_context_instance(CONTEXT_COURSE, $id);
$context = context_course::instance($id);
require_login($course);

// to create notes the current user needs a capability
Expand Down
10 changes: 5 additions & 5 deletions user/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@
}

if ($course->id == SITEID) {
$coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
$coursecontext = context_system::instance(); // SYSTEM context
} else {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
$coursecontext = context_course::instance($course->id); // Course context
}
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$personalcontext = get_context_instance(CONTEXT_USER, $user->id);
$systemcontext = context_system::instance();
$personalcontext = context_user::instance($user->id);

// check access control
if ($user->id == $USER->id) {
Expand Down Expand Up @@ -244,7 +244,7 @@

$a = new stdClass();
$a->url = $CFG->wwwroot . '/user/emailupdate.php?key=' . $usernew->preference_newemailkey . '&id=' . $user->id;
$a->site = format_string($SITE->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
$a->site = format_string($SITE->fullname, true, array('context' => context_course::instance(SITEID)));
$a->fullname = fullname($user, true);

$emailupdatemessage = get_string('emailupdatemessage', 'auth', $a);
Expand Down
4 changes: 2 additions & 2 deletions user/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function definition_after_data() {

// print picture
if (!empty($CFG->gdversion)) {
$context = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST);
$context = context_user::instance($user->id, MUST_EXIST);
$fs = get_file_storage();
$hasuploadedpicture = ($fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg'));
if (!empty($user->picture) && $hasuploadedpicture) {
Expand Down Expand Up @@ -147,7 +147,7 @@ function validation($usernew, $files) {
$errors['email'] = get_string('toomanybounces');
}

if (isset($usernew->email) and !empty($CFG->verifychangedemail) and !isset($errors['email']) and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {
if (isset($usernew->email) and !empty($CFG->verifychangedemail) and !isset($errors['email']) and !has_capability('moodle/user:update', context_system::instance())) {
$errorstr = email_is_not_allowed($usernew->email);
if ($errorstr !== false) {
$errors['email'] = $errorstr;
Expand Down
12 changes: 6 additions & 6 deletions user/editadvanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
}

if ($course->id == SITEID) {
$coursecontext = get_context_instance(CONTEXT_SYSTEM); // SYSTEM context
$coursecontext = context_system::instance(); // SYSTEM context
} else {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id); // Course context
$coursecontext = context_course::instance($course->id); // Course context
}
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$systemcontext = context_system::instance();

if ($id == -1) {
// creating new user
Expand All @@ -68,7 +68,7 @@
// editing existing user
require_capability('moodle/user:update', $systemcontext);
$user = $DB->get_record('user', array('id'=>$id), '*', MUST_EXIST);
$PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id));
$PAGE->set_context(context_user::instance($user->id));
if ($user->id == $USER->id) {
if ($course->id != SITEID && $node = $PAGE->navigation->find($course->id, navigation_node::TYPE_COURSE)) {
$node->make_active();
Expand Down Expand Up @@ -112,7 +112,7 @@
}

if ($user->id !== -1) {
$usercontext = get_context_instance(CONTEXT_USER, $user->id);
$usercontext = context_user::instance($user->id);
$editoroptions = array(
'maxfiles' => EDITOR_UNLIMITED_FILES,
'maxbytes' => $CFG->maxbytes,
Expand Down Expand Up @@ -203,7 +203,7 @@
$usercreated = false;
}

$usercontext = get_context_instance(CONTEXT_USER, $usernew->id);
$usercontext = context_user::instance($usernew->id);

//update preferences
useredit_update_user_preference($usernew);
Expand Down
2 changes: 1 addition & 1 deletion user/editadvanced_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function definition_after_data() {
// print picture
if (!empty($CFG->gdversion) and empty($USER->newadminuser)) {
if ($user) {
$context = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST);
$context = context_user::instance($user->id, MUST_EXIST);
$fs = get_file_storage();
$hasuploadedpicture = ($fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg'));
if (!empty($user->picture) && $hasuploadedpicture) {
Expand Down
2 changes: 1 addition & 1 deletion user/editlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function useredit_update_picture(stdClass $usernew, moodleform $userform, $filem
global $CFG, $DB;
require_once("$CFG->libdir/gdlib.php");

$context = get_context_instance(CONTEXT_USER, $usernew->id, MUST_EXIST);
$context = context_user::instance($usernew->id, MUST_EXIST);
$user = $DB->get_record('user', array('id'=>$usernew->id), 'id, picture', MUST_EXIST);

$newpicture = $user->picture;
Expand Down
2 changes: 1 addition & 1 deletion user/emailupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
$id = required_param('id', PARAM_INT);

$PAGE->set_url('/user/emailupdate.php', array('id'=>$id, 'key'=>$key));
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->set_context(context_system::instance());

if (!$user = $DB->get_record('user', array('id' => $id))) {
print_error('invaliduserid');
Expand Down
10 changes: 5 additions & 5 deletions user/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function create_users($users) {
require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function

// Ensure the current user is allowed to run this function
$context = get_context_instance(CONTEXT_SYSTEM);
$context = context_system::instance();
self::validate_context($context);
require_capability('moodle/user:create', $context);

Expand Down Expand Up @@ -226,7 +226,7 @@ public static function delete_users($userids) {
require_once($CFG->dirroot."/user/lib.php");

// Ensure the current user is allowed to run this function
$context = get_context_instance(CONTEXT_SYSTEM);
$context = context_system::instance();
require_capability('moodle/user:delete', $context);
self::validate_context($context);

Expand Down Expand Up @@ -324,7 +324,7 @@ public static function update_users($users) {
require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function

// Ensure the current user is allowed to run this function
$context = get_context_instance(CONTEXT_SYSTEM);
$context = context_system::instance();
require_capability('moodle/user:update', $context);
self::validate_context($context);

Expand Down Expand Up @@ -413,7 +413,7 @@ public static function get_users_by_id($userids) {
continue;
}
context_instance_preload($user);
$usercontext = get_context_instance(CONTEXT_USER, $user->id);
$usercontext = context_user::instance($user->id, IGNORE_MISSING);
self::validate_context($usercontext);
$currentuser = ($user->id == $USER->id);

Expand Down Expand Up @@ -576,7 +576,7 @@ public static function get_course_user_profiles($userlist) {
}
context_instance_preload($user);
$course = $courses[$courseids[$user->id]];
$context = get_context_instance(CONTEXT_COURSE, $courseids[$user->id]);
$context = context_course::instance($courseids[$user->id], IGNORE_MISSING);
self::validate_context($context);
if ($userarray = user_get_user_details($user, $course)) {
$result[] = $userarray;
Expand Down
2 changes: 1 addition & 1 deletion user/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
$returnurl = new moodle_url('/user/files.php');
}

$context = get_context_instance(CONTEXT_USER, $USER->id);
$context = context_user::instance($USER->id);
require_capability('moodle/user:manageownfiles', $context);

$title = get_string('myfiles');
Expand Down
Loading

0 comments on commit 4373103

Please sign in to comment.