diff --git a/classes/dml/outagedb.php b/classes/dml/outagedb.php index 1098a91..32aa4fc 100644 --- a/classes/dml/outagedb.php +++ b/classes/dml/outagedb.php @@ -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; diff --git a/classes/form/outage/edit.php b/classes/form/outage/edit.php index 11ff166..b37df11 100644 --- a/classes/form/outage/edit.php +++ b/classes/form/outage/edit.php @@ -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); } diff --git a/classes/local/outagelib.php b/classes/local/outagelib.php index b7ceb2e..cf8ebbd 100644 --- a/classes/local/outagelib.php +++ b/classes/local/outagelib.php @@ -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() { diff --git a/edit.php b/edit.php index 4beda3d..5cd25f8 100644 --- a/edit.php +++ b/edit.php @@ -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); diff --git a/lang/en/auth_outage.php b/lang/en/auth_outage.php index dde625c..6b5f497 100644 --- a/lang/en/auth_outage.php +++ b/lang/en/auth_outage.php @@ -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.
Untick "Auto start maintenance mode" if you want to prevent this.'; /* * Privacy provider (GDPR) diff --git a/views/manage.php b/views/manage.php index 22925df..52c856c 100644 --- a/views/manage.php +++ b/views/manage.php @@ -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(); ?> - + + + single_button($urlnew, get_string('outagecreate', 'auth_outage')); ?> +