diff --git a/comment/lib.php b/comment/lib.php index c158c97800c..ef1e619cd80 100644 --- a/comment/lib.php +++ b/comment/lib.php @@ -685,7 +685,7 @@ class comment { global $DB; $contexts = array(); $contexts[] = $context->id; - $children = get_child_contexts($context); + $children = $context->get_child_contexts(); foreach ($children as $c) { $contexts[] = $c->id; } diff --git a/lib/accesslib.php b/lib/accesslib.php index 66975330a94..221f1b336c1 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -7230,27 +7230,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 its children context ids. - * - * For course category contexts it will return immediate children only categories and courses. - * It will NOT recurse into courses or child categories. - * If you want to do that, call it on the returned courses/categories. - * - * When called for a course context, it will return the modules and blocks - * displayed in the course page. - * - * If called on a user/course/module context it _will_ populate the cache with the appropriate - * contexts ;-) - * - * @deprecated since 2.2, use $context->get_child_contexts() instead - * @param context $context - * @return array Array of child records - */ -function get_child_contexts(context $context) { - return $context->get_child_contexts(); -} - /** * Precreates all contexts including all parents * diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index c4d3191b342..5555d400840 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -4963,3 +4963,26 @@ function get_parent_contextid(context $context) { return false; } } + +/** + * Recursive function which, given a context, find all its children contexts. + * + * For course category contexts it will return immediate children only categories and courses. + * It will NOT recurse into courses or child categories. + * If you want to do that, call it on the returned courses/categories. + * + * When called for a course context, it will return the modules and blocks + * displayed in the course page. + * + * If called on a user/course/module context it _will_ populate the cache with the appropriate + * contexts ;-) + * + * @see context::get_child_contexts() + * @deprecated since 2.2 + * @param context $context + * @return array Array of child records + */ +function get_child_contexts(context $context) { + debugging('get_child_contexts() is deprecated, please use $context->get_child_contexts() instead.', DEBUG_DEVELOPER); + return $context->get_child_contexts(); +} diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 0767ee63f23..593c964f296 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -5230,7 +5230,7 @@ function reset_course_userdata($data) { $componentstr = get_string('roles'); if (!empty($data->reset_roles_overrides)) { - $children = get_child_contexts($context); + $children = $context->get_child_contexts(); foreach ($children as $child) { $DB->delete_records('role_capabilities', array('contextid'=>$child->id)); } @@ -5241,7 +5241,7 @@ function reset_course_userdata($data) { } if (!empty($data->reset_roles_local)) { - $children = get_child_contexts($context); + $children = $context->get_child_contexts(); foreach ($children as $child) { role_unassign_all(array('contextid'=>$child->id)); } diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index cd4d8f5590e..261e2a1a082 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -2363,8 +2363,10 @@ class accesslib_testcase extends advanced_testcase { } $children = get_child_contexts($systemcontext); - $this->resetDebugging(); + // Using assertEquals here as assertSame fails for some reason... + $this->assertEquals($children, $systemcontext->get_child_contexts()); $this->assertEquals(count($children), $DB->count_records('context')-1); + $this->resetDebugging(); unset($children); // Make sure a debugging is thrown. @@ -2378,6 +2380,8 @@ class accesslib_testcase extends advanced_testcase { $this->assertDebuggingCalled('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.', DEBUG_DEVELOPER); get_parent_contextid($context); $this->assertDebuggingCalled('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER); + get_child_contexts($frontpagecontext); + $this->assertDebuggingCalled('get_child_contexts() is deprecated, please use $context->get_child_contexts() instead.', DEBUG_DEVELOPER); $DB->delete_records('context', array('contextlevel'=>CONTEXT_BLOCK)); create_contexts(); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index d4f755cfab3..d3040b533bc 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -11,6 +11,7 @@ information provided here is intended especially for developers. * get_system_context() is deprecated, please use context_system::instance(). * get_parent_contexts() is deprecated, please use $context->get_parent_context_ids(). * get_parent_contextid() is deprecated, please use $context->get_parent_context(). +* get_child_contexts() is deprecated, please use $context->get_child_contexts(). * Use new function moodleform::mock_submit() to simulate form submission in unit tests (backported). === 2.5.1 ===