mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
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:
parent
2939efff84
commit
e412f3029e
2 changed files with 37 additions and 1 deletions
|
@ -2782,5 +2782,41 @@ function xmldb_main_upgrade($oldversion) {
|
||||||
upgrade_main_savepoint(true, 2021052500.24);
|
upgrade_main_savepoint(true, 2021052500.24);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($oldversion < 2021052500.26) {
|
||||||
|
// 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, 2021052500.26);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$version = 2021052500.25; // YYYYMMDD = weekly release date of this DEV branch.
|
$version = 2021052500.26; // YYYYMMDD = weekly release date of this DEV branch.
|
||||||
// RR = release increments - 00 in DEV branches.
|
// RR = release increments - 00 in DEV branches.
|
||||||
// .XX = incremental changes.
|
// .XX = incremental changes.
|
||||||
$release = '4.0dev (Build: 20201016)'; // Human-friendly version name
|
$release = '4.0dev (Build: 20201016)'; // Human-friendly version name
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue