diff --git a/admin/roles/usersroles.php b/admin/roles/usersroles.php index 0935f6f8472..c62c979a673 100644 --- a/admin/roles/usersroles.php +++ b/admin/roles/usersroles.php @@ -99,9 +99,9 @@ foreach ($contexts as $conid => $con) { // Put the contexts into a tree structure. foreach ($contexts as $conid => $con) { $context = context::instance_by_id($conid); - $parentcontextid = get_parent_contextid($context); - if ($parentcontextid) { - $contexts[$parentcontextid]->children[] = $conid; + $parentcontext = $context->get_parent_context(); + if ($parentcontext) { + $contexts[$parentcontext->id]->children[] = $conid; } } diff --git a/admin/tool/capability/locallib.php b/admin/tool/capability/locallib.php index aff07913660..08cd8b3acb1 100644 --- a/admin/tool/capability/locallib.php +++ b/admin/tool/capability/locallib.php @@ -74,9 +74,9 @@ function tool_capability_calculate_role_data($capability, array $roles) { // Put the contexts into a tree structure. foreach ($contexts as $conid => $con) { $context = context::instance_by_id($conid); - $parentcontextid = get_parent_contextid($context); - if ($parentcontextid) { - $contexts[$parentcontextid]->children[] = $conid; + $parentcontext = $context->get_parent_context(); + if ($parentcontext) { + $contexts[$parentcontext->id]->children[] = $conid; } } diff --git a/lib/accesslib.php b/lib/accesslib.php index 362c338e21a..66975330a94 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -7230,22 +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. -/** - * Return the id of the parent of this context, or false if there is no parent (only happens if this - * is the site context.) - * - * @deprecated since 2.2, use $context->get_parent_context() instead - * @param context $context - * @return integer the id of the parent context. - */ -function get_parent_contextid(context $context) { - if ($parent = $context->get_parent_context()) { - return $parent->id; - } else { - return false; - } -} - /** * Recursive function which, given a context, find all its children context ids. * diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 249df2c6f57..c4d3191b342 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -4946,9 +4946,20 @@ function get_parent_contexts(context $context, $includeself = false) { } /** - * This function has been deprecated please use {@link message_get_providers_for_user()} instead. - * @deprecated since 2.1 + * Return the id of the parent of this context, or false if there is no parent (only happens if this + * is the site context.) + * + * @deprecated since Moodle 2.2 + * @see context::get_parent_context() + * @param context $context + * @return integer the id of the parent context. */ -function message_get_my_providers() { - throw new coding_exception('message_get_my_providers() is deprecated please use message_get_providers_for_user()'); +function get_parent_contextid(context $context) { + debugging('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER); + + if ($parent = $context->get_parent_context()) { + return $parent->id; + } else { + return false; + } } diff --git a/lib/filebrowser/file_info_context_course.php b/lib/filebrowser/file_info_context_course.php index 64fcc4b2969..84fd4e6da99 100644 --- a/lib/filebrowser/file_info_context_course.php +++ b/lib/filebrowser/file_info_context_course.php @@ -472,13 +472,10 @@ class file_info_context_course extends file_info { /** * Returns parent file_info instance * - * @todo error checking if get_parent_contextid() returns false * @return file_info or null for root */ public function get_parent() { - //TODO: error checking if get_parent_contextid() returns false - $pcid = get_parent_contextid($this->context); - $parent = context::instance_by_id($pcid, IGNORE_MISSING); + $parent = $this->context->get_parent_context(); return $this->browser->get_file_info($parent); } } diff --git a/lib/filebrowser/file_info_context_coursecat.php b/lib/filebrowser/file_info_context_coursecat.php index 02b1774f7bf..5b495263b14 100644 --- a/lib/filebrowser/file_info_context_coursecat.php +++ b/lib/filebrowser/file_info_context_coursecat.php @@ -254,8 +254,7 @@ class file_info_context_coursecat extends file_info { * @return file_info|null fileinfo instance or null for root directory */ public function get_parent() { - $cid = get_parent_contextid($this->context); - $parent = context::instance_by_id($cid, IGNORE_MISSING); + $parent = $this->context->get_parent_context(); return $this->browser->get_file_info($parent); } } diff --git a/lib/filebrowser/file_info_context_module.php b/lib/filebrowser/file_info_context_module.php index 9affb2bb62e..5bd064d797b 100644 --- a/lib/filebrowser/file_info_context_module.php +++ b/lib/filebrowser/file_info_context_module.php @@ -352,8 +352,7 @@ class file_info_context_module extends file_info { * @return file_info|null file_info or null for root */ public function get_parent() { - $pcid = get_parent_contextid($this->context); - $parent = context::instance_by_id($pcid, IGNORE_MISSING); + $parent = $this->context->get_parent_context(); return $this->browser->get_file_info($parent); } } diff --git a/lib/pagelib.php b/lib/pagelib.php index 556a9dfc345..28967fab86e 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -917,7 +917,8 @@ class moodle_page { // fine - no change needed } else if ($this->_context->contextlevel == CONTEXT_SYSTEM or $this->_context->contextlevel == CONTEXT_COURSE) { // hmm - not ideal, but it might produce too many warnings due to the design of require_login - } else if ($this->_context->contextlevel == CONTEXT_MODULE and $this->_context->id == get_parent_contextid($context)) { + } else if ($this->_context->contextlevel == CONTEXT_MODULE and ($parentcontext = $context->get_parent_context()) and + $this->_context->id == $parentcontext->id) { // hmm - most probably somebody did require_login() and after that set the block context } else { // we do not want devs to do weird switching of context levels on the fly, diff --git a/lib/questionlib.php b/lib/questionlib.php index f1c77be8491..ecbbb473059 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -441,8 +441,13 @@ function question_delete_course_category($category, $newcategory, $feedback=true $questionids = $DB->get_records_menu('question', array('category'=>$category->id), '', 'id, 1'); if (!empty($questionids)) { + $parentcontextid = false; + $parentcontext = $context->get_parent_context(); + if ($parentcontext) { + $parentcontextid = $parentcontext->id; + } if (!$rescueqcategory = question_save_from_deletion( - array_keys($questionids), get_parent_contextid($context), + array_keys($questionids), $parentcontextid, print_context_name($context), $rescueqcategory)) { return false; } diff --git a/lib/setuplib.php b/lib/setuplib.php index e120a909661..1f850848541 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -215,7 +215,7 @@ class required_capability_exception extends moodle_exception { $capabilityname = get_capability_string($capability); if ($context->contextlevel == CONTEXT_MODULE and preg_match('/:view$/', $capability)) { // we can not go to mod/xx/view.php because we most probably do not have cap to view it, let's go to course instead - $paranetcontext = context::instance_by_id(get_parent_contextid($context)); + $paranetcontext = $context->get_parent_context(); $link = get_context_url($paranetcontext); } else { $link = get_context_url($context); diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index 0ef7a3678ce..04e122de31f 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -2360,6 +2360,7 @@ class accesslib_testcase extends advanced_testcase { } else { $this->assertSame(get_parent_contextid($context), $context->get_parent_context()->id); } + $this->assertDebuggingCalled('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER); } $children = get_child_contexts($systemcontext); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 506bb20b41a..f3da7ea6d7f 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -10,6 +10,7 @@ information provided here is intended especially for developers. * 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(). +* get_parent_contextid() is deprecated, please use $context->get_parent_context(). === 2.5.1 ===