MDL-84504 cli: Add config logging for cli maintenance mode

This commit is contained in:
Brendan Heywood
2025-09-22 10:13:52 +10:00
committed by Benjamin Walker
parent 10b28ebb08
commit b7a3d429e2
2 changed files with 32 additions and 11 deletions
+14 -2
View File
@@ -1161,15 +1161,27 @@ if (!empty($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'],
// Switch to CLI maintenance mode if required, we need to do it here after all the settings are initialised.
if (isset($CFG->maintenance_later) and $CFG->maintenance_later <= time()) {
// Because maintenance_later is triggered by any potentially real non admin user
// who just happened to be the first to load a page after the time is due, we do
// this simple workaround so add_to_config_log doesn't log it as them.
\core\session\manager::write_close();
$USER->id = 0;
if (!file_exists("$CFG->dataroot/climaintenance.html")) {
require_once("$CFG->libdir/adminlib.php");
set_config('maintenance_enabled', 'cli mode', null, true);
enable_cli_maintenance_mode();
}
unset_config('maintenance_later');
if (isset($CFG->maintenance_later)) {
unset_config('maintenance_later', null, true);
}
if (AJAX_SCRIPT) {
die;
} else if (!CLI_SCRIPT) {
redirect(new moodle_url('/'));
// We redirect to ourselves to reload the page to get a fresh bootstrap
// so that we get the maintenance page which is earlier in setup.
redirect(new moodle_url($ME));
}
}