Preventing cli/finish.php to run while in maintenance mode.

This commit is contained in:
Daniel Thee Roperto
2016-11-14 13:57:23 +11:00
parent 27c7558e57
commit 73daf6f666
3 changed files with 16 additions and 4 deletions

View File

@@ -78,6 +78,11 @@ class cli_exception extends Exception {
*/
const ERROR_PLUGIN_DISABLED = 8;
/**
* Moodle maintenance mode is enabled.
*/
const ERROR_MAINTENANCE_MODE = 9;
/**
* cliexception constructor.
* @param string $message An explanation of the exception.

View File

@@ -46,9 +46,9 @@ class finish extends clibase {
public function generate_options() {
// Do not provide some defaults, if cloning an outage we need to know which parameters were provided.
$options = [
'help' => false,
'help' => false,
'outageid' => null,
'active' => false,
'active' => false,
];
return $options;
}
@@ -59,9 +59,9 @@ class finish extends clibase {
*/
public function generate_shortcuts() {
return [
'h' => 'help',
'h' => 'help',
'id' => 'outageid',
'a' => 'active',
'a' => 'active',
];
}
@@ -75,6 +75,12 @@ class finish extends clibase {
return;
}
// Cannot run during CLI_MAINTENANCE mode.
if (CLI_MAINTENANCE) {
throw new cli_exception(get_string('cliinmaintenancemode', 'auth_outage'),
cli_exception::ERROR_MAINTENANCE_MODE);
}
// Requires outageid or active but not both at the same time.
$byid = !is_null($this->options['outageid']);
$byactive = $this->options['active'];

View File

@@ -42,6 +42,7 @@ $string['clifinishnotongoing'] = 'Outage is not ongoing.';
$string['clifinishparamhelp'] = 'shows parameters help.';
$string['clifinishparamactive'] = 'finishes the currently active outage.';
$string['clifinishparamoutageid'] = 'the id of the outage to finish.';
$string['cliinmaintenancemode'] = 'Moodle maintenance mode is on. Use "admin/cli/maintenance.php --disable" to disable it before finishing the outage.';
$string['cliplugindisabled'] = 'The authentication plugin \'Outage\' is disabled. Please enable it in the site administration it and try again.';
$string['cliwaitforiterroridxoractive'] = 'You must use --outageid=# or --active parameter but not both.';
$string['cliwaitforithelp'] = 'Waits until an outage starts.';