MDL-40403 libraries: Deprecate get_parent_contexts()
authorFrederic Massart <fred@moodle.com>
Thu, 4 Jul 2013 03:07:12 +0000 (11:07 +0800)
committerFrederic Massart <fred@moodle.com>
Tue, 9 Jul 2013 05:34:44 +0000 (13:34 +0800)
12 files changed:
backup/util/dbops/restore_dbops.class.php
enrol/category/locallib.php
enrol/cohort/lib.php
enrol/cohort/locallib.php
enrol/locallib.php
lib/accesslib.php
lib/blocklib.php
lib/deprecatedlib.php
lib/externallib.php
lib/gradelib.php
lib/tests/accesslib_test.php
lib/upgrade.txt

index 5146cfe..7feafe8 100644 (file)
@@ -741,7 +741,7 @@ abstract class restore_dbops {
                  // Build the array of contexts we are going to look
                  $systemctx = context_system::instance();
                  $coursectx = context_course::instance($courseid);
-                 $parentctxs= get_parent_contexts($coursectx);
+                 $parentctxs = $coursectx->get_parent_context_ids();
                  foreach ($parentctxs as $parentctx) {
                      // Exclude system context
                      if ($parentctx == $systemctx->id) {
index 4ca66c8..4240276 100644 (file)
@@ -129,7 +129,7 @@ class enrol_category_handler {
 
         foreach ($rs as $instance) {
             $coursecontext = context_course::instance($instance->courseid);
-            $contextids = get_parent_contexts($coursecontext);
+            $contextids = $coursecontext->get_parent_context_ids();
             array_pop($contextids); // Remove system context, we are interested in categories only.
 
             list($contextids, $contextparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED, 'c');
@@ -178,7 +178,7 @@ function enrol_category_sync_course($course) {
 
     // First find out if any parent category context contains interesting role assignments.
     $coursecontext = context_course::instance($course->id);
-    $contextids = get_parent_contexts($coursecontext);
+    $contextids = $coursecontext->get_parent_context_ids();
     array_pop($contextids); // Remove system context, we are interested in categories only.
 
     list($roleids, $params) = $DB->get_in_or_equal(array_keys($roles), SQL_PARAMS_NAMED, 'r');
index eeed03a..6ab0402 100644 (file)
@@ -86,7 +86,7 @@ class enrol_cohort_plugin extends enrol_plugin {
         if (!has_capability('moodle/course:enrolconfig', $coursecontext) or !has_capability('enrol/cohort:config', $coursecontext)) {
             return false;
         }
-        list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($coursecontext));
+        list($sqlparents, $params) = $DB->get_in_or_equal($coursecontext->get_parent_context_ids());
         $sql = "SELECT id, contextid
                   FROM {cohort}
                  WHERE contextid $sqlparents
index 606b829..377584e 100644 (file)
@@ -394,7 +394,7 @@ function enrol_cohort_get_cohorts(course_enrolment_manager $manager) {
             $enrolled[] = $instance->customint1;
         }
     }
-    list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($context));
+    list($sqlparents, $params) = $DB->get_in_or_equal($context->get_parent_context_ids());
     $sql = "SELECT id, name, idnumber, contextid
               FROM {cohort}
              WHERE contextid $sqlparents
index a2039da..da06cc6 100644 (file)
@@ -176,7 +176,7 @@ class course_enrolment_manager {
     public function get_total_other_users() {
         global $DB;
         if ($this->totalotherusers === null) {
-            list($ctxcondition, $params) = $DB->get_in_or_equal(get_parent_contexts($this->context, true), SQL_PARAMS_NAMED, 'ctx');
+            list($ctxcondition, $params) = $DB->get_in_or_equal($this->context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'ctx');
             $params['courseid'] = $this->course->id;
             $sql = "SELECT COUNT(DISTINCT u.id)
                       FROM {role_assignments} ra
@@ -293,7 +293,7 @@ class course_enrolment_manager {
         }
         $key = md5("$sort-$direction-$page-$perpage");
         if (!array_key_exists($key, $this->otherusers)) {
-            list($ctxcondition, $params) = $DB->get_in_or_equal(get_parent_contexts($this->context, true), SQL_PARAMS_NAMED, 'ctx');
+            list($ctxcondition, $params) = $DB->get_in_or_equal($this->context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'ctx');
             $params['courseid'] = $this->course->id;
             $params['cid'] = $this->course->id;
             $sql = "SELECT ra.id as raid, ra.contextid, ra.component, ctx.contextlevel, ra.roleid, u.*, ue.lastseen
index 368cd82..ad09d5b 100644 (file)
@@ -7225,20 +7225,6 @@ class context_block extends context {
 // before removing devs will be warned with a debugging message first,
 // then we will add error message and only after that we can remove the functions
 // completely.
-/**
- * Recursive function which, given a context, find all parent context ids,
- * and return the array in reverse order, i.e. parent first, then grand
- * parent, etc.
- *
- * @deprecated since 2.2, use $context->get_parent_context_ids() instead
- * @param context $context
- * @param bool $includeself optional, defaults to false
- * @return array
- */
-function get_parent_contexts(context $context, $includeself = false) {
-    return $context->get_parent_context_ids($includeself);
-}
-
 /**
  * Return the id of the parent of this context, or false if there is no parent (only happens if this
  * is the site context.)
index 02e3c8d..346985c 100644 (file)
@@ -566,7 +566,7 @@ class block_manager {
         $context = $this->page->context;
         $contexttest = 'bi.parentcontextid = :contextid2';
         $parentcontextparams = array();
-        $parentcontextids = get_parent_contexts($context);
+        $parentcontextids = $context->get_parent_context_ids();
         if ($parentcontextids) {
             list($parentcontexttest, $parentcontextparams) =
                     $DB->get_in_or_equal($parentcontextids, SQL_PARAMS_NAMED, 'parentcontext');
index 064725d..1d27c8c 100644 (file)
@@ -4928,3 +4928,19 @@ function get_system_context($cache = true) {
     debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
     return context_system::instance(0, IGNORE_MISSING, $cache);
 }
+
+/**
+ * Recursive function which, given a context, find all parent context ids,
+ * and return the array in reverse order, i.e. parent first, then grand
+ * parent, etc.
+ *
+ * @see context::get_parent_context_ids()
+ * @deprecated since 2.2, use $context->get_parent_context_ids() instead
+ * @param context $context
+ * @param bool $includeself optional, defaults to false
+ * @return array
+ */
+function get_parent_contexts(context $context, $includeself = false) {
+    debugging('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.', DEBUG_DEVELOPER);
+    return $context->get_parent_context_ids($includeself);
+}
index 9b92c5e..e6d868f 100644 (file)
@@ -345,7 +345,7 @@ class external_api {
         } else if ($rcontext->contextlevel > $context->contextlevel) {
             throw new restricted_context_exception();
         } else {
-            $parents = get_parent_contexts($context);
+            $parents = $context->get_parent_context_ids();
             if (!in_array($rcontext->id, $parents)) {
                 throw new restricted_context_exception();
             }
index 3ae134f..e95a2af 100644 (file)
@@ -839,7 +839,7 @@ function grade_get_letters($context=null) {
 
     $letters = array();
 
-    $contexts = get_parent_contexts($context);
+    $contexts = $context->get_parent_context_ids();
     array_unshift($contexts, $context->id);
 
     foreach ($contexts as $ctxid) {
index fa6dfc2..a86e040 100644 (file)
@@ -2374,6 +2374,8 @@ class accesslib_testcase extends advanced_testcase {
         $this->assertDebuggingCalled('get_context_instance_by_id() is deprecated, please use context::instance_by_id($id) instead.', DEBUG_DEVELOPER);
         get_system_context();
         $this->assertDebuggingCalled('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
+        get_parent_contexts($context);
+        $this->assertDebuggingCalled('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.', DEBUG_DEVELOPER);
 
         $DB->delete_records('context', array('contextlevel'=>CONTEXT_BLOCK));
         create_contexts();
index 919cb45..506bb20 100644 (file)
@@ -2,12 +2,14 @@ This files describes API changes in core libraries and APIs,
 information provided here is intended especially for developers.
 
 === 2.6 ===
+
 * Use new core_component::* plugin listing and component normalisation methods.
 * Use core_text::* instead of textlib:: and also core_collator::* instead of collatorlib::*.
 * get_context_instance() is deprecated, please use use context_xxxx::instance().
 * get_context_instance_by_id() is deprecated, please use context::instance_by_id($id).
 * load_temp_role() and remove_temp_roles() can not be used any more.
 * get_system_context() is deprecated, please use context_system::instance().
+* get_parent_contexts() is deprecated, please use $context->get_parent_context_ids().
 
 === 2.5.1 ===