MDL-19776 make sure contexts are fully initialised after each core upgrade, it is...
authorPetr Skoda <skodak@moodle.org>
Tue, 6 Jul 2010 17:14:36 +0000 (17:14 +0000)
committerPetr Skoda <skodak@moodle.org>
Tue, 6 Jul 2010 17:14:36 +0000 (17:14 +0000)
lib/db/upgrade.php
lib/upgradelib.php

index 2e6bccc..e83ae7a 100644 (file)
@@ -2008,26 +2008,6 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
         upgrade_main_savepoint(true, 2009071000);
     }
 
         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
     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
         // 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;
         $newblockinstances['globalnavigation']->pagetypepattern = '*'; // Thats right everywhere
         $newblockinstances['globalnavigation']->subpagetypepattern = null;
         $newblockinstances['globalnavigation']->defaultregion = BLOCK_POS_LEFT;
index fa917e8..a36f3c9 100644 (file)
@@ -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
         // 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);
 
         $syscontext = get_context_instance(CONTEXT_SYSTEM);
         mark_context_dirty($syscontext->path);