]> git.mjollnir.org Git - moodle.git/commitdiff
course: Changing a course cat from course/edit calls context_moved()
authormartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:13:57 +0000 (07:13 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:13:57 +0000 (07:13 +0000)
Changes to course cat from the main course settings form now calls
context_moved(), and accesslib data is properly maintained.

course/lib.php

index f21afeca6aa6bc465ccb10a7e4fff0957e064ad2..40d46f4984bee0075750b442fc9c97a5e412443a 100644 (file)
@@ -2757,11 +2757,14 @@ function update_course($data) {
         unset($data->restrictmodules);
     }
 
+    $movecat = false;
     $oldcourse = get_record('course', 'id', $data->id); // should not fail, already tested above
     if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $oldcourse->category))
       or !has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $data->category))) {
         // can not move to new category, keep the old one
         unset($data->category);
+    } elseif ($oldcourse->category != $data->category) {
+        $movecat = true;
     }
 
     // Update with the new data
@@ -2775,6 +2778,12 @@ function update_course($data) {
             update_restricted_mods($course, $allowedmods);
         }
 
+        if ($movecat) {
+            $context   = get_context_instance(CONTEXT_COURSE, $course->id);
+            $newparent = get_context_instance(CONTEXT_COURSECAT, $course->category);
+            context_moved($context, $newparent);
+        }
+
         fix_course_sortorder();
 
         // Test for and remove blocks which aren't appropriate anymore