From a906f993f01558340858a81ca6fcea0399ca1151 Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Tue, 4 Feb 2020 16:11:17 +1100 Subject: [PATCH] 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() {