From 2e5eba856077396502ed81b8071da44c76b2fe30 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Tue, 6 Jul 2010 17:14:36 +0000 Subject: [PATCH] MDL-19776 make sure contexts are fully initialised after each core upgrade, it is relatively cheap, so it should not cause any problems --- lib/db/upgrade.php | 22 +--------------------- lib/upgradelib.php | 5 +++++ 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 2e6bcccac46..e83ae7a03de 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2008,26 +2008,6 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint(true, 2009071000); } - if ($oldversion < 2009071300) { - - /// Create contexts for every block. In the past, only non-sticky course block had contexts. - /// This is a copy of the code in create_contexts. - $sql = "INSERT INTO {context} (contextlevel, instanceid) - SELECT " . CONTEXT_BLOCK . ", bi.id - FROM {block_instances} bi - WHERE NOT EXISTS (SELECT 'x' - FROM {context} ctx - WHERE bi.id = ctx.instanceid AND ctx.contextlevel=" . CONTEXT_BLOCK . ")"; - $DB->execute($sql); - - /// TODO MDL-19776 We should not really use API functions in upgrade. - /// If MDL-19776 is done, we can remove this whole upgrade block. - build_context_path(); - - /// Main savepoint reached - upgrade_main_savepoint(true, 2009071300); - } - if ($oldversion < 2009071600) { /// Define field summaryformat to be added to post @@ -2096,7 +2076,7 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); // The new global navigation block instance as a stdClass $newblockinstances['globalnavigation']->blockname = 'global_navigation_tree'; $newblockinstances['globalnavigation']->parentcontextid = $syscontext->id; // System context - $newblockinstances['globalnavigation']->showinsubcontexts = true; // Show absolutly everywhere + $newblockinstances['globalnavigation']->showinsubcontexts = true; // Show absolutely everywhere $newblockinstances['globalnavigation']->pagetypepattern = '*'; // Thats right everywhere $newblockinstances['globalnavigation']->subpagetypepattern = null; $newblockinstances['globalnavigation']->defaultregion = BLOCK_POS_LEFT; diff --git a/lib/upgradelib.php b/lib/upgradelib.php index fa917e83544..a36f3c981b9 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -1259,6 +1259,11 @@ function upgrade_core($version, $verbose) { // Reset caches again, just to be sure upgrade_reset_caches(); remove_dir($CFG->dataroot . '/cache', true); // flush cache + + // Clean up contexts - more and more stuff depends on existence of paths and contexts + cleanup_contexts(); + create_contexts(); + build_context_path(); $syscontext = get_context_instance(CONTEXT_SYSTEM); mark_context_dirty($syscontext->path); -- 2.43.0