When deleting a category, send children courses to live with grandma

This commit is contained in:
moodler
2003-12-21 05:10:13 +00:00
parent 6049fb78f2
commit 54e7130ed2
+13 -3
View File
@@ -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!");
}
}
}
}
}