]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17267 fixed regression caused by my last commit
authorskodak <skodak>
Wed, 19 Nov 2008 14:43:38 +0000 (14:43 +0000)
committerskodak <skodak>
Wed, 19 Nov 2008 14:43:38 +0000 (14:43 +0000)
lib/accesslib.php
lib/setup.php

index 60fcbc60c8ededc9c3bfe236bd716650957065a7..bf20bbe81860b444150c5f3f5ed5dd65ad532318 100755 (executable)
@@ -1808,7 +1808,7 @@ function moodle_install_roles() {
                                       get_string('authenticateduserdescription'), 'moodle/legacy:user');
 
 /// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles
-
+    $systemcontext = get_context_instance(CONTEXT_SYSTEM);
     if (!assign_capability('moodle/site:doanything', CAP_ALLOW, $adminrole, $systemcontext->id)) {
         print_error('cannotassignanthing');
     }
@@ -2133,7 +2133,9 @@ function create_context($contextlevel, $instanceid) {
 }
 
 /**
- * This hacky function is needed because we can not change system context instanceid using normal upgrade routine.
+ * Returns system context or null if can not be created yet.
+ * @param bool $cache use caching
+ * @return mixed system context or null
  */
 function get_system_context($cache=true) {
     global $DB;
@@ -2150,10 +2152,15 @@ function get_system_context($cache=true) {
         }
         return $cached;
     }
-
     try {
-        $context = $DB->get_record('context', array('contextlevel'=>CONTEXT_SYSTEM));
-    } catch (dml_read_exception $e) {
+        // TODO: can not use get_record() because we do not know if query failed :-(
+        //       switch to get_record() later
+        $contextarr = $DB->get_records('context', array('contextlevel'=>CONTEXT_SYSTEM));
+        if ($contextarr === false) {
+            return null;
+        }
+        $context = $contextarr ? reset($contextarr) : null;
+    } catch (dml_exception $e) {
         //table does not exist yet, sorry
         return null;
     }
@@ -2165,20 +2172,13 @@ function get_system_context($cache=true) {
         $context->depth        = 1;
         $context->path         = NULL; //not known before insert
 
-        if (!$context->id = $DB->insert_record('context', $context)) {
-            // better something than nothing - let's hope it will work somehow
-            // DONT do it if we're cli because it's IMMUNTABLE.  Doing it during web installer works because
-            // each step is a new request
-            if (!defined('SYSCONTEXTID') && !defined('CLI_UPGRADE')) {
-                define('SYSCONTEXTID', 1);
-                $context->id   = SYSCONTEXTID;
-                $context->path = '/'.SYSCONTEXTID;
-            } else {
-                $context->id   = 0;
-                $context->path = '/0';
+        try {
+            if (!$context->id = $DB->insert_record('context', $context)) {
+            // can not create context yet, sorry
+                return null;
             }
-            debugging('Can not create system context');
-            return $context;
+        } catch (dml_exception $e) {
+            return null;
         }
     }
 
index b0b3de031555847fdae33a3abfdb45c6e163eea5..9dc398e1ec311787676125bc78a51fbbf7ee7ba7 100644 (file)
@@ -220,11 +220,7 @@ global $HTTPSPAGEREQUIRED;
 
     // define SYSCONTEXTID in config.php if you want to save some queries (after install or upgrade!)
     if (!defined('SYSCONTEXTID')) {
-        try {
-            get_system_context();
-        } catch (dml_read_exception $e) {
-            // not available yet
-        }
+        get_system_context();
     }
 
 /// Set error reporting back to normal