Skip to content
Permalink
Browse files

MDL-34472 libraries: add deprecated warning to get_context_instance()

  • Loading branch information...
ankitagarwal committed Jul 1, 2013
1 parent f0d37f4 commit 61a0299a9464f8a3043beb174227a45ac6e28839
Showing with 35 additions and 30 deletions.
  1. +0 −30 lib/accesslib.php
  2. +34 −0 lib/deprecatedlib.php
  3. +1 −0 lib/upgrade.txt
@@ -7265,36 +7265,6 @@ function get_system_context($cache = true) {
return context_system::instance(0, IGNORE_MISSING, $cache);
}
/**
* Get the context instance as an object. This function will create the
* context instance if it does not exist yet.
*
* @deprecated since 2.2, use context_course::instance() or other relevant class instead
* @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
* @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
* for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
* @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
* MUST_EXIST means throw exception if no record or multiple records found
* @return context The context object.
*/
function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
$instances = (array)$instance;
$contexts = array();
$classname = context_helper::get_class_for_level($contextlevel);
// we do not load multiple contexts any more, PAGE should be responsible for any preloading
foreach ($instances as $inst) {
$contexts[$inst] = $classname::instance($inst, $strictness);
}
if (is_array($instance)) {
return $contexts;
} else {
return $contexts[$instance];
}
}
/**
* Get a context instance as an object, from a given context id.
*
@@ -4849,3 +4849,37 @@ function can_use_rotated_text() {
debugging('can_use_rotated_text() is deprecated since Moodle 2.5. JS feature detection is used automatically.', DEBUG_DEVELOPER);
return true;
}
/**
* Get the context instance as an object. This function will create the
* context instance if it does not exist yet.
*
* @deprecated since 2.2, use context_course::instance() or other relevant class instead
* @todo This will be deleted in Moodle 2.8, refer MDL-34472
* @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
* @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
* for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
* @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
* MUST_EXIST means throw exception if no record or multiple records found
* @return context The context object.
*/
function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
debugging('get_context_instance() is deprecated, please use respective context_xxxx::instance().', DEBUG_DEVELOPER);
$instances = (array)$instance;
$contexts = array();
$classname = context_helper::get_class_for_level($contextlevel);
// we do not load multiple contexts any more, PAGE should be responsible for any preloading
foreach ($instances as $inst) {
$contexts[$inst] = $classname::instance($inst, $strictness);
}
if (is_array($instance)) {
return $contexts;
} else {
return $contexts[$instance];
}
}
@@ -3,6 +3,7 @@ information provided here is intended especially for developers.

=== 2.6 ===
* Use new core_component::* plugin listing and component normalisation methods.
* get_context_instance() now throws deprecated warning.


=== 2.5.1 ===

0 comments on commit 61a0299

Please sign in to comment.
You can’t perform that action at this time.