From 8e8891b76b4a53d28d82a0d3d5cbb284e828f552 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Thu, 4 Jul 2013 11:07:12 +0800 Subject: [PATCH] MDL-40403 libraries: Deprecate get_parent_contexts() --- backup/util/dbops/restore_dbops.class.php | 2 +- enrol/category/locallib.php | 4 ++-- enrol/cohort/lib.php | 2 +- enrol/cohort/locallib.php | 2 +- enrol/locallib.php | 4 ++-- lib/accesslib.php | 14 -------------- lib/blocklib.php | 2 +- lib/deprecatedlib.php | 16 ++++++++++++++++ lib/externallib.php | 2 +- lib/gradelib.php | 2 +- lib/tests/accesslib_test.php | 2 ++ lib/upgrade.txt | 2 ++ 12 files changed, 30 insertions(+), 24 deletions(-) diff --git a/backup/util/dbops/restore_dbops.class.php b/backup/util/dbops/restore_dbops.class.php index 5146cfe73d9..7feafe8cf61 100644 --- a/backup/util/dbops/restore_dbops.class.php +++ b/backup/util/dbops/restore_dbops.class.php @@ -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) { diff --git a/enrol/category/locallib.php b/enrol/category/locallib.php index 4ca66c84ce5..4240276c8de 100644 --- a/enrol/category/locallib.php +++ b/enrol/category/locallib.php @@ -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'); diff --git a/enrol/cohort/lib.php b/enrol/cohort/lib.php index eeed03a2ae1..6ab0402bcc5 100644 --- a/enrol/cohort/lib.php +++ b/enrol/cohort/lib.php @@ -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 diff --git a/enrol/cohort/locallib.php b/enrol/cohort/locallib.php index 606b8290e17..377584e49a9 100644 --- a/enrol/cohort/locallib.php +++ b/enrol/cohort/locallib.php @@ -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 diff --git a/enrol/locallib.php b/enrol/locallib.php index a2039da679e..da06cc67b25 100644 --- a/enrol/locallib.php +++ b/enrol/locallib.php @@ -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 diff --git a/lib/accesslib.php b/lib/accesslib.php index 368cd824b3c..ad09d5b4171 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -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.) diff --git a/lib/blocklib.php b/lib/blocklib.php index 02e3c8dc3ff..346985c5f29 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -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'); diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 064725d2eda..1d27c8c4a49 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -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); +} diff --git a/lib/externallib.php b/lib/externallib.php index 9b92c5ec660..e6d868fc031 100644 --- a/lib/externallib.php +++ b/lib/externallib.php @@ -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(); } diff --git a/lib/gradelib.php b/lib/gradelib.php index 3ae134f4e8d..e95a2af3db4 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -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) { diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index fa6dfc277f4..a86e0408fe7 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -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(); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 919cb45caa5..506bb20b41a 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -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 ===