MDL-69079 core: Restore and set missing guest user

This commit is contained in:
Mihail Geshoski 2020-07-24 11:08:25 +08:00
parent 7add3440c8
commit d6ec2d3e44
2 changed files with 31 additions and 1 deletions

View 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;
}

View 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