From 7bb03e8a7b2ec766429f7880e51dea10d46a7837 Mon Sep 17 00:00:00 2001
From: mjollnir_ <mjollnir_>
Date: Wed, 19 Dec 2007 23:32:53 +0000
Subject: [PATCH] merged from MOODLE_19_STABLE: fixing lying phpdoc comments in
 role_cap_duplicate function that I moved to accesslib yesterday

---
 lib/accesslib.php | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/lib/accesslib.php b/lib/accesslib.php
index 2a1dcc25a2..7464aa2a0d 100755
--- a/lib/accesslib.php
+++ b/lib/accesslib.php
@@ -2277,12 +2277,17 @@ function get_system_context($cache=true) {
 
         if (!$context->id = insert_record('context', $context)) {
             // better something than nothing - let's hope it will work somehow
-            if (!defined('SYSCONTEXTID')) {
+            // 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';
             }
             debugging('Can not create system context');
-            $context->id   = SYSCONTEXTID;
-            $context->path = '/'.SYSCONTEXTID;
             return $context;
         }
     }
@@ -5030,7 +5035,7 @@ function switch_roles($first, $second) {
 /**
  * duplicates all the base definitions of a role
  *
- * @param int $sourcerole id of role to copy from
+ * @param object $sourcerole role to copy from
  * @param int $targetrole id of role to copy to
  *
  * @return void
-- 
2.39.5