Issue #50 - Automatically unset maintenance_message and log an error if it had something.

This commit is contained in:
Daniel Thee Roperto
2016-09-26 12:00:15 +10:00
parent b79a70d122
commit 619a5a663f
2 changed files with 59 additions and 0 deletions

View File

@@ -132,6 +132,15 @@ class outagelib {
if (is_null($next)) {
unset_config('maintenance_later');
} else {
$message = get_config('moodle', 'maintenance_message');
if ($message) {
if (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST) {
error_log('Disabling $CFG->maintenance_message to allow our template page to take place.');
error_log('Previous value: '.$message);
}
// We cannot do much if forced config, but the logs will show the error.
unset_config('maintenance_message');
}
set_config('maintenance_later', $next->starttime);
}
}

View File

@@ -0,0 +1,50 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
defined('MOODLE_INTERNAL') || die();
/**
* Tests performed on outagelib class.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class outagelib_test extends advanced_testcase {
public function test_maintenancemessage() {
global $CFG;
$this->resetAfterTest(true);
static::setAdminUser();
$now = time();
$outage = new outage([
'autostart' => true,
'warntime' => $now,
'starttime' => $now + 100,
'stoptime' => $now + 200,
'title' => 'Title',
'description' => 'Description',
]);
set_config('maintenance_message', 'A message.');
outagedb::save($outage);
self::assertFalse((bool)get_config('moodle', 'maintenance_message'));
}
}