Merge pull request #311 from QihuiChan/logging-maint-mode

Add logging for maint mode and fix failed CI tests
This commit is contained in:
Brendan Heywood
2022-12-21 12:23:09 +11:00
committed by GitHub
7 changed files with 53 additions and 9 deletions

View File

@@ -164,7 +164,7 @@ class edit extends moodleform {
// If the default_autostart is configured in config, then force autostart to be the default value.
if (array_key_exists('auth_outage', $CFG->forced_plugin_settings)
&& array_key_exists('default_autostart', $CFG->forced_plugin_settings['auth_outage'])){
&& array_key_exists('default_autostart', $CFG->forced_plugin_settings['auth_outage'])) {
$this->_form->setDefaults([
'autostart' => $CFG->forced_plugin_settings['auth_outage']['default_autostart']
]);

View File

@@ -246,6 +246,7 @@ class outagelib {
unset_config('maintenance_message');
}
set_config('maintenance_later', $outage->starttime);
self::maintenance_config_log($outage);
}
}
@@ -414,4 +415,18 @@ EOT;
return $message;
}
/**
* Logging for maintenance mode configuration.
*
* @param outage|null $outage Outage or null if no scheduled outage.
*/
private static function maintenance_config_log(outage $outage) {
mtrace(get_string('logformaintmodeconfig', 'auth_outage'));
$timezone = ' (Timezone ' . \core_date::get_server_timezone_object()->getName() . ')';
mtrace('... updated at ' . date('H:i:s'));
$time = date("Y-m-d H:i:s", $outage->starttime);
mtrace("... enable maintenance mode at $time $timezone");
mtrace(get_string('logformaintmodeconfigcomplete', 'auth_outage'));
}
}

View File

@@ -107,6 +107,8 @@ $string['allowedipsempty'] = 'When the allowed IPs list is empty we will not blo
$string['allowedipshasmyip'] = 'Your IP (<i>{$a->ip}</i>) is in the list and you will not be blocked out during an Outage.';
$string['allowedipshasntmyip'] = 'Your IP (<i>{$a->ip}</i>) is not in the list and you will be blocked out during an outage.';
$string['allowedipsnoconfig'] = 'Your config.php does not have the extra setup to allow blocking via IP.<br />Please refer to our <a href="https://github.com/catalyst/moodle-auth_outage#installation" target="_blank">README.md</a> file for more information.';
$string['logformaintmodeconfig'] = 'Update maintenance mode configuration.';
$string['logformaintmodeconfigcomplete'] = 'Updating maintenance mode configuration complete.';
$string['menusettings'] = 'Settings';
$string['menumanage'] = 'Manage outages';
$string['messageoutagebackonline'] = 'We are back online!';

View File

@@ -63,7 +63,11 @@ class auth_outage_installation_test extends auth_outage_base_testcase {
'title' => 'Title',
'description' => 'Description',
]);
ob_start();
\auth_outage\dml\outagedb::save($outage);
$text = trim(ob_get_contents());
ob_end_clean();
self::assertStringContainsString('Update maintenance mode configuration', $text);
self::assertSame(1, $DB->count_records_select('event', "eventtype = 'auth_outage'", null));
// Uninstall plugin.

View File

@@ -159,8 +159,8 @@ class auth_outage_create_test extends auth_outage_cli_testcase {
$text = $this->execute($cli);
self::assertStringContainsString('created', $text);
// Check creted outage.
list(, $id) = explode(':', $text);
$id = (int)$id;
$clioutput = explode(':', $text);
$id = (int)end($clioutput);
$outage = outagedb::get_by_id($id);
self::assertSame($now, $outage->starttime);
self::assertSame(10, $outage->get_warning_duration());
@@ -223,8 +223,8 @@ class auth_outage_create_test extends auth_outage_cli_testcase {
$text = $this->execute($cli);
self::assertStringContainsString('created', $text);
// Check creted outage.
list(, $id) = explode(':', $text);
$id = (int)$id;
$clioutput = explode(':', $text);
$id = (int)end($clioutput);
$outage = outagedb::get_by_id($id);
self::assertSame($now + 50, $outage->starttime, 'Wrong starttime.');
self::assertSame($outage->starttime - 100, $outage->warntime, 'Wrong warntime.');

View File

@@ -60,7 +60,11 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
]);
set_config('maintenance_message', 'A message.');
ob_start();
outagedb::save($outage);
$text = trim(ob_get_contents());
ob_end_clean();
self::assertStringContainsString('Update maintenance mode configuration', $text);
self::assertFalse((bool)get_config('moodle', 'maintenance_message'));
self::assertCount(2, $this->getDebuggingMessages());
$this->resetDebugging();
@@ -94,7 +98,11 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
'title' => 'Title',
'description' => 'Description',
]);
ob_start();
$outage->id = outagedb::save($outage);
$text = trim(ob_get_contents());
ob_end_clean();
self::assertStringContainsString('Update maintenance mode configuration', $text);
outagelib::reset_injectcalled();
// Get full header to avoid interactions with other single inject plugins.
@@ -136,7 +144,11 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
'title' => 'Title',
'description' => 'Description',
]);
ob_start();
$outage->id = outagedb::save($outage);
$text = trim(ob_get_contents());
ob_end_clean();
self::assertStringContainsString('Update maintenance mode configuration', $text);
$_GET = ['auth_outage_preview' => (string)$outage->id];
@@ -175,8 +187,11 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
'title' => 'Title',
'description' => 'Description',
]);
ob_start();
$outage->id = outagedb::save($outage);
$text = trim(ob_get_contents());
ob_end_clean();
self::assertStringContainsString('Update maintenance mode configuration', $text);
$_GET = ['auth_outage_preview' => (string)$outage->id, 'auth_outage_delta' => '500'];
outagelib::reset_injectcalled();
$header = outagelib::get_inject_code();
@@ -282,7 +297,11 @@ class auth_outage_outagelib_test extends auth_outage_base_testcase {
'title' => 'Title',
'description' => 'Description',
]);
ob_start();
$outage->id = outagedb::save($outage);
$text = trim(ob_get_contents());
ob_end_clean();
self::assertStringContainsString('Update maintenance mode configuration', $text);
// Pretend we are there...
$_SERVER['SCRIPT_FILENAME'] = '/var/www/alternativepath/admin/settings.php'; // Issue #88 regression test.
@@ -341,6 +360,7 @@ EOT;
/**
* Test create maintenance php code without age
*
* @param string $configkey The key of the config.
* @dataProvider test_createmaintenancephpcode_withoutage_provider
*/
public function test_createmaintenancephpcode_withoutage($configkey) {
@@ -538,8 +558,11 @@ EOT;
'title' => 'Title',
'description' => 'Description',
]);
ob_start();
$outage->id = outagedb::save($outage);
$text = trim(ob_get_contents());
ob_end_clean();
self::assertStringContainsString('Update maintenance mode configuration', $text);
// Pretend we are there...
$_SERVER['SCRIPT_FILENAME'] = '/var/www/alternativepath/admin/settings.php'; // Issue #88 regression test.
$_SERVER['SCRIPT_NAME'] = '/admin/settings.php';

View File

@@ -28,8 +28,8 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = "auth_outage";
$plugin->version = 2022051200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2022051200; // Human-readable release information.
$plugin->version = 2022121900; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2022121900; // Human-readable release information.
$plugin->requires = 2017111309; // 2017111309 = T13, but this really requires 3.9 and higher.
$plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments!
$plugin->supported = [39, 311]; // A range of branch numbers of supported moodle versions.