MDL-40404 Libraries: Deprecated get_parent_contextid()

This commit is contained in:
Rajesh Taneja
2013-07-04 12:59:06 +08:00
parent 766fd0d92f
commit 7f5b51c4e6
12 changed files with 35 additions and 37 deletions

View File

@@ -99,9 +99,9 @@ foreach ($contexts as $conid => $con) {
// Put the contexts into a tree structure. // Put the contexts into a tree structure.
foreach ($contexts as $conid => $con) { foreach ($contexts as $conid => $con) {
$context = context::instance_by_id($conid); $context = context::instance_by_id($conid);
$parentcontextid = get_parent_contextid($context); $parentcontext = $context->get_parent_context();
if ($parentcontextid) { if ($parentcontext) {
$contexts[$parentcontextid]->children[] = $conid; $contexts[$parentcontext->id]->children[] = $conid;
} }
} }

View File

@@ -74,9 +74,9 @@ function tool_capability_calculate_role_data($capability, array $roles) {
// Put the contexts into a tree structure. // Put the contexts into a tree structure.
foreach ($contexts as $conid => $con) { foreach ($contexts as $conid => $con) {
$context = context::instance_by_id($conid); $context = context::instance_by_id($conid);
$parentcontextid = get_parent_contextid($context); $parentcontext = $context->get_parent_context();
if ($parentcontextid) { if ($parentcontext) {
$contexts[$parentcontextid]->children[] = $conid; $contexts[$parentcontext->id]->children[] = $conid;
} }
} }

View File

@@ -7230,22 +7230,6 @@ class context_block extends context {
// before removing devs will be warned with a debugging message first, // 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 // then we will add error message and only after that we can remove the functions
// completely. // 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. * Recursive function which, given a context, find all its children context ids.
* *

View File

@@ -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. * Return the id of the parent of this context, or false if there is no parent (only happens if this
* @deprecated since 2.1 * 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() { function get_parent_contextid(context $context) {
throw new coding_exception('message_get_my_providers() is deprecated please use message_get_providers_for_user()'); 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;
}
} }

View File

@@ -472,13 +472,10 @@ class file_info_context_course extends file_info {
/** /**
* Returns parent file_info instance * Returns parent file_info instance
* *
* @todo error checking if get_parent_contextid() returns false
* @return file_info or null for root * @return file_info or null for root
*/ */
public function get_parent() { public function get_parent() {
//TODO: error checking if get_parent_contextid() returns false $parent = $this->context->get_parent_context();
$pcid = get_parent_contextid($this->context);
$parent = context::instance_by_id($pcid, IGNORE_MISSING);
return $this->browser->get_file_info($parent); return $this->browser->get_file_info($parent);
} }
} }

View File

@@ -254,8 +254,7 @@ class file_info_context_coursecat extends file_info {
* @return file_info|null fileinfo instance or null for root directory * @return file_info|null fileinfo instance or null for root directory
*/ */
public function get_parent() { public function get_parent() {
$cid = get_parent_contextid($this->context); $parent = $this->context->get_parent_context();
$parent = context::instance_by_id($cid, IGNORE_MISSING);
return $this->browser->get_file_info($parent); return $this->browser->get_file_info($parent);
} }
} }

View File

@@ -352,8 +352,7 @@ class file_info_context_module extends file_info {
* @return file_info|null file_info or null for root * @return file_info|null file_info or null for root
*/ */
public function get_parent() { public function get_parent() {
$pcid = get_parent_contextid($this->context); $parent = $this->context->get_parent_context();
$parent = context::instance_by_id($pcid, IGNORE_MISSING);
return $this->browser->get_file_info($parent); return $this->browser->get_file_info($parent);
} }
} }

View File

@@ -917,7 +917,8 @@ class moodle_page {
// fine - no change needed // fine - no change needed
} else if ($this->_context->contextlevel == CONTEXT_SYSTEM or $this->_context->contextlevel == CONTEXT_COURSE) { } 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 // 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 // hmm - most probably somebody did require_login() and after that set the block context
} else { } else {
// we do not want devs to do weird switching of context levels on the fly, // we do not want devs to do weird switching of context levels on the fly,

View File

@@ -441,8 +441,13 @@ function question_delete_course_category($category, $newcategory, $feedback=true
$questionids = $DB->get_records_menu('question', $questionids = $DB->get_records_menu('question',
array('category'=>$category->id), '', 'id, 1'); array('category'=>$category->id), '', 'id, 1');
if (!empty($questionids)) { if (!empty($questionids)) {
$parentcontextid = false;
$parentcontext = $context->get_parent_context();
if ($parentcontext) {
$parentcontextid = $parentcontext->id;
}
if (!$rescueqcategory = question_save_from_deletion( if (!$rescueqcategory = question_save_from_deletion(
array_keys($questionids), get_parent_contextid($context), array_keys($questionids), $parentcontextid,
print_context_name($context), $rescueqcategory)) { print_context_name($context), $rescueqcategory)) {
return false; return false;
} }

View File

@@ -215,7 +215,7 @@ class required_capability_exception extends moodle_exception {
$capabilityname = get_capability_string($capability); $capabilityname = get_capability_string($capability);
if ($context->contextlevel == CONTEXT_MODULE and preg_match('/:view$/', $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 // 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); $link = get_context_url($paranetcontext);
} else { } else {
$link = get_context_url($context); $link = get_context_url($context);

View File

@@ -2360,6 +2360,7 @@ class accesslib_testcase extends advanced_testcase {
} else { } else {
$this->assertSame(get_parent_contextid($context), $context->get_parent_context()->id); $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); $children = get_child_contexts($systemcontext);

View File

@@ -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. * load_temp_role() and remove_temp_roles() can not be used any more.
* get_system_context() is deprecated, please use context_system::instance(). * get_system_context() is deprecated, please use context_system::instance().
* get_parent_contexts() is deprecated, please use $context->get_parent_context_ids(). * 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 === === 2.5.1 ===