From 7d52bb9695902e746de3e0c289a8224e50dab291 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Mon, 24 Feb 2020 13:37:18 +1300 Subject: [PATCH 01/18] update readme to cover branch versions. --- README.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 590781e..a50c4d0 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,6 @@ * [Why is it an auth plugin?](#why-it-is-an-auth-plugin) * [Feedback and issues](#feedback-and-issues) -Version Support -------------- -The master branch supports Moodle 3.3 and higher. -The MOODLE_32_STABLE branch supports Moodle 2.7 -> Moodle 3.2 - What is this? ------------- @@ -45,6 +40,14 @@ If you have an older version of Moodle you can still make it work but you will need to manually add one extra plugin, please check: * https://github.com/catalyst/moodle-local_outage +Branches +-------- +| Moodle version | Branch | PHP | +| ----------------- | ----------- | ---- | +| Moodle 2.7 to 3.2 | MOODLE_32_STABLE | 5.5+ | +| Totara up to 10 | TOTARA_10 | 5.5+ | +| Moodle 3.3+ | master | 7.0+ | +| Totara 11+ | master | 7.0+ | Screenshots ----------- From bac83b143a2fa5be94a063409b2da75475f30762 Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Wed, 4 Mar 2020 13:03:44 +1100 Subject: [PATCH 02/18] Fix url parsing when Moodle is installed without subdir. --- bootstrap.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bootstrap.php b/bootstrap.php index 84f5b6b..50dbf40 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -69,7 +69,11 @@ if (is_callable('auth_outage_bootstrap_callback')) { // 3) Check for allowed scripts or IPs during outages. if (!empty($_SERVER['REQUEST_URI'])) { $rooturl = parse_url($CFG->wwwroot); - $url = $rooturl['path'].'/auth/outage/info.php'; + $path = ''; + if (array_key_exists('path', $rooturl) && !empty($rooturl['path'])) { + $path = $root['url']; + } + $url = $path.'/auth/outage/info.php'; $outageinfo = strpos($_SERVER['REQUEST_URI'], $url) === 0 ? true : false; } $allowed = !file_exists($CFG->dataroot.'/climaintenance.php') // Not in maintenance mode. From 4467bea1cf526317754b0bb5e1c01515b77f2ac4 Mon Sep 17 00:00:00 2001 From: katcher Date: Wed, 18 Mar 2020 09:17:19 -0400 Subject: [PATCH 03/18] Issue 189 Unable to find Class 'core\ip_utils' Following upgrade of moodle to 3.5.11, error above prevented moodle from displaying on the web. The class ip_utils was for somereason not loaded and through an error preventing the site from displaying when in maintenance mod. Adding the require class appears to have fixed the issue. --- classes/local/outagelib.php | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/local/outagelib.php b/classes/local/outagelib.php index 8a8b496..8af5aa9 100644 --- a/classes/local/outagelib.php +++ b/classes/local/outagelib.php @@ -269,6 +269,7 @@ class outagelib { if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) { define('MOODLE_INTERNAL', true); require_once($CFG->dirroot.'/lib/moodlelib.php'); + require_once($CFG->dirroot.'/lib/classes/ip_utils.php'); if (!remoteip_in_list('{{ALLOWEDIPS}}')) { header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance'); header('Status: 503 Moodle under maintenance'); From 777e466a0ad5e3c22eb63720d30c25fbee2c8d61 Mon Sep 17 00:00:00 2001 From: Peter Burnett Date: Wed, 25 Mar 2020 15:15:02 +1000 Subject: [PATCH 04/18] Issue #189: Updated unit tests --- tests/phpunit/local/outagelib_test.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/phpunit/local/outagelib_test.php b/tests/phpunit/local/outagelib_test.php index 40ec445..d5ecf60 100644 --- a/tests/phpunit/local/outagelib_test.php +++ b/tests/phpunit/local/outagelib_test.php @@ -289,6 +289,7 @@ class outagelib_test extends advanced_testcase { if ((time() >= 123) && (time() < 456)) { define('MOODLE_INTERNAL', true); require_once($CFG->dirroot.'/lib/moodlelib.php'); + require_once($CFG->dirroot.'/lib/classes/ip_utils.php'); if (!remoteip_in_list('hey\'\"you a.b.c.d e.e.e.e/20')) { @@ -330,6 +331,7 @@ EOT; if ((time() >= 123) && (time() < 456)) { define('MOODLE_INTERNAL', true); require_once($CFG->dirroot.'/lib/moodlelib.php'); + require_once($CFG->dirroot.'/lib/classes/ip_utils.php'); if (!remoteip_in_list('127.0.0.1')) { header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance'); header('Status: 503 Moodle under maintenance'); From e6a63f02e6bf0711c2f842bb2af475db54228b33 Mon Sep 17 00:00:00 2001 From: Brendan Heywood Date: Wed, 25 Mar 2020 21:35:53 +1100 Subject: [PATCH 05/18] Added missing lang string --- lang/en/auth_outage.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/en/auth_outage.php b/lang/en/auth_outage.php index 98fc5d1..ac1c164 100644 --- a/lang/en/auth_outage.php +++ b/lang/en/auth_outage.php @@ -125,6 +125,7 @@ $string['outagefinish'] = 'Finish outage'; $string['outagefinishwarning'] = 'You are about to mark this outage as finished. The system will be immediately back online.'; $string['outageslistfuture'] = 'Planned outages'; $string['outageslistpast'] = 'Outage history'; +$string['outage:updatenotify'] = ''; $string['pluginname'] = 'Outage manager'; $string['removeselectors'] = 'Remove selectors'; $string['removeselectorsdescription'] = 'CSS selectors to remove when rendering a static themed maintenance page. One selector per line.'; From 3b1b1ea0e1d0ec687acbd26e9498a605e032d05e Mon Sep 17 00:00:00 2001 From: Brendan Heywood Date: Wed, 25 Mar 2020 22:21:35 +1100 Subject: [PATCH 06/18] Allow default start time using cron syntax #163 --- classes/local/outagelib.php | 1 + edit.php | 18 ++++++++++++++++++ lang/en/auth_outage.php | 2 ++ settings.php | 7 +++++++ version.php | 4 ++-- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/classes/local/outagelib.php b/classes/local/outagelib.php index 8af5aa9..2e28ff8 100644 --- a/classes/local/outagelib.php +++ b/classes/local/outagelib.php @@ -152,6 +152,7 @@ class outagelib { return [ 'allowedips' => '', 'css' => '', + 'default_time' => '', 'default_autostart' => '0', 'default_duration' => (string)(60 * 60), 'default_warning_duration' => (string)(60 * 60), diff --git a/edit.php b/edit.php index 5cd25f8..d707989 100644 --- a/edit.php +++ b/edit.php @@ -61,6 +61,24 @@ if ($clone) { } else { $config = outagelib::get_config(); $time = time(); + + $default = $config->default_time; + if ($default) { + + // Lean on the Task API to convert the cron syntax to + // the next valid outage date and time. + $parts = explode(' ', $default); + if (count($parts) == 5) { + $task = new \core\task\calendar_cron_task(); + $task->set_minute($parts[0]); + $task->set_hour($parts[1]); + $task->set_day($parts[2]); + $task->set_month($parts[3]); + $task->set_day_of_week($parts[4]); + $time = $task->get_next_scheduled_time(); + } + } + $outage = new outage([ 'autostart' => $config->default_autostart, 'starttime' => $time, diff --git a/lang/en/auth_outage.php b/lang/en/auth_outage.php index ac1c164..3ea661e 100644 --- a/lang/en/auth_outage.php +++ b/lang/en/auth_outage.php @@ -80,6 +80,8 @@ $string['defaultoutageduration'] = 'Outage duration'; $string['defaultoutagedurationdescription'] = 'Default duration (in minutes) of an outage.'; $string['defaultwarningduration'] = 'Warning duration'; $string['defaultwarningdurationdescription'] = 'Default warning time (in minutes) for outages.'; +$string['defaulttime'] = 'Default time'; +$string['defaulttimedescription'] = 'The default time for the next outage. This is expressed in cron notation, eg to say that a regular outage window is any thursday at 7pm you would set this to:
0 19 * * 4
'; $string['defaulttitle'] = 'Title'; $string['defaulttitledescription'] = 'Default title for outages. Use {{start}} and {{stop}} placeholders as required.'; $string['defaulttitlevalue'] = 'System down from {{start}} for {{duration}}'; diff --git a/settings.php b/settings.php index 9c3be2c..c86670e 100644 --- a/settings.php +++ b/settings.php @@ -59,6 +59,13 @@ if ($hassiteconfig && is_enabled_auth('outage')) { $defaults['default_duration'], 60 )); + $settings->add(new admin_setting_configtext( + 'auth_outage/default_time', + get_string('defaulttime', 'auth_outage'), + get_string('defaulttimedescription', 'auth_outage'), + '', + PARAM_TEXT + )); $settings->add(new admin_setting_configtext( 'auth_outage/default_title', get_string('defaulttitle', 'auth_outage'), diff --git a/version.php b/version.php index b07af31..cd60ab6 100644 --- a/version.php +++ b/version.php @@ -28,7 +28,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = "auth_outage"; -$plugin->version = 2020021300; // The current plugin version (Date: YYYYMMDDXX). -$plugin->release = '1.0.11'; // Human-readable release information. +$plugin->version = 2020032500; // The current plugin version (Date: YYYYMMDDXX). +$plugin->release = 2020032500; // Human-readable release information. $plugin->requires = 2017051500; // Requires 3.3 and higher. $plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments! From 22b38c2838ce799cd448db2c5a94af5023323b3f Mon Sep 17 00:00:00 2001 From: Brendan Heywood Date: Thu, 26 Mar 2020 00:56:17 +1100 Subject: [PATCH 07/18] Accept natural language start times #163 --- edit.php | 3 +++ lang/en/auth_outage.php | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/edit.php b/edit.php index d707989..bbc6ad8 100644 --- a/edit.php +++ b/edit.php @@ -65,6 +65,9 @@ if ($clone) { $default = $config->default_time; if ($default) { + // First try natural language parsing. + $time = strtotime($default); + // Lean on the Task API to convert the cron syntax to // the next valid outage date and time. $parts = explode(' ', $default); diff --git a/lang/en/auth_outage.php b/lang/en/auth_outage.php index 3ea661e..ae585aa 100644 --- a/lang/en/auth_outage.php +++ b/lang/en/auth_outage.php @@ -81,7 +81,10 @@ $string['defaultoutagedurationdescription'] = 'Default duration (in minutes) of $string['defaultwarningduration'] = 'Warning duration'; $string['defaultwarningdurationdescription'] = 'Default warning time (in minutes) for outages.'; $string['defaulttime'] = 'Default time'; -$string['defaulttimedescription'] = 'The default time for the next outage. This is expressed in cron notation, eg to say that a regular outage window is any thursday at 7pm you would set this to:
0 19 * * 4
'; +$string['defaulttimedescription'] = 'The default time for the next outage. This is expressed in either natural language or a cron notation. eg to say that a regular outage window is any Thursday at 7pm either of these work: +
0 19 * * 4
+next Thursday 7pm
+See also Cron expressions and Relative dates'; $string['defaulttitle'] = 'Title'; $string['defaulttitledescription'] = 'Default title for outages. Use {{start}} and {{stop}} placeholders as required.'; $string['defaulttitlevalue'] = 'System down from {{start}} for {{duration}}'; From 9ed0b741126ed46b7db6afc4ce9a900592ea4405 Mon Sep 17 00:00:00 2001 From: Brendan Heywood Date: Thu, 26 Mar 2020 01:30:03 +1100 Subject: [PATCH 08/18] Added next 3 available window button for new outages #163 --- classes/form/outage/edit.php | 3 ++- classes/local/outagelib.php | 34 ++++++++++++++++++++++++++++++++++ edit.php | 23 +++-------------------- views/manage.php | 22 ++++++++++++++++++---- 4 files changed, 57 insertions(+), 25 deletions(-) diff --git a/classes/form/outage/edit.php b/classes/form/outage/edit.php index b37df11..d27d77d 100644 --- a/classes/form/outage/edit.php +++ b/classes/form/outage/edit.php @@ -164,7 +164,8 @@ class edit extends moodleform { 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')); + $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 2e28ff8..a6dceda 100644 --- a/classes/local/outagelib.php +++ b/classes/local/outagelib.php @@ -79,6 +79,40 @@ class outagelib { self::inject(); } + /** + * Given a time, usually now, when is the next outage window? + */ + public static function get_next_window($time = null) { + + $config = self::get_config(); + + if (!$time) { + $time = time(); + } + + $default = $config->default_time; + if ($default) { + + // First try natural language parsing. + $time = strtotime($default, $time); + + // Lean on the Task API to convert the cron syntax to + // the next valid outage date and time. + $parts = explode(' ', $default); + if (count($parts) == 5) { + $task = new \core\task\calendar_cron_task(); + $task->set_minute($parts[0]); + $task->set_hour($parts[1]); + $task->set_day($parts[2]); + $task->set_month($parts[3]); + $task->set_day_of_week($parts[4]); + $time = $task->get_next_scheduled_time(); + } + } + return $time; + } + + /** * Will check for ongoing or warning outages and will attach the message bar as required. */ diff --git a/edit.php b/edit.php index bbc6ad8..e2b0e18 100644 --- a/edit.php +++ b/edit.php @@ -47,6 +47,7 @@ if ($mform->is_cancelled()) { $clone = optional_param('clone', 0, PARAM_INT); $edit = optional_param('edit', 0, PARAM_INT); +$time = optional_param('starttime', 0, PARAM_INT); if ($clone && $edit) { throw new invalid_parameter_exception('Cannot provide both clone and edit ids.'); } @@ -60,26 +61,8 @@ if ($clone) { $action = 'outageedit'; } else { $config = outagelib::get_config(); - $time = time(); - - $default = $config->default_time; - if ($default) { - - // First try natural language parsing. - $time = strtotime($default); - - // Lean on the Task API to convert the cron syntax to - // the next valid outage date and time. - $parts = explode(' ', $default); - if (count($parts) == 5) { - $task = new \core\task\calendar_cron_task(); - $task->set_minute($parts[0]); - $task->set_hour($parts[1]); - $task->set_day($parts[2]); - $task->set_month($parts[3]); - $task->set_day_of_week($parts[4]); - $time = $task->get_next_scheduled_time(); - } + if (empty($time)) { + $time = outagelib::get_next_window(); } $outage = new outage([ diff --git a/views/manage.php b/views/manage.php index 52c856c..f2fee40 100644 --- a/views/manage.php +++ b/views/manage.php @@ -27,6 +27,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; +use auth_outage\local\outagelib; defined('MOODLE_INTERNAL') || die(); @@ -49,10 +50,23 @@ echo $viewbag['warning']; $table->finish_output(); ?> - - - single_button($urlnew, get_string('outagecreate', 'auth_outage')); ?> - + default_time; + $max = $default ? 3 : 1; + $next = time(); + for ($c = 0; $c < $max; $c++) { + echo '

'; + $next = outagelib::get_next_window($next); + $urlnew->param('starttime', $next); + echo $OUTPUT->single_button($urlnew, get_string('outagecreate', 'auth_outage')); + if ($default) { + echo ' ' . userdate( $next, get_string('datetimeformat', 'auth_outage')); + } + } + endif; ?>

From afc81edfde1825e3e01c0ac4e48740e625351527 Mon Sep 17 00:00:00 2001 From: Brendan Heywood Date: Thu, 26 Mar 2020 01:40:06 +1100 Subject: [PATCH 09/18] Removed support for cron syntax #163 --- classes/local/outagelib.php | 14 -------------- lang/en/auth_outage.php | 5 +---- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/classes/local/outagelib.php b/classes/local/outagelib.php index a6dceda..57a0e49 100644 --- a/classes/local/outagelib.php +++ b/classes/local/outagelib.php @@ -92,22 +92,8 @@ class outagelib { $default = $config->default_time; if ($default) { - // First try natural language parsing. $time = strtotime($default, $time); - - // Lean on the Task API to convert the cron syntax to - // the next valid outage date and time. - $parts = explode(' ', $default); - if (count($parts) == 5) { - $task = new \core\task\calendar_cron_task(); - $task->set_minute($parts[0]); - $task->set_hour($parts[1]); - $task->set_day($parts[2]); - $task->set_month($parts[3]); - $task->set_day_of_week($parts[4]); - $time = $task->get_next_scheduled_time(); - } } return $time; } diff --git a/lang/en/auth_outage.php b/lang/en/auth_outage.php index ae585aa..9f27c96 100644 --- a/lang/en/auth_outage.php +++ b/lang/en/auth_outage.php @@ -81,10 +81,7 @@ $string['defaultoutagedurationdescription'] = 'Default duration (in minutes) of $string['defaultwarningduration'] = 'Warning duration'; $string['defaultwarningdurationdescription'] = 'Default warning time (in minutes) for outages.'; $string['defaulttime'] = 'Default time'; -$string['defaulttimedescription'] = 'The default time for the next outage. This is expressed in either natural language or a cron notation. eg to say that a regular outage window is any Thursday at 7pm either of these work: -
0 19 * * 4
-next Thursday 7pm
-See also Cron expressions and Relative dates'; +$string['defaulttimedescription'] = 'The default time for the next outage, expressed in natural language eg "next Thursday 7pm". See PHP relative dates'; $string['defaulttitle'] = 'Title'; $string['defaulttitledescription'] = 'Default title for outages. Use {{start}} and {{stop}} placeholders as required.'; $string['defaulttitlevalue'] = 'System down from {{start}} for {{duration}}'; From 73f283847a8d43e3963768f77880397db006c385 Mon Sep 17 00:00:00 2001 From: Peter Burnett Date: Thu, 26 Mar 2020 12:04:00 +1000 Subject: [PATCH 10/18] Changed require statement to check file exists --- classes/local/outagelib.php | 4 +++- tests/phpunit/local/outagelib_test.php | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/classes/local/outagelib.php b/classes/local/outagelib.php index 2e28ff8..6671556 100644 --- a/classes/local/outagelib.php +++ b/classes/local/outagelib.php @@ -270,7 +270,9 @@ class outagelib { if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) { define('MOODLE_INTERNAL', true); require_once($CFG->dirroot.'/lib/moodlelib.php'); - require_once($CFG->dirroot.'/lib/classes/ip_utils.php'); + if (file_exists($CFG->dirroot.'/lib/classes/ip_utils.php')) { + require_once($CFG->dirroot.'/lib/classes/ip_utils.php'); + } if (!remoteip_in_list('{{ALLOWEDIPS}}')) { header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance'); header('Status: 503 Moodle under maintenance'); diff --git a/tests/phpunit/local/outagelib_test.php b/tests/phpunit/local/outagelib_test.php index d5ecf60..0e04866 100644 --- a/tests/phpunit/local/outagelib_test.php +++ b/tests/phpunit/local/outagelib_test.php @@ -289,7 +289,9 @@ class outagelib_test extends advanced_testcase { if ((time() >= 123) && (time() < 456)) { define('MOODLE_INTERNAL', true); require_once($CFG->dirroot.'/lib/moodlelib.php'); - require_once($CFG->dirroot.'/lib/classes/ip_utils.php'); + if (file_exists($CFG->dirroot.'/lib/classes/ip_utils.php')) { + require_once($CFG->dirroot.'/lib/classes/ip_utils.php'); + } if (!remoteip_in_list('hey\'\"you a.b.c.d e.e.e.e/20')) { @@ -331,7 +333,9 @@ EOT; if ((time() >= 123) && (time() < 456)) { define('MOODLE_INTERNAL', true); require_once($CFG->dirroot.'/lib/moodlelib.php'); - require_once($CFG->dirroot.'/lib/classes/ip_utils.php'); + if (file_exists($CFG->dirroot.'/lib/classes/ip_utils.php')) { + require_once($CFG->dirroot.'/lib/classes/ip_utils.php'); + } if (!remoteip_in_list('127.0.0.1')) { header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance'); header('Status: 503 Moodle under maintenance'); From bf242d9e65e7021ec183c5d2d21efd5c439cc949 Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Wed, 8 Apr 2020 16:49:47 +1000 Subject: [PATCH 11/18] Set CFG->svgicons to true on info page #194. --- classes/local/controllers/infopage.php | 5 +++++ tests/phpunit/local/controllers/infopage_test.php | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/classes/local/controllers/infopage.php b/classes/local/controllers/infopage.php index 4c691d4..a1be30e 100644 --- a/classes/local/controllers/infopage.php +++ b/classes/local/controllers/infopage.php @@ -53,6 +53,11 @@ class infopage { * @param array $params Parameters to use or null to get from Moodle API (request). */ public function __construct(array $params = null) { + global $CFG; + // Enable SVG support here to make sure all SVG files + // used in the current theme are served properly. + $CFG->svgicons = true; + if (is_null($params)) { $params = [ 'id' => optional_param('id', null, PARAM_INT), diff --git a/tests/phpunit/local/controllers/infopage_test.php b/tests/phpunit/local/controllers/infopage_test.php index 1041175..9c3bc5a 100644 --- a/tests/phpunit/local/controllers/infopage_test.php +++ b/tests/phpunit/local/controllers/infopage_test.php @@ -106,4 +106,14 @@ class infopagecontroller_test extends auth_outage_base_testcase { $output = $info->get_output(); self::assertContains('auth_outage_info', $output); } + + /** + * Tests the constructor enables SVG support. + */ + public function test_svgicons_is_true() { + global $CFG; + $CFG->svgicons = false; + new infopage(); + self::assertTrue($CFG->svgicons); + } } From 5a53bf04a1779cf0b0bc6c888efe596b1c2b87e2 Mon Sep 17 00:00:00 2001 From: Brendan Heywood Date: Fri, 19 Jun 2020 09:17:39 +1000 Subject: [PATCH 12/18] Fixed bug with moodles under a subdir #196 --- bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap.php b/bootstrap.php index 50dbf40..b06e11a 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -71,7 +71,7 @@ if (!empty($_SERVER['REQUEST_URI'])) { $rooturl = parse_url($CFG->wwwroot); $path = ''; if (array_key_exists('path', $rooturl) && !empty($rooturl['path'])) { - $path = $root['url']; + $path = $rooturl['url']; } $url = $path.'/auth/outage/info.php'; $outageinfo = strpos($_SERVER['REQUEST_URI'], $url) === 0 ? true : false; From 32412c25800da85d72aeba254bf40ba0651bfd97 Mon Sep 17 00:00:00 2001 From: Brendan Heywood Date: Fri, 19 Jun 2020 09:51:27 +1000 Subject: [PATCH 13/18] Fixed travis node issue --- .travis.yml | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6ff61a9..c13e5f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,29 +20,23 @@ php: - 7.2 env: - - DB=pgsql MOODLE_BRANCH=master + - DB=pgsql MOODLE_BRANCH=MOODLE_36_STABLE NODEJS=8 + - DB=mysqli MOODLE_BRANCH=MOODLE_36_STABLE NODEJS=8 + - DB=pgsql MOODLE_BRANCH=MOODLE_37_STABLE + - DB=pgsql MOODLE_BRANCH=MOODLE_38_STABLE + - DB=pgsql MOODLE_BRANCH=MOODLE_39_STABLE + - DB=mysqli MOODLE_BRANCH=MOODLE_39_STABLE + - DB=pgsql MOODLE_BRANCH=master - DB=mysqli MOODLE_BRANCH=master - - DB=pgsql MOODLE_BRANCH=MOODLE_38_STABLE - - DB=mysqli MOODLE_BRANCH=MOODLE_38_STABLE - - DB=pgsql MOODLE_BRANCH=MOODLE_37_STABLE - - DB=mysqli MOODLE_BRANCH=MOODLE_37_STABLE - - DB=pgsql MOODLE_BRANCH=MOODLE_36_STABLE - - DB=mysqli MOODLE_BRANCH=MOODLE_36_STABLE matrix: include: - - php: 7.1 - env: DB=pgsql MOODLE_BRANCH=MOODLE_35_STABLE - - php: 7.1 + - php: 5.6 + env: DB=pgsql MOODLE_BRANCH=MOODLE_33_STABLE NODEJS=8 + - php: 7.0 env: DB=mysqli MOODLE_BRANCH=MOODLE_35_STABLE - - php: 7.0 - env: DB=pgsql MOODLE_BRANCH=MOODLE_34_STABLE - - php: 7.0 - env: DB=mysqli MOODLE_BRANCH=MOODLE_34_STABLE - - php: 5.6 - env: DB=pgsql MOODLE_BRANCH=MOODLE_33_STABLE - - php: 5.6 - env: DB=mysqli MOODLE_BRANCH=MOODLE_33_STABLE + - php: 7.1 + env: DB=mysqli MOODLE_BRANCH=MOODLE_33_STABLE NODEJS=8 before_install: - export MOODLE_VERSION=$(echo "$MOODLE_BRANCH" | cut -d'_' -f 2) @@ -51,8 +45,13 @@ before_install: sudo /etc/init.d/postgresql start 9.5; fi - phpenv config-rm xdebug.ini - - nvm install 8.9 - - nvm use 8.9 + - if [ "$NODEJS" = 8 ]; then + nvm install 8.9; + nvm use 8.9; + else + nvm install 14.0.0; + nvm use 14.0.0; + fi - cd ../.. - composer selfupdate - composer create-project -n --no-dev --prefer-dist blackboard-open-source/moodle-plugin-ci ci ^2 @@ -74,4 +73,4 @@ script: # Behat tests are failing due to issue: # https://github.com/blackboard-open-source/moodle-plugin-ci/issues/70 # Commenting it out until the issue is fixed. -# - moodle-plugin-ci behat \ No newline at end of file +# - moodle-plugin-ci behat From 6f65ff9199ed01385f849812eeb32c2665b50c69 Mon Sep 17 00:00:00 2001 From: Nicholas Hoobin Date: Mon, 6 Jul 2020 14:20:51 +1000 Subject: [PATCH 14/18] Issue #201: Resolve unit test failures with PHP7.4 --- classes/local/controllers/maintenance_static_page_generator.php | 2 +- classes/local/controllers/maintenance_static_page_io.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/local/controllers/maintenance_static_page_generator.php b/classes/local/controllers/maintenance_static_page_generator.php index d58e87b..986750a 100644 --- a/classes/local/controllers/maintenance_static_page_generator.php +++ b/classes/local/controllers/maintenance_static_page_generator.php @@ -128,7 +128,7 @@ class maintenance_static_page_generator { continue; } $saved = $this->io->save_url_file($href); - if (is_null($saved['url'])) { + if (empty($saved['url'])) { $url = $href; // Skipped, use original URL. } else { $this->update_link_stylesheet_parse($saved['file'], dirname($href)); diff --git a/classes/local/controllers/maintenance_static_page_io.php b/classes/local/controllers/maintenance_static_page_io.php index a5dbb40..eeafb53 100644 --- a/classes/local/controllers/maintenance_static_page_io.php +++ b/classes/local/controllers/maintenance_static_page_io.php @@ -213,7 +213,7 @@ class maintenance_static_page_io { /** * Saves the content of the URL into a file, returning the local filename. * @param string $url Input URL. - * @return string|null Output filename or null if skipped. + * @return array|null Output an array with the filename and url or null if skipped. */ public function save_url_file($url) { global $CFG; From c4f9945c219afe8868659329cf9c2a3c0ef0ea85 Mon Sep 17 00:00:00 2001 From: Nicholas Hoobin Date: Mon, 6 Jul 2020 16:40:04 +1000 Subject: [PATCH 15/18] Issue #201: Update travis to check against PHP7.4 Travis, PGSQL 9.5. Default distro. PHP 7.4 check added on M39/master. --- .travis.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index c13e5f7..b2023cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,15 +2,16 @@ language: php sudo: true +services: + - mysql + addons: firefox: "47.0.1" - postgresql: "9.4" + postgresql: "9.5" apt: packages: - openjdk-8-jre -dist: trusty - cache: directories: - $HOME/.composer/cache @@ -26,8 +27,6 @@ env: - DB=pgsql MOODLE_BRANCH=MOODLE_38_STABLE - DB=pgsql MOODLE_BRANCH=MOODLE_39_STABLE - DB=mysqli MOODLE_BRANCH=MOODLE_39_STABLE - - DB=pgsql MOODLE_BRANCH=master - - DB=mysqli MOODLE_BRANCH=master matrix: include: @@ -37,13 +36,13 @@ matrix: env: DB=mysqli MOODLE_BRANCH=MOODLE_35_STABLE - php: 7.1 env: DB=mysqli MOODLE_BRANCH=MOODLE_33_STABLE NODEJS=8 + - php: 7.4 + env: DB=mysqli MOODLE_BRANCH=master + - php: 7.4 + env: DB=pgsql MOODLE_BRANCH=master before_install: - export MOODLE_VERSION=$(echo "$MOODLE_BRANCH" | cut -d'_' -f 2) - - if [ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ] && [ $DB == "pgsql" ] && [[ "$MOODLE_VERSION" -gt 38 || "$MOODLE_VERSION" == "master" ]] ; then - sudo /etc/init.d/postgresql stop; - sudo /etc/init.d/postgresql start 9.5; - fi - phpenv config-rm xdebug.ini - if [ "$NODEJS" = 8 ]; then nvm install 8.9; From 2b249ac03688da290bb136cd9f403e5291b13e62 Mon Sep 17 00:00:00 2001 From: Nicholas Hoobin Date: Fri, 11 Sep 2020 15:43:52 +1000 Subject: [PATCH 16/18] WR #343135: Update tests to work with T12. For some reason, $this->resetAfterTest(true); is not resetting the outage table in T12 (probably T11/13 too) --- tests/phpunit/base_testcase.php | 10 ++++++++++ tests/phpunit/local/outagelib_test.php | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/base_testcase.php b/tests/phpunit/base_testcase.php index 0e71ed1..307a0c4 100644 --- a/tests/phpunit/base_testcase.php +++ b/tests/phpunit/base_testcase.php @@ -31,6 +31,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use auth_outage\dml\outagedb; + defined('MOODLE_INTERNAL') || die(); /** @@ -70,4 +72,12 @@ abstract class auth_outage_base_testcase extends advanced_testcase { parent::setUp(); $this->resetAfterTest(true); } + + public function tearDown() { + global $DB; + + foreach (outagedb::get_all() as $i => $outage) { + $DB->delete_records('auth_outage', ['id' => $outage->id]); + } + } } diff --git a/tests/phpunit/local/outagelib_test.php b/tests/phpunit/local/outagelib_test.php index 0e04866..6fd2875 100644 --- a/tests/phpunit/local/outagelib_test.php +++ b/tests/phpunit/local/outagelib_test.php @@ -31,6 +31,7 @@ defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->libdir.'/adminlib.php'); +require_once(__DIR__.'/../base_testcase.php'); /** * outagelib_test test class. @@ -41,7 +42,7 @@ require_once($CFG->libdir.'/adminlib.php'); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @SuppressWarnings(public) Allow as many methods as needed. */ -class outagelib_test extends advanced_testcase { +class outagelib_test extends auth_outage_base_testcase { /** * Check if maintenance message is disabled as needed. */ From 0efb9acbd1835a00eb57d529c15d7bbc9afb103b Mon Sep 17 00:00:00 2001 From: Nicholas Hoobin Date: Fri, 11 Sep 2020 16:04:04 +1000 Subject: [PATCH 17/18] Begin the song and dance of travis. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b2023cf..49eb20c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ services: addons: firefox: "47.0.1" - postgresql: "9.5" + postgresql: "9.6" apt: packages: - openjdk-8-jre From 6113b48866bba4af0cfd56a4d591d6666a4960cb Mon Sep 17 00:00:00 2001 From: Nicholas Hoobin Date: Wed, 16 Sep 2020 12:32:11 +1000 Subject: [PATCH 18/18] Issue #207: Use Moodle curl to honor proxy settings --- classes/local/outagelib.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/classes/local/outagelib.php b/classes/local/outagelib.php index d5e9e9a..b450bd1 100644 --- a/classes/local/outagelib.php +++ b/classes/local/outagelib.php @@ -29,6 +29,7 @@ use auth_outage\dml\outagedb; use auth_outage\local\controllers\maintenance_static_page; use auth_outage\output\renderer; use coding_exception; +use curl; use Exception; use file_exception; use invalid_parameter_exception; @@ -58,16 +59,14 @@ class outagelib { private static $injectcalled = false; public static function fetch_page($file) { - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $file); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); // It is localhost, time to connect is enough. - curl_setopt($curl, CURLOPT_TIMEOUT, 60); - $contents = curl_exec($curl); - $mime = curl_getinfo($curl, CURLINFO_CONTENT_TYPE); - curl_close($curl); + $curl = new curl(); + $contents = $curl->get($file); + $info = $curl->get_info(); + if (!empty($info['content_type'])) { + $mime = $info['content_type']; + } else { + $mime = ''; + } return compact('contents', 'mime'); }