Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-43367 stop returning of bogus context children when path unknown

This also prevents deletion of system context.
  • Loading branch information...
commit f06d89b2b53ab513677d55de1423c129a96f180b 1 parent 346ef56
@skodak skodak authored
Showing with 14 additions and 0 deletions.
  1. +14 −0 lib/accesslib.php
View
14 lib/accesslib.php
@@ -5270,6 +5270,10 @@ public function delete_content() {
public function delete() {
global $DB;
+ if ($this->_contextlevel <= CONTEXT_SYSTEM) {
+ throw new coding_exception('Cannot delete system context');
+ }
+
// double check the context still exists
if (!$DB->record_exists('context', array('id'=>$this->_id))) {
context::cache_remove($this);
@@ -5365,6 +5369,11 @@ public function get_context_name($withprefix = true, $short = false) {
public function get_child_contexts() {
global $DB;
+ if (empty($this->_path) or empty($this->_depth)) {
+ debugging('Can not find child contexts of context '.$this->_id.' try rebuilding of context paths');
+ return array();
+ }
+
$sql = "SELECT ctx.*
FROM {context} ctx
WHERE ctx.path LIKE ?";
@@ -6337,6 +6346,11 @@ public static function instance($instanceid, $strictness = MUST_EXIST) {
public function get_child_contexts() {
global $DB;
+ if (empty($this->_path) or empty($this->_depth)) {
+ debugging('Can not find child contexts of context '.$this->_id.' try rebuilding of context paths');
+ return array();
+ }
+
$sql = "SELECT ctx.*
FROM {context} ctx
WHERE ctx.path LIKE ? AND (ctx.depth = ? OR ctx.contextlevel = ?)";
Please sign in to comment.
Something went wrong with that request. Please try again.