]> git.mjollnir.org Git - moodle.git/commitdiff
When deleting a category, send children courses to live with grandma
authormoodler <moodler>
Sun, 21 Dec 2003 05:10:13 +0000 (05:10 +0000)
committermoodler <moodler>
Sun, 21 Dec 2003 05:10:13 +0000 (05:10 +0000)
course/index.php

index c83991dae7b941b1dd73072da78bd45386750315..bc28254408c6a2078cef56b17c6dd5c8707426bc 100644 (file)
             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!");
+                    }
+                }
+            }
         }
     }