]> git.mjollnir.org Git - moodle.git/commitdiff
accesslib - Ensure newly-created categories have a context
authormartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:50:05 +0000 (07:50 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:50:05 +0000 (07:50 +0000)
New categories need a context immediately, and for top-level
categories, they also need to taint the "root" context to trigger
a reload of $USER->access.

This fixes problems with creation of initial courses(MDL-11178),
duplicate misc categories, etc.

admin/index.php
course/index.php

index 38708e041921c018ac9e78b292056e2bca99f4f5..cfcc4d20d722979bd7c9c1ef8c885fb4b8195797 100644 (file)
 
             $cat = new Object();
             $cat->name = get_string('miscellaneous');
-            if (insert_record('course_categories', $cat)) {
-                  redirect('index.php');
+            if ($cat->id = insert_record('course_categories', $cat)) {
+                $cat->context = get_context_instance(CONTEXT_COURSECAT, $cat->id);
+                 mark_context_dirty('/'.SYSCONTEXTID);
+
+                redirect('index.php');
             } else {
-                 error("Serious Error! Could not set up a default course category!");
+                error("Serious Error! Could not set up a default course category!");
             }
         } else {
             error("Serious Error! Could not set up the site!");
index 2d25f75fdca82059a738376c6685231b97230fb2..070bae0ad0dae12097431bb2b12aae2993196ef1 100644 (file)
             $newcategory->name = stripslashes_safe($form->addcategory);
             $newcategory->description = $form->description;
             $newcategory->sortorder = 999;
-            if (!insert_record('course_categories', $newcategory)) {
+            if (!$newcategory->id = insert_record('course_categories', $newcategory)) {
                 notify("Could not insert the new category '" . format_string($newcategory->name) . "'");
             } else {
+                $newcategory->context = get_context_instance(CONTEXT_COURSECAT, $newcategory->id);
+                mark_context_dirty($newcategory->context->path);
                 notify(get_string('categoryadded', '', format_string($newcategory->name)));
             }
         }
         if (!$tempcat->id = insert_record('course_categories', $tempcat)) {
             error('Serious error: Could not create a default category!');
         }
+        $tempcat->context = get_context_instance(CONTEXT_COURSECAT, $tempcat->id);
+        mark_context_dirty('/'.SYSCONTEXTID);
     }