From 1909a127604fd8851f4a0ed2023abc704b42cdcd Mon Sep 17 00:00:00 2001 From: skodak Date: Sat, 8 Mar 2008 22:38:11 +0000 Subject: [PATCH] MDL-13853 incorrect paths when moving grade categories - affects aggregation in subcategories; merged from MOODLE_19_STABLE --- lib/grade/grade_category.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 80ea408b4a..94e09f13cc 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -197,6 +197,9 @@ class grade_category extends grade_object { if (empty($this->path)) { $this->path = grade_category::build_path($this); $this->depth = substr_count($this->path, '/') - 1; + $updatechildren = true; + } else { + $updatechildren = false; } $this->apply_forced_settings(); @@ -215,7 +218,21 @@ class grade_category extends grade_object { $this->timemodified = time(); - return parent::update($source); + $result = parent::update($source); + + // now update paths in all child categories + if ($result and $updatechildren) { + if ($children = grade_category::fetch_all(array('parent'=>$this->id))) { + foreach ($children as $child) { + echo "updating $child->id "; + $child->path = null; + $child->depth = 0; + $child->update($source); + } + } + } + + return $result; } /** -- 2.39.5