Show warning if outage editing will trigger re-enabling maintenance mode #172.

This commit is contained in:
Mikhail Golenkov
2020-02-04 17:02:59 +11:00
parent d709f39122
commit 1e7d035a9b
2 changed files with 11 additions and 2 deletions

View File

@@ -82,8 +82,6 @@ class edit extends moodleform {
$mform->addHelpButton('description', 'description', 'auth_outage');
$mform->addElement('static', 'usagehints', '', get_string('textplaceholdershint', 'auth_outage'));
$this->add_action_buttons();
}
/**
@@ -146,6 +144,8 @@ class edit extends moodleform {
* @throws coding_exception
*/
public function set_data($outage) {
global $OUTPUT;
// Cannot change method signature, check type.
if ($outage instanceof outage) {
$this->_form->setDefaults([
@@ -157,6 +157,14 @@ class edit extends moodleform {
'title' => $outage->title,
'description' => ['text' => $outage->description, 'format' => '1'],
]);
if (!empty($outage->id) && $outage->autostart && $outage->starttime < time() &&
$outage->stoptime > time()) {
$this->_form->addElement('html',
$OUTPUT->notification(get_string('warningreenablemaintenancemode', 'auth_outage'), 'notifywarning'));
}
$this->add_action_buttons();
} else {
throw new coding_exception('$outage must be an outage object.', $outage);
}

View File

@@ -143,6 +143,7 @@ $string['title_help'] = 'A short title to for this outage. It will be displayed
$string['warningdurationerrorinvalid'] = 'Warning duration must be positive.';
$string['warningduration'] = 'Warning duration';
$string['warningduration_help'] = 'How long before the start of the outage should the warning be displayed.';
$string['warningreenablemaintenancemode'] = 'Please note that saving this outage will re-enable maintenance mode.<br />Untick "Auto start maintenance mode" if you want to prevent this.';
/*
* Privacy provider (GDPR)