Skip to content

Commit

Permalink
MDL-34471 libraries: Replace all uses of get_context_instance() with …
Browse files Browse the repository at this point in the history
…respective context_XXXX::instance() method
  • Loading branch information
ankitagarwal committed Aug 2, 2012
1 parent 470d47f commit bf0f06b
Show file tree
Hide file tree
Showing 56 changed files with 189 additions and 189 deletions.
2 changes: 1 addition & 1 deletion auth/fc/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function sync_roles($user) {

if ($roles = get_archetype_roles('coursecreator')) {
$creatorrole = array_shift($roles); // We can only use one, let's use the first one
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$systemcontext = context_system::instance();

if ($iscreator) { // Following calls will not create duplicates
role_assign($creatorrole->id, $user->id, $systemcontext->id, 'auth_fc');
Expand Down
6 changes: 3 additions & 3 deletions auth/ldap/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ function sync_users($do_updates=true) {
if (!empty($users)) {
print_string('userentriestoupdate', 'auth_ldap', count($users));

$sitecontext = get_context_instance(CONTEXT_SYSTEM);
$sitecontext = context_system::instance();
if (!empty($this->config->creators) and !empty($this->config->memberattribute)
and $roles = get_archetype_roles('coursecreator')) {
$creatorrole = array_shift($roles); // We can only use one, let's use the first one
Expand Down Expand Up @@ -820,7 +820,7 @@ function sync_users($do_updates=true) {
if (!empty($add_users)) {
print_string('userentriestoadd', 'auth_ldap', count($add_users));

$sitecontext = get_context_instance(CONTEXT_SYSTEM);
$sitecontext = context_system::instance();
if (!empty($this->config->creators) and !empty($this->config->memberattribute)
and $roles = get_archetype_roles('coursecreator')) {
$creatorrole = array_shift($roles); // We can only use one, let's use the first one
Expand Down Expand Up @@ -1649,7 +1649,7 @@ function sync_roles($user) {

if ($roles = get_archetype_roles('coursecreator')) {
$creatorrole = array_shift($roles); // We can only use one, let's use the first one
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$systemcontext = context_system::instance();

if ($iscreator) { // Following calls will not create duplicates
role_assign($creatorrole->id, $user->id, $systemcontext->id, $this->roleauth);
Expand Down
2 changes: 1 addition & 1 deletion auth/ldap/ntlmsso_attempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$PAGE->https_required();

$PAGE->set_url('/auth/ldap/ntlmsso_attempt.php');
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->set_context(context_system::instance());

// Define variables used in page
$site = get_site();
Expand Down
2 changes: 1 addition & 1 deletion auth/ldap/ntlmsso_finish.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$PAGE->https_required();

$PAGE->set_url('/auth/ldap/ntlmsso_finish.php');
$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->set_context(context_system::instance());

// Define variables used in page
$site = get_site();
Expand Down
2 changes: 1 addition & 1 deletion auth/ldap/ntlmsso_magic.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//HTTPS is required in this page when $CFG->loginhttps enabled
$PAGE->https_required();

$PAGE->set_context(get_context_instance(CONTEXT_SYSTEM));
$PAGE->set_context(context_system::instance());

$authsequence = get_enabled_auth_plugins(true); // auths, in sequence
if (!in_array('ldap', $authsequence, true)) {
Expand Down
6 changes: 3 additions & 3 deletions auth/mnet/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function user_authorise($token, $useragent) {

if (array_key_exists('picture', $userdata) && !empty($user->picture)) {
$fs = get_file_storage();
$usercontext = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST);
$usercontext = context_user::instance($user->id, MUST_EXIST);
if ($usericonfile = $fs->get_file($usercontext->id, 'user', 'icon', 0, '/', 'f1.png')) {
$userdata['_mnet_userpicture_timemodified'] = $usericonfile->get_timemodified();
$userdata['_mnet_userpicture_mimetype'] = $usericonfile->get_mimetype();
Expand Down Expand Up @@ -299,7 +299,7 @@ function confirm_mnet_session($token, $remotepeer) {

if ($key == '_mnet_userpicture_timemodified' and empty($CFG->disableuserimages) and isset($remoteuser->picture)) {
// update the user picture if there is a newer verion at the identity provider
$usercontext = get_context_instance(CONTEXT_USER, $localuser->id, MUST_EXIST);
$usercontext = context_user::instance($localuser->id, MUST_EXIST);
if ($usericonfile = $fs->get_file($usercontext->id, 'user', 'icon', 0, '/', 'f1.png')) {
$localtimemodified = $usericonfile->get_timemodified();
} else if ($usericonfile = $fs->get_file($usercontext->id, 'user', 'icon', 0, '/', 'f1.jpg')) {
Expand Down Expand Up @@ -1136,7 +1136,7 @@ function fetch_user_image($username) {

if ($user = $DB->get_record('user', array('username' => $username, 'mnethostid' => $CFG->mnet_localhost_id))) {
$fs = get_file_storage();
$usercontext = get_context_instance(CONTEXT_USER, $user->id, MUST_EXIST);
$usercontext = context_user::instance($user->id, MUST_EXIST);
$return = array();
if ($f1 = $fs->get_file($usercontext->id, 'user', 'icon', 0, '/', 'f1.png')) {
$return['f1'] = base64_encode($f1->get_content());
Expand Down
2 changes: 1 addition & 1 deletion auth/shibboleth/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
}

/// Go to my-moodle page instead of homepage if defaulthomepage enabled
if (!has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM)) and !empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_MY and !isguestuser()) {
if (!has_capability('moodle/site:config',context_system::instance()) and !empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_MY and !isguestuser()) {
if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
$urltogo = $CFG->wwwroot.'/my/';
}
Expand Down
2 changes: 1 addition & 1 deletion comment/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
require_login();
admin_externalpage_setup('comments', '', null, '', array('pagelayout'=>'report'));

$context = get_context_instance(CONTEXT_SYSTEM);
$context = context_system::instance();
require_capability('moodle/comment:delete', $context);

$PAGE->requires->js_init_call('M.core_comment.init_admin', null, true);
Expand Down
4 changes: 2 additions & 2 deletions completion/criteria/completion_criteria_course.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function get_title_detailed() {
global $DB;

$prereq = $DB->get_record('course', array('id' => $this->courseinstance));
$coursecontext = get_context_instance(CONTEXT_COURSE, $prereq->id, MUST_EXIST);
$coursecontext = context_course::instance($prereq->id, MUST_EXIST);
$fullname = format_string($prereq->fullname, true, array('context' => $coursecontext));
return shorten_text(urldecode($fullname));
}
Expand Down Expand Up @@ -215,7 +215,7 @@ public function get_details($completion) {
$info = new completion_info($course);

$prereq = $DB->get_record('course', array('id' => $this->courseinstance));
$coursecontext = get_context_instance(CONTEXT_COURSE, $prereq->id, MUST_EXIST);
$coursecontext = context_course::instance($prereq->id, MUST_EXIST);
$fullname = format_string($prereq->fullname, true, array('context' => $coursecontext));

$prereq_info = new completion_info($prereq);
Expand Down
2 changes: 1 addition & 1 deletion file.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
}
}

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

$fs = get_file_storage();

Expand Down
2 changes: 1 addition & 1 deletion group/assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
$courseid = $course->id;

require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $courseid);
$context = context_course::instance($courseid);
require_capability('moodle/course:managegroups', $context);

$returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$courseid;
Expand Down
4 changes: 2 additions & 2 deletions group/autogroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
// Make sure that the user has permissions to manage groups.
require_login($course);

$context = get_context_instance(CONTEXT_COURSE, $courseid);
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$context = context_course::instance($courseid);
$systemcontext = context_system::instance();
require_capability('moodle/course:managegroups', $context);

$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id;
Expand Down
2 changes: 1 addition & 1 deletion group/autogroup_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function definition() {
$mform->setDefault('roleid', $student->id);
}

$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
$context = context_course::instance($COURSE->id);
if (has_capability('moodle/cohort:view', $context)) {
$options = cohort_get_visible_list($COURSE);
if ($options) {
Expand Down
2 changes: 1 addition & 1 deletion group/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
print_error('invalidcourseid');
}
require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$context = context_course::instance($course->id);
require_capability('moodle/course:managegroups', $context);
$changeidnumber = has_capability('moodle/course:changeidnumber', $context);

Expand Down
14 changes: 7 additions & 7 deletions group/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static function create_groups($groups) {
}

// now security checks
$context = get_context_instance(CONTEXT_COURSE, $group->courseid);
$context = context_course::instance($group->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
Expand Down Expand Up @@ -168,7 +168,7 @@ public static function get_groups($groupids) {
$group = groups_get_group($groupid, 'id, courseid, name, description, descriptionformat, enrolmentkey', MUST_EXIST);

// now security checks
$context = get_context_instance(CONTEXT_COURSE, $group->courseid);
$context = context_course::instance($group->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
Expand Down Expand Up @@ -235,7 +235,7 @@ public static function get_course_groups($courseid) {
$params = self::validate_parameters(self::get_course_groups_parameters(), array('courseid'=>$courseid));

// now security checks
$context = get_context_instance(CONTEXT_COURSE, $params['courseid']);
$context = context_course::instance($params['courseid']);
try {
self::validate_context($context);
} catch (Exception $e) {
Expand Down Expand Up @@ -318,7 +318,7 @@ public static function delete_groups($groupids) {
}

// now security checks
$context = get_context_instance(CONTEXT_COURSE, $group->courseid);
$context = context_course::instance($group->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
Expand Down Expand Up @@ -376,7 +376,7 @@ public static function get_group_members($groupids) {
// validate params
$group = groups_get_group($groupid, 'id, courseid, name, enrolmentkey', MUST_EXIST);
// now security checks
$context = get_context_instance(CONTEXT_COURSE, $group->courseid);
$context = context_course::instance($group->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
Expand Down Expand Up @@ -456,7 +456,7 @@ public static function add_group_members($members) {
$user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0, 'mnethostid'=>$CFG->mnet_localhost_id), '*', MUST_EXIST);

// now security checks
$context = get_context_instance(CONTEXT_COURSE, $group->courseid);
$context = context_course::instance($group->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
Expand Down Expand Up @@ -534,7 +534,7 @@ public static function delete_group_members($members) {
$user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0, 'mnethostid'=>$CFG->mnet_localhost_id), '*', MUST_EXIST);

// now security checks
$context = get_context_instance(CONTEXT_COURSE, $group->courseid);
$context = context_course::instance($group->courseid);
try {
self::validate_context($context);
} catch (Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion group/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
}

require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$context = context_course::instance($course->id);
require_capability('moodle/course:managegroups', $context);

$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
Expand Down
2 changes: 1 addition & 1 deletion group/grouping.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
$PAGE->set_url($url);

require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$context = context_course::instance($course->id);
require_capability('moodle/course:managegroups', $context);

$returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$course->id;
Expand Down
2 changes: 1 addition & 1 deletion group/groupings.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}

require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$context = context_course::instance($course->id);
require_capability('moodle/course:managegroups', $context);

$strgrouping = get_string('grouping', 'group');
Expand Down
4 changes: 2 additions & 2 deletions group/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
$PAGE->set_url('/group/import.php', array('id'=>$id));

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

require_capability('moodle/course:managegroups', $context);

Expand Down Expand Up @@ -160,7 +160,7 @@
if (isset($newgroup->courseid)) {
$linenum++;
$groupname = $newgroup->name;
$newgrpcoursecontext = get_context_instance(CONTEXT_COURSE, $newgroup->courseid);
$newgrpcoursecontext = context_course::instance($newgroup->courseid);

///Users cannot upload groups in courses they cannot update.
if (!has_capability('moodle/course:managegroups', $newgrpcoursecontext) or (!is_enrolled($newgrpcoursecontext) and !has_capability('moodle/course:view', $newgrpcoursecontext))) {
Expand Down
2 changes: 1 addition & 1 deletion group/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
$PAGE->requires->yui2_lib('connection');
$PAGE->requires->js('/group/clientlib.js');

$context = get_context_instance(CONTEXT_COURSE, $course->id);
$context = context_course::instance($course->id);
if (!has_capability('moodle/course:managegroups', $context)) {
redirect('/course/view.php', array('id'=>$course->id)); // Not allowed to manage all groups
}
Expand Down
22 changes: 11 additions & 11 deletions group/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function groups_add_member($grouporid, $userorid) {
}

//check if the user a participant of the group course
if (!is_enrolled(get_context_instance(CONTEXT_COURSE, $group->courseid), $userid)) {
if (!is_enrolled(context_course::instance($group->courseid), $userid)) {
return false;
}

Expand Down Expand Up @@ -140,7 +140,7 @@ function groups_create_group($data, $editform = false, $editoroptions = false) {

//check that courseid exists
$course = $DB->get_record('course', array('id' => $data->courseid), '*', MUST_EXIST);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$context = context_course::instance($course->id);

$data->timecreated = time();
$data->timemodified = $data->timecreated;
Expand Down Expand Up @@ -236,7 +236,7 @@ function groups_update_group_icon($group, $data, $editform) {
require_once("$CFG->libdir/gdlib.php");

$fs = get_file_storage();
$context = get_context_instance(CONTEXT_COURSE, $group->courseid, MUST_EXIST);
$context = context_course::instance($group->courseid, MUST_EXIST);

//TODO: it would make sense to allow picture deleting too (skodak)

Expand Down Expand Up @@ -264,7 +264,7 @@ function groups_update_group_icon($group, $data, $editform) {
function groups_update_group($data, $editform = false, $editoroptions = false) {
global $CFG, $DB;

$context = get_context_instance(CONTEXT_COURSE, $data->courseid);
$context = context_course::instance($data->courseid);

$data->timemodified = time();
$data->name = trim($data->name);
Expand Down Expand Up @@ -353,7 +353,7 @@ function groups_delete_group($grouporid) {
$DB->delete_records('groups', array('id'=>$groupid));

// Delete all files associated with this group
$context = get_context_instance(CONTEXT_COURSE, $group->courseid);
$context = context_course::instance($group->courseid);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'group', 'description', $groupid);
$fs->delete_area_files($context->id, 'group', 'icon', $groupid);
Expand Down Expand Up @@ -393,7 +393,7 @@ function groups_delete_grouping($groupingorid) {
//group itself last
$DB->delete_records('groupings', array('id'=>$groupingid));

$context = get_context_instance(CONTEXT_COURSE, $grouping->courseid);
$context = context_course::instance($grouping->courseid);
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'grouping', 'description', $groupingid);
foreach ($files as $file) {
Expand Down Expand Up @@ -484,15 +484,15 @@ function groups_delete_groups($courseid, $showfeedback=false) {
groups_delete_group_members($courseid, 0, $showfeedback);

// delete group pictures and descriptions
$context = get_context_instance(CONTEXT_COURSE, $courseid);
$context = context_course::instance($courseid);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'group');

// delete group calendar events
$groupssql = "SELECT id FROM {groups} g WHERE g.courseid = ?";
$DB->delete_records_select('event', "groupid IN ($groupssql)", array($courseid));

$context = get_context_instance(CONTEXT_COURSE, $courseid);
$context = context_course::instance($courseid);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'group');

Expand Down Expand Up @@ -529,7 +529,7 @@ function groups_delete_groupings($courseid, $showfeedback=false) {
$DB->set_field('course_modules', 'groupingid', 0, array('course'=>$courseid));

// Delete all files associated with groupings for this course
$context = get_context_instance(CONTEXT_COURSE, $courseid);
$context = context_course::instance($courseid);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'grouping');

Expand Down Expand Up @@ -574,7 +574,7 @@ function groups_get_possible_roles($context) {
function groups_get_potential_members($courseid, $roleid = null, $cohortid = null, $orderby = 'lastname ASC, firstname ASC') {
global $DB;

$context = get_context_instance(CONTEXT_COURSE, $courseid);
$context = context_course::instance($courseid);

// we are looking for all users with this role assigned in this context or higher
$listofcontexts = get_related_contexts_string($context);
Expand Down Expand Up @@ -689,7 +689,7 @@ function groups_get_members_by_role($groupid, $courseid, $fields='u.*',

// Retrieve information about all users and their roles on the course or
// parent ('related') contexts
$context = get_context_instance(CONTEXT_COURSE, $courseid);
$context = context_course::instance($courseid);

if ($extrawheretest) {
$extrawheretest = ' AND ' . $extrawheretest;
Expand Down
2 changes: 1 addition & 1 deletion group/members.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
$PAGE->set_pagelayout('standard');

require_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$context = context_course::instance($course->id);
require_capability('moodle/course:managegroups', $context);

$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$group->id;
Expand Down
Loading

0 comments on commit bf0f06b

Please sign in to comment.