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

This commit is contained in:
Brendan Heywood
2025-09-22 10:18:29 +10:00
committed by Benjamin Walker
parent 1d3f14d26a
commit f63aed7459
2 changed files with 32 additions and 11 deletions
+18 -9
View File
@@ -69,7 +69,7 @@ if ($options['enablelater']) {
}
$time = time() + ($options['enablelater']*60);
set_config('maintenance_later', $time);
set_config('maintenance_later', $time, null, true);
echo get_string('clistatusenabledlater', 'admin', userdate($time))."\n";
return 0;
@@ -77,23 +77,32 @@ if ($options['enablelater']) {
} else if ($options['enable']) {
if (file_exists("$CFG->dataroot/climaintenance.html")) {
// The maintenance is already enabled, nothing to do.
} else {
enable_cli_maintenance_mode();
exit(0);
}
enable_cli_maintenance_mode();
set_config('maintenance_enabled', 'cli mode', null, true);
if (isset($CFG->maintenance_later)) {
unset_config('maintenance_later', null, true);
}
set_config('maintenance_enabled', 0);
unset_config('maintenance_later');
echo get_string('sitemaintenanceoncli', 'admin')."\n";
exit(0);
} else if ($options['enableold']) {
set_config('maintenance_enabled', 1);
unset_config('maintenance_later');
set_config('maintenance_enabled', 1, null, true);
if (isset($CFG->maintenance_later)) {
unset_config('maintenance_later', null, true);
}
echo get_string('sitemaintenanceon', 'admin')."\n";
exit(0);
} else if ($options['disable']) {
set_config('maintenance_enabled', 0);
unset_config('maintenance_later');
if ($CFG->maintenance_enabled !== '0') {
set_config('maintenance_enabled', 0, null, true);
}
if (isset($CFG->maintenance_later)) {
unset_config('maintenance_later', null, true);
}
if (file_exists("$CFG->dataroot/climaintenance.html")) {
unlink("$CFG->dataroot/climaintenance.html");
}
+14 -2
View File
@@ -1160,15 +1160,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));
}
}