From 1e7d035a9be9ffce16b0ff3f51cb1fe0fd3b0402 Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Tue, 4 Feb 2020 17:02:59 +1100 Subject: [PATCH 1/7] Show warning if outage editing will trigger re-enabling maintenance mode #172. --- classes/form/outage/edit.php | 12 ++++++++++-- lang/en/auth_outage.php | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/classes/form/outage/edit.php b/classes/form/outage/edit.php index 11ff166..96edaa2 100644 --- a/classes/form/outage/edit.php +++ b/classes/form/outage/edit.php @@ -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); } 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) From 10223da3517fd0c85989ee5b2534f0498a8938e2 Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Tue, 4 Feb 2020 15:03:30 +1100 Subject: [PATCH 2/7] Amend redirection url when outage is saved. --- edit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From a906f993f01558340858a81ca6fcea0399ca1151 Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Tue, 4 Feb 2020 16:11:17 +1100 Subject: [PATCH 3/7] Add conditions before calling update_maintenance_later() #172. --- classes/dml/outagedb.php | 2 +- classes/local/outagelib.php | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) 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/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() { From 0137811f2b71c113ffe93c15277e6a05dafd9147 Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Tue, 4 Feb 2020 16:51:41 +1100 Subject: [PATCH 4/7] Hide Create outage button if there is an ongoing outage #172. --- views/manage.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/views/manage.php b/views/manage.php index 22925df..0ff9f0d 100644 --- a/views/manage.php +++ b/views/manage.php @@ -26,6 +26,7 @@ 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(); @@ -47,9 +48,12 @@ echo $viewbag['warning']; $table->finish_output(); ?> - + + + +
From 587bd3a311c4d25354a9accf991d88e91b29becd Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Tue, 4 Feb 2020 17:40:32 +1100 Subject: [PATCH 5/7] Fix Cancel button on Edit form. --- classes/form/outage/edit.php | 10 ++++++++-- edit.php | 14 +++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/classes/form/outage/edit.php b/classes/form/outage/edit.php index 96edaa2..7fb7d93 100644 --- a/classes/form/outage/edit.php +++ b/classes/form/outage/edit.php @@ -163,10 +163,16 @@ class edit extends moodleform { $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); } } + + /** + * {@inheritDoc} + * @see moodleform::definition_after_data() + */ + public function definition_after_data() { + $this->add_action_buttons(); + } } diff --git a/edit.php b/edit.php index 5cd25f8..0d7cb24 100644 --- a/edit.php +++ b/edit.php @@ -38,11 +38,15 @@ $PAGE->set_url(new moodle_url('/auth/outage/manage.php')); $mform = new edit(); -if ($mform->is_cancelled()) { - redirect(new moodle_url('/auth/outage/manage.php')); -} else if ($outage = $mform->get_data()) { - $id = outagedb::save($outage); - redirect(new moodle_url('/auth/outage/manage.php')); +if ($mform->is_submitted()) { + $mform->is_validated(); + + if ($mform->is_cancelled()) { + redirect(new moodle_url('/auth/outage/manage.php')); + } else if ($outage = $mform->get_data()) { + $id = outagedb::save($outage); + redirect(new moodle_url('/auth/outage/manage.php')); + } } $clone = optional_param('clone', 0, PARAM_INT); From d438027a185ff1b5c6e6c5c45bba4f5c36c07e19 Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Wed, 5 Feb 2020 12:51:43 +1100 Subject: [PATCH 6/7] Reorganize warning and buttons for Edit form #172. --- classes/form/outage/edit.php | 19 +++++++------------ edit.php | 14 +++++--------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/classes/form/outage/edit.php b/classes/form/outage/edit.php index 7fb7d93..b37df11 100644 --- a/classes/form/outage/edit.php +++ b/classes/form/outage/edit.php @@ -82,6 +82,9 @@ 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(); } /** @@ -145,6 +148,7 @@ class edit extends moodleform { */ public function set_data($outage) { global $OUTPUT; + $mform = $this->_form; // Cannot change method signature, check type. if ($outage instanceof outage) { @@ -158,21 +162,12 @@ class edit extends moodleform { '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')); + 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); } } - - /** - * {@inheritDoc} - * @see moodleform::definition_after_data() - */ - public function definition_after_data() { - $this->add_action_buttons(); - } } diff --git a/edit.php b/edit.php index 0d7cb24..5cd25f8 100644 --- a/edit.php +++ b/edit.php @@ -38,15 +38,11 @@ $PAGE->set_url(new moodle_url('/auth/outage/manage.php')); $mform = new edit(); -if ($mform->is_submitted()) { - $mform->is_validated(); - - if ($mform->is_cancelled()) { - redirect(new moodle_url('/auth/outage/manage.php')); - } else if ($outage = $mform->get_data()) { - $id = outagedb::save($outage); - redirect(new moodle_url('/auth/outage/manage.php')); - } +if ($mform->is_cancelled()) { + redirect(new moodle_url('/auth/outage/manage.php')); +} else if ($outage = $mform->get_data()) { + $id = outagedb::save($outage); + redirect(new moodle_url('/auth/outage/manage.php')); } $clone = optional_param('clone', 0, PARAM_INT); From c724e1abe4ea56023246d70e644a5a8b0e3c9449 Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Wed, 5 Feb 2020 14:09:34 +1100 Subject: [PATCH 7/7] Replace custom html button with OUTPUT->single_button #172. --- views/manage.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/views/manage.php b/views/manage.php index 0ff9f0d..52c856c 100644 --- a/views/manage.php +++ b/views/manage.php @@ -30,6 +30,7 @@ use auth_outage\dml\outagedb; defined('MOODLE_INTERNAL') || die(); +global $OUTPUT; $urlnew = new moodle_url('/auth/outage/edit.php'); echo $viewbag['warning']; @@ -50,9 +51,7 @@ echo $viewbag['warning']; - + single_button($urlnew, get_string('outagecreate', 'auth_outage')); ?>