From 1d28d87b3569aafd1417bab3e8171bfc06d53fbf Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Wed, 19 Sep 2007 07:50:05 +0000 Subject: [PATCH] accesslib - Ensure newly-created categories have a context 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 | 9 ++++++--- course/index.php | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/admin/index.php b/admin/index.php index 38708e0419..cfcc4d20d7 100644 --- a/admin/index.php +++ b/admin/index.php @@ -467,10 +467,13 @@ $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!"); diff --git a/course/index.php b/course/index.php index 2d25f75fdc..070bae0ad0 100644 --- a/course/index.php +++ b/course/index.php @@ -53,9 +53,11 @@ $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))); } } @@ -180,6 +182,8 @@ 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); } -- 2.39.5