MDL-69751 core: Restore deleted guest user and add missing context
This upgrade step fixes the cases where the current guest user is labelled as 'deleted' and the related user context is missing.
This commit is contained in:
@@ -2589,5 +2589,41 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2020061501.11);
|
||||
}
|
||||
|
||||
if ($oldversion < 2020061502.09) {
|
||||
// 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, 2020061502.09);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2020061502.08; // 20200615 = branching date YYYYMMDD - do not modify!
|
||||
$version = 2020061502.09; // 20200615 = branching date YYYYMMDD - do not modify!
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
$release = '3.9.2+ (Build: 20201016)'; // Human-friendly version name
|
||||
|
||||
Reference in New Issue
Block a user