From 54e7130ed2f3eea1a9e63bd70b4e4fe0a53c4c41 Mon Sep 17 00:00:00 2001 From: moodler Date: Sun, 21 Dec 2003 05:10:13 +0000 Subject: [PATCH] When deleting a category, send children courses to live with grandma --- course/index.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/course/index.php b/course/index.php index c83991dae7..bc28254408 100644 --- a/course/index.php +++ b/course/index.php @@ -102,14 +102,24 @@ if (delete_records("course_categories", "id", $tempcat->id)) { notify(get_string("categorydeleted", "", $tempcat->name)); } - if ($children = get_records("course_categories", "parent", $tempcat->id)) { - // Send the children to live with their grandparent - foreach ($children as $childcat) { + + /// Send the children categories to live with their grandparent + if ($childcats = get_records("course_categories", "parent", $tempcat->id)) { + foreach ($childcats as $childcat) { if (! set_field("course_categories", "parent", $tempcat->parent, "id", $childcat->id)) { notify("Could not update a child category!"); } } } + + /// Send the children courses to live with their grandparent as well + if ($childcourses = get_records("course", "category", $tempcat->id)) { + foreach ($childcourses as $childcourse) { + if (! set_field("course", "category", $tempcat->parent, "id", $childcourse->id)) { + notify("Could not update a child course!"); + } + } + } } } -- 2.39.5