Merge pull request #173 from catalyst/issue172

Fix events that trigger re-enabling maintenance mode
This commit is contained in:
Brendan Heywood
2020-02-05 13:48:57 +10:00
committed by GitHub
6 changed files with 29 additions and 7 deletions

View File

@@ -135,7 +135,7 @@ class outagedb {
}
// Trigger outages modified events.
outagelib::prepare_next_outage();
outagelib::prepare_next_outage(true);
// All done, return the id.
return $outage->id;

View File

@@ -82,6 +82,7 @@ class edit extends moodleform {
$mform->addHelpButton('description', 'description', 'auth_outage');
$mform->addElement('static', 'usagehints', '', get_string('textplaceholdershint', 'auth_outage'));
$mform->addElement('static', 'warningreenablemaintenancemode', '');
$this->add_action_buttons();
}
@@ -146,6 +147,9 @@ class edit extends moodleform {
* @throws coding_exception
*/
public function set_data($outage) {
global $OUTPUT;
$mform = $this->_form;
// Cannot change method signature, check type.
if ($outage instanceof outage) {
$this->_form->setDefaults([
@@ -157,6 +161,11 @@ 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()) {
$warning = $mform->getElement('warningreenablemaintenancemode');
$warning->setValue($OUTPUT->notification(get_string('warningreenablemaintenancemode', 'auth_outage'), 'notifywarning'));
}
} else {
throw new coding_exception('$outage must be an outage object.', $outage);
}

View File

@@ -163,16 +163,25 @@ class outagelib {
/**
* Executed when outages are modified (created, updated or deleted).
*
* @param bool $reenablemaint should we re-enable maintenance mode for ongoing outage
* @throws coding_exception
* @throws file_exception
*/
public static function prepare_next_outage() {
public static function prepare_next_outage($reenablemaint = false) {
// If there is an ongoing outage, prepare it instead.
$outage = outagedb::get_ongoing();
if (is_null($outage)) {
$outage = outagedb::get_next_starting();
$ongoingoutage = false;
} else {
$ongoingoutage = true;
}
maintenance_static_page::create_from_outage($outage)->generate();
self::update_climaintenance_code($outage);
self::update_maintenance_later($outage);
if (!$ongoingoutage || $reenablemaint || is_null($outage)) {
self::update_maintenance_later($outage);
}
}
private static function check_wwwroot_accessible() {

View File

@@ -42,7 +42,7 @@ if ($mform->is_cancelled()) {
redirect(new moodle_url('/auth/outage/manage.php'));
} else if ($outage = $mform->get_data()) {
$id = outagedb::save($outage);
redirect($CFG->wwwroot. '/auth/outage/manage.php#auth_outage_id_'.$id);
redirect(new moodle_url('/auth/outage/manage.php'));
}
$clone = optional_param('clone', 0, PARAM_INT);

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)

View File

@@ -26,9 +26,11 @@
use auth_outage\output\manage\history_table;
use auth_outage\output\manage\planned_table;
use auth_outage\output\renderer;
use auth_outage\dml\outagedb;
defined('MOODLE_INTERNAL') || die();
global $OUTPUT;
$urlnew = new moodle_url('/auth/outage/edit.php');
echo $viewbag['warning'];
@@ -47,9 +49,10 @@ echo $viewbag['warning'];
$table->finish_output();
?>
<?php endif; ?>
<input type="button" class="form-submit"
value="<?php echo get_string('outagecreate', 'auth_outage'); ?>"
onclick="location.href='<?php echo $urlnew; ?>';"/>
<?php $outage = outagedb::get_ongoing(); ?>
<?php if (is_null($outage)): ?>
<?php echo $OUTPUT->single_button($urlnew, get_string('outagecreate', 'auth_outage')); ?>
<?php endif; ?>
</section>
<section id="section_outage_history">