From 803614793167ca01042b5c79abfe42bbf16460ec Mon Sep 17 00:00:00 2001 From: Daniel Thee Roperto Date: Thu, 26 Apr 2018 15:56:33 +1000 Subject: [PATCH] Issue #129 - Stop maintenance after stoptime. --- classes/local/outagelib.php | 6 +++--- tests/phpunit/local/outagelib_test.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/classes/local/outagelib.php b/classes/local/outagelib.php index a514b68..e579523 100644 --- a/classes/local/outagelib.php +++ b/classes/local/outagelib.php @@ -250,7 +250,7 @@ class outagelib { $code = <<<'EOT' = {{STARTTIME}}) { +if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) { define('MOODLE_INTERNAL', true); require_once($CFG->dirroot.'/lib/moodlelib.php'); if (!remoteip_in_list('{{ALLOWEDIPS}}')) { @@ -278,8 +278,8 @@ if (time() >= {{STARTTIME}}) { } } EOT; - $search = ['{{STARTTIME}}', '{{ALLOWEDIPS}}', '{{YOURIP}}']; - $replace = [$starttime, $allowedips, getremoteaddr('n/a')]; + $search = ['{{STARTTIME}}', '{{STOPTIME}}', '{{ALLOWEDIPS}}', '{{YOURIP}}']; + $replace = [$starttime, $stoptime, $allowedips, getremoteaddr('n/a')]; return str_replace($search, $replace, $code); } diff --git a/tests/phpunit/local/outagelib_test.php b/tests/phpunit/local/outagelib_test.php index f7e380a..ba39c42 100644 --- a/tests/phpunit/local/outagelib_test.php +++ b/tests/phpunit/local/outagelib_test.php @@ -290,7 +290,7 @@ class outagelib_test extends advanced_testcase { public function test_createmaintenancephpcode() { $expected = <<<'EOT' = 123) { +if ((time() >= 123) && (time() < 456)) { define('MOODLE_INTERNAL', true); require_once($CFG->dirroot.'/lib/moodlelib.php'); if (!remoteip_in_list('heyyou @@ -330,7 +330,7 @@ EOT; $expected = <<<'EOT' = 123) { +if ((time() >= 123) && (time() < 456)) { define('MOODLE_INTERNAL', true); require_once($CFG->dirroot.'/lib/moodlelib.php'); if (!remoteip_in_list('127.0.0.1')) {