Skip to content

Commit

Permalink
MDL-40405 libraries: Deprecate get_child_contexts()
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Jul 9, 2013
1 parent c513812 commit f9aa801
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion comment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ public static function reset_course_page_comments($context) {
global $DB;
$contexts = array();
$contexts[] = $context->id;
$children = get_child_contexts($context);
$children = $context->get_child_contexts();
foreach ($children as $c) {
$contexts[] = $c->id;
}
Expand Down
21 changes: 0 additions & 21 deletions lib/accesslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -7230,27 +7230,6 @@ protected static function build_paths($force) {
// 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
*
Expand Down
23 changes: 23 additions & 0 deletions lib/deprecatedlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
4 changes: 2 additions & 2 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand Down
6 changes: 5 additions & 1 deletion lib/tests/accesslib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2363,8 +2363,10 @@ public function test_permission_evaluation() {
}

$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.
Expand All @@ -2378,6 +2380,8 @@ public function test_permission_evaluation() {
$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();
Expand Down
1 change: 1 addition & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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().

=== 2.5.1 ===

Expand Down

0 comments on commit f9aa801

Please sign in to comment.