mirror of
https://github.com/moodle/moodle.git
synced 2025-07-25 16:21:47 +02:00
MDL-40404 Libraries: Deprecated get_parent_contextid()
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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.
|
||||
*
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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,
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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 ===
|
||||
|
||||
|
Reference in New Issue
Block a user