MDL-69079 core: Restore and set missing guest user
authorMihail Geshoski <mihail@moodle.com>
Fri, 24 Jul 2020 03:08:25 +0000 (11:08 +0800)
committerMihail Geshoski <mihail@moodle.com>
Fri, 24 Jul 2020 03:08:25 +0000 (11:08 +0800)
lib/db/upgrade.php
version.php

index b0ccb2a..a61f5e9 100644 (file)
@@ -2509,5 +2509,35 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint(true, 2020071100.01);
     }
 
+    if ($oldversion < 2020072300.01) {
+        // Restore and set the guest user if it has been previously removed via GDPR, or set to an nonexistent
+        // user account.
+        $currentguestuser = $DB->get_record('user', array('id' => $CFG->siteguest));
+
+        if (!$currentguestuser) {
+            if (!$guest = $DB->get_record('user', array('username' => 'guest', 'mnethostid' => $CFG->mnet_localhost_id))) {
+                // Create a guest user account.
+                $guest = new stdClass();
+                $guest->auth        = 'manual';
+                $guest->username    = 'guest';
+                $guest->password    = hash_internal_user_password('guest');
+                $guest->firstname   = get_string('guestuser');
+                $guest->lastname    = ' ';
+                $guest->email       = 'root@localhost';
+                $guest->description = get_string('guestuserinfo');
+                $guest->mnethostid  = $CFG->mnet_localhost_id;
+                $guest->confirmed   = 1;
+                $guest->lang        = $CFG->lang;
+                $guest->timemodified= time();
+                $guest->id = $DB->insert_record('user', $guest);
+            }
+            // Set the guest user.
+            set_config('siteguest', $guest->id);
+        }
+
+        // Main savepoint reached.
+        upgrade_main_savepoint(true, 2020072300.01);
+    }
+
     return true;
 }
index e5c6368..5c70e04 100644 (file)
@@ -29,7 +29,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2020072300.00;              // YYYYMMDD      = weekly release date of this DEV branch.
+$version  = 2020072300.01;              // YYYYMMDD      = weekly release date of this DEV branch.
                                         //         RR    = release increments - 00 in DEV branches.
                                         //           .XX = incremental changes.
 $release  = '4.0dev (Build: 20200723)'; // Human-friendly version name