diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index c1f539b36c6..d80a8bff040 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2782,5 +2782,41 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2020101300.01); } + if ($oldversion < 2020101600.01) { + // Get the current guest user which is also set as 'deleted'. + $guestuser = $DB->get_record('user', ['id' => $CFG->siteguest, 'deleted' => 1]); + // If there is a deleted guest user, reset the user to not be deleted and make sure the related + // user context exists. + if ($guestuser) { + $guestuser->deleted = 0; + $DB->update_record('user', $guestuser); + + // Get the guest user context. + $guestusercontext = $DB->get_record('context', + ['contextlevel' => CONTEXT_USER, 'instanceid' => $guestuser->id]); + + // If the guest user context does not exist, create it. + if (!$guestusercontext) { + $record = new stdClass(); + $record->contextlevel = CONTEXT_USER; + $record->instanceid = $guestuser->id; + $record->depth = 0; + // The path is not known before insert. + $record->path = null; + $record->locked = 0; + + $record->id = $DB->insert_record('context', $record); + + // Update the path. + $record->path = '/' . SYSCONTEXTID . '/' . $record->id; + $record->depth = substr_count($record->path, '/'); + $DB->update_record('context', $record); + } + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2020101600.01); + } + return true; } diff --git a/version.php b/version.php index 788804768ee..2c43adf6464 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2020101600.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2020101600.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '3.10dev+ (Build: 20201016)';// Human-friendly version name