From f49fe84488d9493bad1add77c31139fc8c30931a Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Fri, 24 Jul 2020 11:08:25 +0800 Subject: [PATCH 1/1] MDL-69079 core: Restore and set missing guest user --- lib/db/upgrade.php | 30 ++++++++++++++++++++++++++++++ version.php | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 1df218e4e64..32298db70a0 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2497,5 +2497,35 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2020061501.01); } + if ($oldversion < 2020061501.04) { + // 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, 2020061501.04); + } + return true; } diff --git a/version.php b/version.php index ccb3c81161b..87794039939 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2020061501.03; // 20200615 = branching date YYYYMMDD - do not modify! +$version = 2020061501.04; // 20200615 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '3.9.1+ (Build: 20200723)'; // Human-friendly version name -- 2.43.0