mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-09-07 08:11:07 +02:00
Compare commits
36
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9bab491666 | ||
|
|
20fef09b03 | ||
|
|
f2b7d1c7dd | ||
|
|
f0f3112ea1 | ||
|
|
0ac6b14ed1 | ||
|
|
b2c3fbd7b2 | ||
|
|
840d2c39d9 | ||
|
|
ddd56cd93f | ||
|
|
7d779f8fe9 | ||
|
|
ac29a02402 | ||
|
|
ffda33329c | ||
|
|
0bff6f5145 | ||
|
|
bffd5f39f9 | ||
|
|
fcb2a681e7 | ||
|
|
59a62c4aa4 | ||
|
|
073a682b01 | ||
|
|
da18e31dab | ||
|
|
1ef47a6233 | ||
|
|
551a97142c | ||
|
|
ceee32d889 | ||
|
|
149223d10f | ||
|
|
42b6ec3c87 | ||
|
|
6792b03ab0 | ||
|
|
7f968b2365 | ||
|
|
42dbec5b4d | ||
|
|
5d064a0bec | ||
|
|
d16ae47a5f | ||
|
|
1e3572be9f | ||
|
|
0222741c3d | ||
|
|
611c7a000c | ||
|
|
f994a97a7d | ||
|
|
da0f7c5865 | ||
|
|
da080f8d65 | ||
|
|
b01dd8723e | ||
|
|
99452cb4f3 | ||
|
|
6e70c45547 |
+1
-2
@@ -98,9 +98,8 @@ Execute the commands from your Moodle instalation directory and leave the browse
|
||||
1) Create an outage
|
||||
|
||||
This command will create an outage starting in 30 seconds, with a warning period of 15 seconds.
|
||||
It will automatically start (trigger maintenance mode).
|
||||
|
||||
`php auth/outage/cli/create.php -w=20 -s=30 --autostart=Y`
|
||||
`php auth/outage/cli/create.php -w=20 -s=30`
|
||||
|
||||
Refresh the page but you will not see anything yet.
|
||||
|
||||
|
||||
@@ -40,14 +40,19 @@ 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 supported branches
|
||||
--------
|
||||
| Moodle version | Totara | Branch | PHP |
|
||||
| ------------------ | --------------- | ---------------- | ---- |
|
||||
| Moodle 3.9+ | Totara 13+ | MOODLE_39_STABLE | 7.2+ |
|
||||
| Moodle 3.3 to 3.8 | Totara 11 to 12 | MOODLE_38_STABLE | 7.1+ |
|
||||
| Moodle 2.7 to 3.2 | | MOODLE_32_STABLE | 5.5+ |
|
||||
| | Totara up to 10 | TOTARA_10 | 5.5+ |
|
||||
| Version | Branch | PHP |
|
||||
|-------------|-------------------|------|
|
||||
| Moodle 3.9+ | MOODLE_39_STABLE | 7.2+ |
|
||||
|
||||
Totara supported branches
|
||||
--------
|
||||
| Version | Branch | PHP |
|
||||
| --------------- | ---------------- | ---- |
|
||||
| Totara 19 | TOTARA_19 | 7.2+ |
|
||||
| Totara 13-18 | MOODLE_39_STABLE | 7.2+ |
|
||||
|
||||
|
||||
Screenshots
|
||||
-----------
|
||||
@@ -162,7 +167,6 @@ Creates a new outage.
|
||||
|
||||
-h, --help shows parameters help.
|
||||
-c, --clone clone another outage except for the start time.
|
||||
-a, --autostart must be Y or N, sets if the outage automatically triggers maintenance mode.
|
||||
-w, --warn how many seconds before it starts to display a warning.
|
||||
-s, --start in how many seconds should this outage start or unix time to start outage. Required.
|
||||
-d, --duration how many seconds should the outage last.
|
||||
|
||||
+3
-2
@@ -29,9 +29,10 @@
|
||||
*
|
||||
* @var stdClass $CFG
|
||||
*/
|
||||
|
||||
define('MOODLE_INTERNAL', true);
|
||||
defined('MOODLE_INTERNAL') || die(); // Make sniffer happy.
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
//
|
||||
// We need the CFG->dataroot, if not set yet this script is called too early in config.php file.
|
||||
if (!isset($CFG->dataroot)) {
|
||||
|
||||
@@ -342,37 +342,6 @@ class outagedb {
|
||||
return (count($data) == 0) ? null : new outage(array_shift($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next outage which has not started yet and has the autostart flag set to true.
|
||||
* @param null $time Timestamp reference for current time.
|
||||
* @return outage|null The outage or null if not found.
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public static function get_next_autostarting($time = null) {
|
||||
global $DB;
|
||||
|
||||
if ($time === null) {
|
||||
$time = time();
|
||||
}
|
||||
if (!is_int($time) || ($time <= 0)) {
|
||||
throw new coding_exception('$time must be null or a positive int.', $time);
|
||||
}
|
||||
|
||||
$data = $DB->get_records_select(
|
||||
'auth_outage',
|
||||
'(:datetime <= starttime) AND (autostart = 1)',
|
||||
['datetime' => $time],
|
||||
'starttime ASC',
|
||||
'*',
|
||||
0,
|
||||
1
|
||||
);
|
||||
|
||||
// Not using $DB->get_record_select instead because there is no 'limit' parameter.
|
||||
// Allowing multiple records still raises an internal error.
|
||||
return (count($data) == 0) ? null : new outage(array_shift($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an ongoing outage (between start and stop time but not finished).
|
||||
* @param int|null $time Timestamp considered to check for outages, null for current date/time.
|
||||
|
||||
@@ -48,9 +48,6 @@ class edit extends moodleform {
|
||||
$mform->addElement('hidden', 'id');
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
$mform->addElement('checkbox', 'autostart', get_string('autostart', 'auth_outage'));
|
||||
$mform->addHelpButton('autostart', 'autostart', 'auth_outage');
|
||||
|
||||
$mform->addElement('duration', 'warningduration', get_string('warningduration', 'auth_outage'));
|
||||
$mform->addHelpButton('warningduration', 'warningduration', 'auth_outage');
|
||||
|
||||
@@ -88,6 +85,10 @@ class edit extends moodleform {
|
||||
$mform->disabledIf('accesskey', 'useaccesskey');
|
||||
$mform->addHelpButton('accesskey', 'accesskey', 'auth_outage');
|
||||
|
||||
$mform->addElement('text', 'metadata', get_string('metadata', 'auth_outage'));
|
||||
$mform->setType('metadata', PARAM_TEXT);
|
||||
$mform->addHelpButton('metadata', 'metadata', 'auth_outage');
|
||||
|
||||
$this->add_action_buttons();
|
||||
}
|
||||
|
||||
@@ -135,13 +136,13 @@ class edit extends moodleform {
|
||||
}
|
||||
$outagedata = [
|
||||
'id' => ($data->id === 0) ? null : $data->id,
|
||||
'autostart' => (isset($data->autostart) && ($data->autostart == 1)),
|
||||
'starttime' => $data->starttime,
|
||||
'stoptime' => $data->starttime + $data->outageduration,
|
||||
'warntime' => $data->starttime - $data->warningduration,
|
||||
'title' => $data->title,
|
||||
'description' => $data->description['text'],
|
||||
'accesskey' => $data->useaccesskey ? $data->accesskey : null,
|
||||
'metadata' => $data->metadata ?? null,
|
||||
];
|
||||
return new outage($outagedata);
|
||||
}
|
||||
@@ -159,7 +160,6 @@ class edit extends moodleform {
|
||||
if ($outage instanceof outage) {
|
||||
$this->_form->setDefaults([
|
||||
'id' => $outage->id,
|
||||
'autostart' => $outage->autostart,
|
||||
'starttime' => $outage->starttime,
|
||||
'outageduration' => $outage->get_duration_planned(),
|
||||
'warningduration' => $outage->get_warning_duration(),
|
||||
@@ -167,6 +167,7 @@ class edit extends moodleform {
|
||||
'description' => ['text' => $outage->description, 'format' => '1'],
|
||||
'accesskey' => $outage->accesskey,
|
||||
'useaccesskey' => !empty($outage->accesskey),
|
||||
'metadata' => $outage->metadata,
|
||||
]);
|
||||
|
||||
// If the default_autostart is configured in config, then force autostart to be the default value.
|
||||
|
||||
@@ -34,6 +34,13 @@ class hook_callbacks {
|
||||
* @param before_standard_top_of_body_html_generation $hook
|
||||
*/
|
||||
public static function before_standard_top_of_body_html_generation(before_standard_top_of_body_html_generation $hook): void {
|
||||
global $CFG;
|
||||
|
||||
if (during_initial_install() || isset($CFG->upgraderunning)) {
|
||||
// Do nothing during installation or upgrade.
|
||||
return;
|
||||
}
|
||||
|
||||
// Get code to inject.
|
||||
$hook->add_html(outagelib::get_inject_code());
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@ use coding_exception;
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class create extends clibase {
|
||||
class create extends clibase
|
||||
{
|
||||
/**
|
||||
* @var mixed[] Defaults to use if given option is null.
|
||||
*/
|
||||
@@ -43,7 +44,6 @@ class create extends clibase {
|
||||
return [
|
||||
'help' => false,
|
||||
'clone' => null,
|
||||
'autostart' => null,
|
||||
'warn' => null,
|
||||
'start' => null,
|
||||
'duration' => null,
|
||||
@@ -60,7 +60,6 @@ class create extends clibase {
|
||||
*/
|
||||
public function generate_shortcuts() {
|
||||
return [
|
||||
'a' => 'autostart',
|
||||
'b' => 'block',
|
||||
'c' => 'clone',
|
||||
'd' => 'duration',
|
||||
@@ -125,7 +124,7 @@ class create extends clibase {
|
||||
$options = $this->merge_options();
|
||||
$id = $this->create_outage($options);
|
||||
|
||||
if ($options['block']) {
|
||||
if ($options['block'] && !$options['onlyid']) {
|
||||
$block = new waitforit(['outageid' => $id]);
|
||||
$block->execute();
|
||||
}
|
||||
@@ -165,7 +164,6 @@ class create extends clibase {
|
||||
// an outage 47 years in advance.
|
||||
$start = $options['start'] > 1500000000 ? $options['start'] : $this->time + $options['start'];
|
||||
$outage = new outage([
|
||||
'autostart' => $options['autostart'],
|
||||
'warntime' => $start - $options['warn'],
|
||||
'starttime' => $start,
|
||||
'stoptime' => $start + $options['duration'],
|
||||
@@ -199,7 +197,6 @@ class create extends clibase {
|
||||
|
||||
$outage = outagedb::get_by_id((int)$id);
|
||||
$this->set_defaults([
|
||||
'autostart' => $outage->autostart,
|
||||
'warn' => $outage->get_warning_duration(),
|
||||
'duration' => $outage->get_duration_planned(),
|
||||
'title' => $outage->title,
|
||||
@@ -222,10 +219,6 @@ class create extends clibase {
|
||||
$options[$param] = $this->merge_options_check_parameters_string_nonempty($options[$param], $param);
|
||||
}
|
||||
|
||||
foreach (['autostart'] as $param) {
|
||||
$options[$param] = $this->merge_options_check_parameters_bool($options[$param], $param);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,14 +53,10 @@ class infopage {
|
||||
$CFG->svgicons = true;
|
||||
|
||||
if (is_null($params)) {
|
||||
$id = optional_param('id', null, PARAM_INT);
|
||||
$params = [
|
||||
'id' => $id,
|
||||
'id' => optional_param('id', null, PARAM_INT),
|
||||
'outage' => null,
|
||||
'static' => !is_null($id) && hash_equals(
|
||||
self::statickey($id),
|
||||
optional_param('statickey', '', PARAM_ALPHANUM)
|
||||
),
|
||||
'static' => optional_param('static', false, PARAM_BOOL),
|
||||
];
|
||||
} else {
|
||||
$defaults = [
|
||||
@@ -113,6 +109,13 @@ class infopage {
|
||||
// No hooks injecting into this page, do it manually.
|
||||
echo outagelib::get_inject_code();
|
||||
|
||||
// Inject metadata into the header before output.
|
||||
if (!empty($this->outage->metadata)) {
|
||||
header('X-Outage-Metadata: ' . $this->outage->metadata);
|
||||
header('X-Outage-StartTime: ' . $this->outage->starttime);
|
||||
header('X-Outage-EndTime: ' . $this->outage->stoptime);
|
||||
}
|
||||
|
||||
echo $OUTPUT->header();
|
||||
$viewbag = [
|
||||
'admin' => is_siteadmin(),
|
||||
@@ -149,21 +152,4 @@ class infopage {
|
||||
$this->outage = $params['outage'];
|
||||
$this->static = $params['static'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the secret token that proves a request to view an outage's static
|
||||
* rendering came from this plugin's own static-page generator, not an external
|
||||
* client forging the request. Used to gate the 'static' flag (see constructor).
|
||||
*
|
||||
* @param int $outageid
|
||||
* @return string
|
||||
*/
|
||||
public static function statickey($outageid) {
|
||||
$secret = get_config('auth_outage', 'staticsecret');
|
||||
if (empty($secret)) {
|
||||
$secret = random_string(64);
|
||||
set_config('staticsecret', $secret, 'auth_outage');
|
||||
}
|
||||
return hash_hmac('sha256', (string)$outageid, $secret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,9 +49,14 @@ class maintenance_static_page {
|
||||
} else if (PHPUNIT_TEST || defined('BEHAT_SITE_RUNNING')) {
|
||||
$html = '<html></html>';
|
||||
} else {
|
||||
// Inject metadata into the header before output.
|
||||
if (!empty($outage->metadata)) {
|
||||
header('X-Outage-Metadata: ' . $outage->metadata);
|
||||
header('X-Outage-StartTime: ' . $outage->starttime);
|
||||
header('X-Outage-EndTime: ' . $outage->stoptime);
|
||||
}
|
||||
$data = maintenance_static_page_io::file_get_data(
|
||||
$CFG->wwwroot . '/auth/outage/info.php?auth_outage_hide_warning=1&id=' . $outage->id
|
||||
. '&statickey=' . infopage::statickey($outage->id)
|
||||
$CFG->wwwroot . '/auth/outage/info.php?auth_outage_hide_warning=1&static=1&id=' . $outage->id
|
||||
);
|
||||
$html = $data['contents'];
|
||||
}
|
||||
|
||||
@@ -58,11 +58,6 @@ class outage {
|
||||
*/
|
||||
public $id = null;
|
||||
|
||||
/**
|
||||
* @var bool|null Maintenance mode auto start flag.
|
||||
*/
|
||||
public $autostart = null;
|
||||
|
||||
/**
|
||||
* @var int|null Start Time timestamp.
|
||||
*/
|
||||
@@ -113,6 +108,11 @@ class outage {
|
||||
*/
|
||||
public $accesskey = null;
|
||||
|
||||
/**
|
||||
* @var string|null metadata string, or null if not enabled.
|
||||
*/
|
||||
public $metadata = null;
|
||||
|
||||
/**
|
||||
* outage constructor.
|
||||
* @param stdClass|array|null $data The data for the outage.
|
||||
@@ -289,9 +289,6 @@ class outage {
|
||||
foreach ($fs as $f) {
|
||||
$this->$f = ($this->$f === null) ? null : (int)$this->$f;
|
||||
}
|
||||
|
||||
// Adjust bool fields.
|
||||
$this->autostart = ($this->autostart === null) ? null : (bool)$this->autostart;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+15
-37
@@ -56,7 +56,7 @@ class outagelib {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/filelib.php');
|
||||
|
||||
$curl = new curl(['ignoresecurity' => true]);
|
||||
$curl = new curl();
|
||||
$contents = $curl->get($file);
|
||||
$info = $curl->get_info();
|
||||
if (!empty($info['content_type'])) {
|
||||
@@ -173,7 +173,6 @@ class outagelib {
|
||||
'allowedips' => '',
|
||||
'css' => '',
|
||||
'default_time' => '',
|
||||
'default_autostart' => '0',
|
||||
'default_duration' => (string)(60 * 60),
|
||||
'default_warning_duration' => (string)(60 * 60),
|
||||
'default_title' => get_string('defaulttitlevalue', 'auth_outage'),
|
||||
@@ -194,9 +193,6 @@ class outagelib {
|
||||
$outage = outagedb::get_ongoing();
|
||||
if (is_null($outage)) {
|
||||
$outage = outagedb::get_next_starting();
|
||||
$ongoingoutage = false;
|
||||
} else {
|
||||
$ongoingoutage = true;
|
||||
}
|
||||
|
||||
// Set json formatted outage string to cache.
|
||||
@@ -204,9 +200,6 @@ class outagelib {
|
||||
|
||||
maintenance_static_page::create_from_outage($outage)->generate();
|
||||
self::update_climaintenance_code($outage);
|
||||
if (!$ongoingoutage || $reenablemaint || is_null($outage)) {
|
||||
self::update_maintenance_later($outage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,25 +211,6 @@ class outagelib {
|
||||
return (!empty($result['contents']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls Moodle API - set_maintenance_later() to set when the next outage starts.
|
||||
* @param outage|null $outage Outage or null if no scheduled outage.
|
||||
*/
|
||||
private static function update_maintenance_later($outage) {
|
||||
if (is_null($outage) || !$outage->autostart) {
|
||||
unset_config('maintenance_later');
|
||||
} else {
|
||||
$message = get_config('moodle', 'maintenance_message');
|
||||
if ($message) {
|
||||
debugging('Disabling $CFG->maintenance_message to allow our template page to take place.');
|
||||
debugging('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', $outage->starttime);
|
||||
self::maintenance_config_log($outage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if we should try to inject an warning bar.
|
||||
@@ -279,11 +253,12 @@ class outagelib {
|
||||
* @param int $stoptime Outage stop time.
|
||||
* @param string $allowedips List of IPs allowed.
|
||||
* @param string|null $accesskey access key, or null if no access key set.
|
||||
* @param string|null $metadata metadata to be added to the outage headers, or null if none.
|
||||
*
|
||||
* @return string
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function create_climaintenancephp_code($starttime, $stoptime, $allowedips, $accesskey = null) {
|
||||
public static function create_climaintenancephp_code($starttime, $stoptime, $allowedips, $accesskey = null, $metadata = null) {
|
||||
global $CFG;
|
||||
if (!is_int($starttime) || !is_int($stoptime)) {
|
||||
throw new invalid_parameter_exception('Make sure $startime and $stoptime are integers.');
|
||||
@@ -292,10 +267,6 @@ class outagelib {
|
||||
// single-quotes (and double for the sake of it) are present otherwise it would break the code.
|
||||
$allowedips = addslashes($allowedips);
|
||||
|
||||
// Escape the access key before substitution into the PHP literal to prevent
|
||||
// code injection via a maliciously crafted access key value.
|
||||
$accesskey = addslashes((string)$accesskey);
|
||||
|
||||
$cookiesecure = is_moodle_cookie_secure();
|
||||
|
||||
// Since Moodle 4.3 cookiehttponly is default to true and this CFG is not set.
|
||||
@@ -341,6 +312,11 @@ if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) {
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
header('Accept-Ranges: none');
|
||||
header('X-Moodle-Maintenance: manager');
|
||||
if (!empty({{METADATA}})) {
|
||||
header('X-Outage-Metadata: ' . {{METADATA}});
|
||||
}
|
||||
header('X-Outage-StartTime: ' . '{{STARTTIME}}');
|
||||
header('X-Outage-EndTime: ' . '{{STOPTIME}}');
|
||||
}
|
||||
|
||||
if (!$isphpunit && ((defined('AJAX_SCRIPT') && AJAX_SCRIPT) || (defined('WS_SERVER') && WS_SERVER))) {
|
||||
@@ -348,11 +324,11 @@ if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) {
|
||||
}
|
||||
|
||||
if ({{USEALLOWEDIPS}} && $ipblocked) {
|
||||
echo '<!-- Blocked by ip, your ip: '.getremoteaddr('n/a').' -->';
|
||||
echo '<!-- auth_outage blocked your ip: '.getremoteaddr('n/a').' -->';
|
||||
}
|
||||
|
||||
if ({{USEACCESSKEY}} && $accesskeyblocked) {
|
||||
echo '<!-- Blocked by missing or incorrect access key, access key given: '. $useraccesskey .' -->';
|
||||
echo '<!-- auth_outage blocked by missing or incorrect access key, access key given: '. $useraccesskey .' -->';
|
||||
}
|
||||
|
||||
if (!$isphpunit) {
|
||||
@@ -367,10 +343,11 @@ if ((time() >= {{STARTTIME}}) && (time() < {{STOPTIME}})) {
|
||||
}
|
||||
EOT;
|
||||
$search = ['{{STARTTIME}}', '{{STOPTIME}}', '{{USEALLOWEDIPS}}', '{{ALLOWEDIPS}}', '{{USEACCESSKEY}}', '{{ACCESSKEY}}',
|
||||
'{{YOURIP}}', '{{COOKIESECURE}}', '{{COOKIEHTTPONLY}}'];
|
||||
'{{YOURIP}}', '{{COOKIESECURE}}', '{{COOKIEHTTPONLY}}', '{{METADATA}}'];
|
||||
// Note that var_export is required because (string) false == '', not 'false'.
|
||||
$replace = [$starttime, $stoptime, var_export(!empty($allowedips), true), $allowedips, var_export(!empty($accesskey), true),
|
||||
$accesskey, getremoteaddr('n/a'), var_export($cookiesecure, true), var_export($cookiehttponly, true)];
|
||||
$accesskey, getremoteaddr('n/a'), var_export($cookiesecure, true),
|
||||
var_export($cookiehttponly, true), var_export($metadata, true)];
|
||||
return str_replace($search, $replace, $code);
|
||||
}
|
||||
|
||||
@@ -393,6 +370,7 @@ EOT;
|
||||
$config = self::get_config();
|
||||
$allowedips = trim($config->allowedips);
|
||||
$accesskey = $outage->accesskey ?? null;
|
||||
$metadata = $outage->metadata ?? null;
|
||||
|
||||
// If no outage, or allowed ips is null and access key is null (i.e. no blocking required).
|
||||
if (is_null($outage) || ($allowedips == '' && empty($accesskey))) {
|
||||
@@ -400,7 +378,7 @@ EOT;
|
||||
unlink($file);
|
||||
}
|
||||
} else {
|
||||
$code = self::create_climaintenancephp_code($outage->starttime, $outage->stoptime, $allowedips, $accesskey);
|
||||
$code = self::create_climaintenancephp_code($outage->starttime, $outage->stoptime, $allowedips, $accesskey, $metadata);
|
||||
|
||||
$dir = dirname($file);
|
||||
if (!file_exists($dir) || !is_dir($dir)) {
|
||||
|
||||
@@ -64,6 +64,41 @@ class base_table extends flexible_table {
|
||||
$this->set_attribute('class', 'generaltable admintable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a user by their fullname with a link to a profile.
|
||||
* @param int $userid
|
||||
* @return string HTML link to user profile
|
||||
*/
|
||||
private function format_user(int $userid): string {
|
||||
if ($userid == 0 || !$user = \core_user::get_user($userid)) {
|
||||
return get_string('na', 'auth_outage');
|
||||
}
|
||||
$url = new moodle_url('/user/profile.php', ['id' => $userid]);
|
||||
return html_writer::link($url, fullname($user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats created by column.
|
||||
* @param outage $outage
|
||||
* @return string The user who created the outage.
|
||||
*/
|
||||
protected function format_created(outage $outage): string {
|
||||
return $this->format_user($outage->createdby);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats modified by column.
|
||||
* @param outage $outage
|
||||
* @return string The user who last modiifed the outage and the last modified time.
|
||||
*/
|
||||
protected function format_modified(outage $outage): string {
|
||||
$timestamp = html_writer::div(
|
||||
userdate($outage->lastmodified, get_string('datetimeformat', 'auth_outage')),
|
||||
'small text-muted'
|
||||
);
|
||||
return $this->format_user($outage->modifiedby) . $timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the action buttons HTML code for a specific outage.
|
||||
* @param outage $outage The outage to generate the buttons.
|
||||
|
||||
@@ -36,7 +36,7 @@ class history_table extends base_table {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->define_columns(['warning', 'starts', 'durationplanned', 'durationactual', 'title', 'actions']);
|
||||
$this->define_columns(['warning', 'starts', 'duration', 'durationactual', 'title', 'created', 'modified', 'actions']);
|
||||
|
||||
$this->define_headers([
|
||||
get_string('tableheaderwarnbefore', 'auth_outage'),
|
||||
@@ -44,6 +44,8 @@ class history_table extends base_table {
|
||||
get_string('tableheaderdurationplanned', 'auth_outage'),
|
||||
get_string('tableheaderdurationactual', 'auth_outage'),
|
||||
get_string('tableheadertitle', 'auth_outage'),
|
||||
get_string('tableheadercreatedby', 'auth_outage'),
|
||||
get_string('tableheadermodifiedby', 'auth_outage'),
|
||||
get_string('actions'),
|
||||
]);
|
||||
|
||||
@@ -64,6 +66,8 @@ class history_table extends base_table {
|
||||
format_time($outage->get_duration_planned()),
|
||||
$finished,
|
||||
$outage->get_title(),
|
||||
$this->format_created($outage),
|
||||
$this->format_modified($outage),
|
||||
$this->create_data_buttons($outage, false),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -38,13 +38,15 @@ class planned_table extends base_table {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->define_columns(['warning', 'starts', 'duration', 'title', 'actions']);
|
||||
$this->define_columns(['warning', 'starts', 'duration', 'title', 'created', 'modified', 'actions']);
|
||||
|
||||
$this->define_headers([
|
||||
get_string('tableheaderwarnbefore', 'auth_outage'),
|
||||
get_string('tableheaderstarttime', 'auth_outage'),
|
||||
get_string('tableheaderduration', 'auth_outage'),
|
||||
get_string('tableheadertitle', 'auth_outage'),
|
||||
get_string('tableheadercreatedby', 'auth_outage'),
|
||||
get_string('tableheadermodifiedby', 'auth_outage'),
|
||||
get_string('actions'),
|
||||
]);
|
||||
|
||||
@@ -68,6 +70,8 @@ class planned_table extends base_table {
|
||||
self::create_starttime_string($outage->starttime),
|
||||
format_time($outage->get_duration_planned()),
|
||||
$title,
|
||||
$this->format_created($outage),
|
||||
$this->format_modified($outage),
|
||||
$this->create_data_buttons($outage, true),
|
||||
]);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="auth/outage/db" VERSION="20160922" COMMENT="XMLDB file for Moodle auth/outage"
|
||||
<XMLDB PATH="auth/outage/db" VERSION="20260120" COMMENT="XMLDB file for Moodle auth/outage"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@@ -7,7 +7,6 @@
|
||||
<TABLE NAME="auth_outage" COMMENT="Table used for auth/outage plugin. Holds information about all past, current and future outages.">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="autostart" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" COMMENT="If the maintenance mode should be automatically triggered once this outage startes."/>
|
||||
<FIELD NAME="warntime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When the outage will start showing a warning for that outage."/>
|
||||
<FIELD NAME="starttime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When outage starts."/>
|
||||
<FIELD NAME="stoptime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When outage ends."/>
|
||||
@@ -18,6 +17,7 @@
|
||||
<FIELD NAME="lastmodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When was this entry last modified."/>
|
||||
<FIELD NAME="finished" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Timestamp of when the outage really finished."/>
|
||||
<FIELD NAME="accesskey" TYPE="char" LENGTH="16" NOTNULL="false" SEQUENCE="false" COMMENT="Unique key used to access during outage"/>
|
||||
<FIELD NAME="metadata" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="metadata to be exposed in outage page headers"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
|
||||
@@ -61,5 +61,36 @@ function xmldb_auth_outage_upgrade($oldversion) {
|
||||
upgrade_plugin_savepoint(true, 2024081900, 'auth', 'outage');
|
||||
}
|
||||
|
||||
if ($oldversion < 2024081901) {
|
||||
// Define field metadata to be added to auth_outage.
|
||||
$table = new xmldb_table('auth_outage');
|
||||
$field = new xmldb_field('metadata', XMLDB_TYPE_TEXT, null, null, null, null, null, 'accesskey');
|
||||
|
||||
// Conditionally launch add field metadata.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Outage savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2024081901, 'auth', 'outage');
|
||||
}
|
||||
|
||||
if ($oldversion < 2024081902) {
|
||||
// Getting the table auth_outage and target field to remove from the table.
|
||||
$table = new xmldb_table('auth_outage');
|
||||
$field = new xmldb_field('autostart');
|
||||
|
||||
// Conditionally launch drop field autostart.
|
||||
if ($dbman->field_exists($table, $field)) {
|
||||
$dbman->drop_field($table, $field);
|
||||
}
|
||||
|
||||
// Removing the default_autostart config as it is no longer used.
|
||||
unset_config('default_autostart', 'auth_outage');
|
||||
|
||||
// Outage savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2024081902, 'auth', 'outage');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ use auth_outage\dml\outagedb;
|
||||
use auth_outage\form\outage\edit;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagelib;
|
||||
use auth_outage\output\renderer;
|
||||
|
||||
|
||||
require_once(__DIR__ . '/../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
@@ -48,7 +48,24 @@ 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 (array_key_exists('starttime', $_POST) && is_array($_POST['starttime'])) {
|
||||
$start = optional_param_array('starttime', [], PARAM_INT);
|
||||
} else {
|
||||
$start = optional_param('starttime', 0, PARAM_INT);
|
||||
}
|
||||
if (!empty($start['year']) && !empty($start['month']) && !empty($start['day'])) {
|
||||
$hour = $start['hour'] ?? 0;
|
||||
$minute = $start['minute'] ?? 0;
|
||||
$time = make_timestamp(
|
||||
(int) $start['year'],
|
||||
(int) $start['month'],
|
||||
(int) $start['day'],
|
||||
(int) $hour,
|
||||
(int) $minute
|
||||
);
|
||||
} else {
|
||||
$time = 0;
|
||||
}
|
||||
if ($clone && $edit) {
|
||||
throw new invalid_parameter_exception('Cannot provide both clone and edit ids.');
|
||||
}
|
||||
@@ -67,12 +84,12 @@ if ($clone) {
|
||||
}
|
||||
|
||||
$outage = new outage([
|
||||
'autostart' => $config->default_autostart,
|
||||
'starttime' => $time,
|
||||
'stoptime' => $time + $config->default_duration,
|
||||
'warntime' => $time - $config->default_warning_duration,
|
||||
'title' => $config->default_title,
|
||||
'description' => $config->default_description,
|
||||
'metadata' => $config->default_metadata,
|
||||
]);
|
||||
$action = 'outagecreate';
|
||||
}
|
||||
|
||||
@@ -69,6 +69,11 @@ function auth_outage_bootstrap_callback() {
|
||||
http_response_code(404);
|
||||
die('File not found.');
|
||||
}
|
||||
|
||||
// Ensure there is nothing in the output buffer.
|
||||
// otherwise the file will not be read correctly.
|
||||
ob_clean();
|
||||
|
||||
readfile($file);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -85,6 +85,8 @@ $string['defaultdescriptiondescription'] = 'Default warning message for outages.
|
||||
$string['defaultdescriptionvalue'] = 'There is maintenance scheduled from {{start}} to {{stop}} and our system will not be available during that time.';
|
||||
$string['defaultlayoutcss'] = 'Layout CSS';
|
||||
$string['defaultlayoutcssdescription'] = 'This CSS code can be used to override the Outage Warning Bar CSS.';
|
||||
$string['defaultmetadata'] = 'Default metadata';
|
||||
$string['defaultmetadatadescription'] = 'The default metadata to include in the outage settings, to be used as a template for new outages. E.g. JIRA-{ticketno}.';
|
||||
$string['defaultoutageautostart'] = 'Outage auto start';
|
||||
$string['defaultoutageautostartdescription'] = 'If the outage should automatically trigger maintenance mode once it starts, locking down the whole site.';
|
||||
$string['defaultoutageduration'] = 'Outage duration';
|
||||
@@ -117,6 +119,8 @@ $string['messageoutagebackonline'] = 'We are back online!';
|
||||
$string['messageoutagebackonlinedescription'] = 'You may resume browsing safely.';
|
||||
$string['messageoutageongoing'] = 'Back online at {$a->stop}.';
|
||||
$string['messageoutagewarning'] = 'Shutting down in {{countdown}}';
|
||||
$string['metadata'] = 'Outage metadata';
|
||||
$string['metadata_help'] = 'Data here will be output in the outage page as a meta tag in the header of the outage page.';
|
||||
$string['na'] = 'n/a';
|
||||
$string['notfound'] = 'No outages found.';
|
||||
$string['outage:updatenotify'] = '';
|
||||
@@ -145,9 +149,11 @@ $string['settingssectionplugin'] = 'Plugin Configuration';
|
||||
$string['settingssectionplugindescription'] = 'General outage management plugin settings.';
|
||||
$string['starttime'] = 'Start date and time';
|
||||
$string['starttime_help'] = 'At which date and time the outage starts, preventing general access to the system.';
|
||||
$string['tableheadercreatedby'] = 'Created by';
|
||||
$string['tableheaderduration'] = 'Duration';
|
||||
$string['tableheaderdurationactual'] = 'Actual duration';
|
||||
$string['tableheaderdurationplanned'] = 'Planned duration';
|
||||
$string['tableheadermodifiedby'] = 'Last modified by';
|
||||
$string['tableheaderstartedtime'] = 'Started on';
|
||||
$string['tableheaderstarttime'] = 'Starts on';
|
||||
$string['tableheadertitle'] = 'Title';
|
||||
|
||||
@@ -30,11 +30,7 @@ use auth_outage\local\controllers\maintenance_static_page;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
admin_externalpage_setup('auth_outage_manage');
|
||||
|
||||
$id = optional_param('id', null, PARAM_INT);
|
||||
$outage = is_null($id) ? outagedb::get_next_starting() : outagedb::get_by_id($id);
|
||||
if (is_null($outage)) {
|
||||
|
||||
+10
-7
@@ -43,13 +43,6 @@ if ($hassiteconfig) {
|
||||
get_string('settingssectiondefaultsdescription', 'auth_outage') . $description
|
||||
));
|
||||
|
||||
$settings->add(new admin_setting_configcheckbox(
|
||||
'auth_outage/default_autostart',
|
||||
get_string('defaultoutageautostart', 'auth_outage'),
|
||||
get_string('defaultoutageautostartdescription', 'auth_outage'),
|
||||
$defaults['default_autostart']
|
||||
));
|
||||
|
||||
$settings->add(new admin_setting_configduration(
|
||||
'auth_outage/default_warning_duration',
|
||||
get_string('defaultwarningduration', 'auth_outage'),
|
||||
@@ -78,6 +71,16 @@ if ($hassiteconfig) {
|
||||
$defaults['default_title'],
|
||||
PARAM_TEXT
|
||||
));
|
||||
$settings->add(
|
||||
new admin_setting_configtext(
|
||||
'auth_outage/default_metadata',
|
||||
get_string('defaultmetadata', 'auth_outage'),
|
||||
get_string('defaultmetadatadescription', 'auth_outage'),
|
||||
'',
|
||||
PARAM_TEXT
|
||||
)
|
||||
);
|
||||
|
||||
$settings->add(new admin_setting_configtextarea(
|
||||
'auth_outage/default_description',
|
||||
get_string('defaultdescription', 'auth_outage'),
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace auth_outage;
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
use auth_outage\local\outage;
|
||||
|
||||
@@ -33,7 +35,7 @@ use auth_outage\local\outage;
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class base_testcase extends \core_phpunit\testcase {
|
||||
abstract class base_testcase extends \advanced_testcase {
|
||||
/**
|
||||
* Checks PHPUnit version and calls the functions accordingly.
|
||||
* @param string $exception Expected exception class.
|
||||
@@ -77,7 +79,6 @@ abstract class base_testcase extends \core_phpunit\testcase {
|
||||
|
||||
return new outage([
|
||||
'id' => 1,
|
||||
'autostart' => false,
|
||||
'warntime' => $now - 100,
|
||||
'starttime' => $now + 100,
|
||||
'stoptime' => $now + 200,
|
||||
@@ -105,6 +106,5 @@ abstract class base_testcase extends \core_phpunit\testcase {
|
||||
foreach (outagedb::get_all() as $i => $outage) {
|
||||
$DB->delete_records('auth_outage', ['id' => $outage->id]);
|
||||
}
|
||||
parent::tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,6 @@ class behat_auth_outage extends behat_base {
|
||||
*/
|
||||
public function there_is_a_outage($type) {
|
||||
$data = [
|
||||
'autostart' => false,
|
||||
'finished' => null,
|
||||
'title' => 'Example of ' . $type . ' outage',
|
||||
'description' => 'An outage: ' . $type,
|
||||
@@ -230,7 +229,8 @@ class behat_auth_outage extends behat_base {
|
||||
|
||||
$found = $this->find_all('xpath', $xpath, false, $container);
|
||||
if (count($found) == 0) {
|
||||
throw new ExpectationException('"' . $text . '" text was not found in the "' . $element . '" element', $this->getSession());
|
||||
throw new ExpectationException('"' . $text . '" text was not found in the "' . $element .
|
||||
'" element', $this->getSession());
|
||||
}
|
||||
|
||||
foreach ($found as $node) {
|
||||
@@ -271,7 +271,6 @@ class behat_auth_outage extends behat_base {
|
||||
// Set defaults.
|
||||
$row = array_merge(
|
||||
[
|
||||
'autostart' => 'no',
|
||||
'warnbefore' => 60,
|
||||
'startsin' => 0,
|
||||
'stopsafter' => 60,
|
||||
@@ -281,16 +280,12 @@ class behat_auth_outage extends behat_base {
|
||||
],
|
||||
$row
|
||||
);
|
||||
if (($row['autostart'] != 'yes') && ($row['autostart'] != 'no')) {
|
||||
throw new Exception('autostart must be yes or no, found: ' . $row['autostart']);
|
||||
}
|
||||
if ($row['finished'] == '') {
|
||||
$row['finished'] = null;
|
||||
}
|
||||
|
||||
$starttime = $time + $row['startsin'];
|
||||
$this->outage = new outage([
|
||||
'autostart' => ($row['autostart'] == 'yes'),
|
||||
'warntime' => $starttime - $row['warnbefore'],
|
||||
'starttime' => $starttime,
|
||||
'stoptime' => $starttime + $row['stopsafter'],
|
||||
|
||||
@@ -14,7 +14,6 @@ Feature: Change the default settings
|
||||
Scenario Outline: Check if I can save the default settings.
|
||||
When I navigate to "Plugins > Authentication > Outage manager > Settings" in site administration
|
||||
And I set the following fields to these values:
|
||||
| s_auth_outage_default_autostart | <autostart> |
|
||||
| s_auth_outage_default_warning_duration[v] | <warning> |
|
||||
| s_auth_outage_default_warning_duration[u] | 60 |
|
||||
| s_auth_outage_default_duration[v] | <duration> |
|
||||
@@ -26,7 +25,6 @@ Feature: Change the default settings
|
||||
Then I should see "Changes saved"
|
||||
When I visit the Create Outage Page
|
||||
Then the following fields match these values:
|
||||
| autostart | <autostart> |
|
||||
| warningduration[number] | <warning> |
|
||||
| warningduration[timeunit] | 60 |
|
||||
| outageduration[number] | <duration> |
|
||||
@@ -35,6 +33,6 @@ Feature: Change the default settings
|
||||
| description[text] | <description> |
|
||||
|
||||
Examples:
|
||||
| autostart | warning | duration | title | description | css |
|
||||
| 1 | 15 | 30 | An Outage | My outage until {stop}. | /* Some CSS. */ |
|
||||
| 0 | 30 | 45 | My Behat Outage {start} | My outage with <b>HTML</b>. | /* More CSS. */ |
|
||||
| warning | duration | title | description | css |
|
||||
| 15 | 30 | An Outage | My outage until {stop}. | /* Some CSS. */ |
|
||||
| 30 | 45 | My Behat Outage {start} | My outage with <b>HTML</b>. | /* More CSS. */ |
|
||||
|
||||
@@ -23,8 +23,9 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace auth_outage\calendar;
|
||||
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\calendar\calendar;
|
||||
|
||||
/**
|
||||
* calendar_test test class.
|
||||
@@ -38,7 +39,7 @@ use auth_outage\calendar\calendar;
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\calendar\calendar
|
||||
*/
|
||||
final class calendar_test extends \core_phpunit\testcase {
|
||||
final class calendar_test extends \advanced_testcase {
|
||||
/**
|
||||
* @var outage|null The calendar entry owner.
|
||||
*/
|
||||
@@ -54,7 +55,6 @@ final class calendar_test extends \core_phpunit\testcase {
|
||||
$time = time();
|
||||
self::$outage = new outage([
|
||||
'id' => 1,
|
||||
'autostart' => false,
|
||||
'warntime' => $time - 100,
|
||||
'starttime' => $time,
|
||||
'stoptime' => $time + (2 * 60 * 60),
|
||||
@@ -75,7 +75,6 @@ final class calendar_test extends \core_phpunit\testcase {
|
||||
$time = time();
|
||||
self::$outage = new outage([
|
||||
'id' => 1,
|
||||
'autostart' => false,
|
||||
'warntime' => $time - 100,
|
||||
'starttime' => $time,
|
||||
'stoptime' => $time + (2 * 60 * 60),
|
||||
@@ -99,7 +98,6 @@ final class calendar_test extends \core_phpunit\testcase {
|
||||
$time = time();
|
||||
self::$outage = new outage([
|
||||
'id' => 1,
|
||||
'autostart' => false,
|
||||
'warntime' => $time - 100,
|
||||
'starttime' => $time,
|
||||
'stoptime' => $time + (2 * 60 * 60),
|
||||
@@ -124,7 +122,6 @@ final class calendar_test extends \core_phpunit\testcase {
|
||||
$time = time();
|
||||
$outage = new outage([
|
||||
'id' => 1,
|
||||
'autostart' => false,
|
||||
'warntime' => $time - 100,
|
||||
'starttime' => $time,
|
||||
'stoptime' => $time + (2 * 60 * 60),
|
||||
@@ -23,8 +23,9 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace auth_outage\dml;
|
||||
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\dml\outagedb;
|
||||
|
||||
/**
|
||||
* events_test tests class.
|
||||
@@ -38,7 +39,7 @@ use auth_outage\dml\outagedb;
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\dml\outagedb
|
||||
*/
|
||||
final class dml_events_test extends \core_phpunit\testcase {
|
||||
final class events_test extends \advanced_testcase {
|
||||
/**
|
||||
* @var outage|null Outage used in the tests.
|
||||
*/
|
||||
@@ -61,7 +62,6 @@ final class dml_events_test extends \core_phpunit\testcase {
|
||||
// Save new outage.
|
||||
$now = time();
|
||||
$outage = new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now - 60,
|
||||
'starttime' => 60,
|
||||
'stoptime' => 120,
|
||||
@@ -94,7 +94,6 @@ final class dml_events_test extends \core_phpunit\testcase {
|
||||
// Save new outage.
|
||||
$now = time();
|
||||
$outage = new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now - 60,
|
||||
'starttime' => 60,
|
||||
'stoptime' => 120,
|
||||
@@ -132,7 +131,6 @@ final class dml_events_test extends \core_phpunit\testcase {
|
||||
// Save new outage.
|
||||
$now = time();
|
||||
$outage = new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now - 60,
|
||||
'starttime' => 60,
|
||||
'stoptime' => 120,
|
||||
@@ -25,11 +25,12 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace auth_outage\dml;
|
||||
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\dml\outagedb;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once(__DIR__ . '/base_testcase.php');
|
||||
require_once(__DIR__ . '/../base_testcase.php');
|
||||
|
||||
/**
|
||||
* installation_test test class.
|
||||
@@ -42,11 +43,7 @@ require_once(__DIR__ . '/base_testcase.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\dml\outagedb
|
||||
*/
|
||||
final class dml_installation_test extends base_testcase {
|
||||
public function tearDown(): void {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
final class installation_test extends \auth_outage\base_testcase {
|
||||
/**
|
||||
* Checks if plugin cleans up data after uninstall.
|
||||
*
|
||||
@@ -59,10 +56,9 @@ final class dml_installation_test extends base_testcase {
|
||||
static::setAdminUser();
|
||||
$dbman = $DB->get_manager();
|
||||
|
||||
// Create a future outage with autostart.
|
||||
// Create a future outage.
|
||||
$now = time();
|
||||
$outage = new outage([
|
||||
'autostart' => true,
|
||||
'starttime' => $now + (1 * 60 * 60),
|
||||
'stoptime' => $now + (2 * 60 * 60),
|
||||
'warntime' => $now - (2 * 60 * 60),
|
||||
@@ -73,7 +69,6 @@ final class dml_installation_test extends base_testcase {
|
||||
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.
|
||||
@@ -23,11 +23,12 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace auth_outage\dml;
|
||||
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\dml\outagedb;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once(__DIR__ . '/base_testcase.php');
|
||||
require_once(__DIR__ . '/../base_testcase.php');
|
||||
|
||||
/**
|
||||
* outagedb_test tests class.
|
||||
@@ -38,11 +39,7 @@ require_once(__DIR__ . '/base_testcase.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\dml\outagedb
|
||||
*/
|
||||
final class dml_outagedb_test extends base_testcase {
|
||||
public function tearDown(): void {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
final class outagedb_test extends \auth_outage\base_testcase {
|
||||
/**
|
||||
* Creates an array of ids in from the given outages array.
|
||||
* @param outage[] $outages An array of outages.
|
||||
@@ -59,7 +56,6 @@ final class dml_outagedb_test extends base_testcase {
|
||||
/**
|
||||
* Helper function to create an outage then save it to the database.
|
||||
*
|
||||
* @param bool $autostart If outage should automatically start.
|
||||
* @param int $now Timestamp for now, such as time().
|
||||
* @param int $warning In how many hours the warning starts. Can be negative.
|
||||
* @param int $start In how many hours this outage starts. Can be negative.
|
||||
@@ -68,9 +64,8 @@ final class dml_outagedb_test extends base_testcase {
|
||||
* @param int|null $finished In how many hours this outage is marked as finished. Can be negative or null.
|
||||
* @return int Id the of created outage.
|
||||
*/
|
||||
private static function saveoutage($autostart, $now, $warning, $start, $stop, $title, $finished = null) {
|
||||
private static function saveoutage($now, $warning, $start, $stop, $title, $finished = null) {
|
||||
return outagedb::save(new outage([
|
||||
'autostart' => $autostart,
|
||||
'warntime' => $now + ($warning * 60 * 60),
|
||||
'starttime' => $now + ($start * 60 * 60),
|
||||
'stoptime' => $now + ($stop * 60 * 60),
|
||||
@@ -156,7 +151,7 @@ final class dml_outagedb_test extends base_testcase {
|
||||
$now = time();
|
||||
$this->resetAfterTest(true);
|
||||
// Create it.
|
||||
$id = self::saveoutage(false, $now, -3, -2, 2, 'An ongoing outage.');
|
||||
$id = self::saveoutage($now, -3, -2, 2, 'An ongoing outage.');
|
||||
$outage = outagedb::get_by_id($id);
|
||||
self::assertTrue($outage->is_active($now));
|
||||
self::assertTrue($outage->is_ongoing($now));
|
||||
@@ -240,26 +235,25 @@ final class dml_outagedb_test extends base_testcase {
|
||||
self::assertEquals([], outagedb::get_all(), 'Ensure there are no other outages that can affect the test.');
|
||||
self::assertNull(outagedb::get_active($now), 'There should be no active outage at this point.');
|
||||
|
||||
self::saveoutage(false, $now, 1, 2, 3, 'An outage that starts in the future and is not in warning period.');
|
||||
self::saveoutage($now, 1, 2, 3, 'An outage that starts in the future and is not in warning period.');
|
||||
self::assertNull(outagedb::get_active($now), 'No active outages yet.');
|
||||
|
||||
self::saveoutage(false, $now, -3, -2, -1, 'An outage that is already in the past.');
|
||||
self::saveoutage($now, -3, -2, -1, 'An outage that is already in the past.');
|
||||
self::assertNull(outagedb::get_active($now), 'No active outages yet.');
|
||||
|
||||
$activeid = self::saveoutage(false, $now, -2, 1, 2, 'An outage in warning period.');
|
||||
$activeid = self::saveoutage($now, -2, 1, 2, 'An outage in warning period.');
|
||||
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
|
||||
|
||||
$activeid = self::saveoutage(false, $now, -2, 0, 2, 'An outage starts now.');
|
||||
$activeid = self::saveoutage($now, -2, 0, 2, 'An outage starts now.');
|
||||
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
|
||||
|
||||
self::saveoutage(false, $now, -2, 0, -1, 'Invalid outage.');
|
||||
self::saveoutage($now, -2, 0, -1, 'Invalid outage.');
|
||||
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
|
||||
|
||||
self::saveoutage(false, $now, -2, 0, 0, 'Invalid outage.');
|
||||
self::saveoutage($now, -2, 0, 0, 'Invalid outage.');
|
||||
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
|
||||
|
||||
self::saveoutage(
|
||||
false,
|
||||
$now,
|
||||
-1,
|
||||
2,
|
||||
@@ -268,17 +262,16 @@ final class dml_outagedb_test extends base_testcase {
|
||||
);
|
||||
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
|
||||
|
||||
self::saveoutage(false, $now, -3, -2, 2, 'An finished outage.', -1);
|
||||
self::saveoutage($now, -3, -2, 2, 'An finished outage.', -1);
|
||||
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
|
||||
|
||||
$activeid = self::saveoutage(false, $now, -3, -2, 2, 'An ongoing outage.');
|
||||
$activeid = self::saveoutage($now, -3, -2, 2, 'An ongoing outage.');
|
||||
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
|
||||
|
||||
self::saveoutage(false, $now, -3, -1, 1, 'Another ongoing outage but ignored because it started after the previous one.');
|
||||
self::saveoutage($now, -3, -1, 1, 'Another ongoing outage but ignored because it started after the previous one.');
|
||||
self::assertSame($activeid, outagedb::get_active($now)->id, 'Wrong active outage picked.');
|
||||
|
||||
self::saveoutage(
|
||||
false,
|
||||
$now,
|
||||
-3,
|
||||
-2,
|
||||
@@ -300,62 +293,62 @@ final class dml_outagedb_test extends base_testcase {
|
||||
self::assertEquals([], outagedb::get_all(), 'Ensure there are no other outages that can affect the test.');
|
||||
self::assertEquals([], outagedb::get_all_unended($now), 'There should be no future outages at this point.');
|
||||
|
||||
self::saveoutage(false, $now, -3, -2, -1, 'A past outage.');
|
||||
self::saveoutage($now, -3, -2, -1, 'A past outage.');
|
||||
self::assertEquals([], outagedb::get_all_unended($now), 'No future outages yet.');
|
||||
|
||||
self::saveoutage(false, $now, -3, -2, 2, 'A finished outage.', -1);
|
||||
self::saveoutage($now, -3, -2, 2, 'A finished outage.', -1);
|
||||
self::assertEquals([], outagedb::get_all_unended($now), 'No future outages yet.');
|
||||
|
||||
$id1 = self::saveoutage(false, $now, 2, 3, 4, 'A future outage.');
|
||||
$id1 = self::saveoutage($now, 2, 3, 4, 'A future outage.');
|
||||
self::assertEquals(
|
||||
[$id1],
|
||||
self::createidarray(outagedb::get_all_unended($now)),
|
||||
'Wrong future data.'
|
||||
);
|
||||
|
||||
$id2 = self::saveoutage(false, $now, 1, 4, 5, 'Another future outage.');
|
||||
$id2 = self::saveoutage($now, 1, 4, 5, 'Another future outage.');
|
||||
self::assertEquals(
|
||||
[$id1, $id2],
|
||||
self::createidarray(outagedb::get_all_unended($now)),
|
||||
'Wrong future data.'
|
||||
);
|
||||
|
||||
$id3 = self::saveoutage(false, $now, 1, 3, 5, 'Yet another future outage.');
|
||||
$id3 = self::saveoutage($now, 1, 3, 5, 'Yet another future outage.');
|
||||
self::assertEquals(
|
||||
[$id3, $id1, $id2],
|
||||
self::createidarray(outagedb::get_all_unended($now)),
|
||||
'Wrong future data.'
|
||||
);
|
||||
|
||||
$id4 = self::saveoutage(false, $now, -2, 1, 2, 'An outage in warning period.');
|
||||
$id4 = self::saveoutage($now, -2, 1, 2, 'An outage in warning period.');
|
||||
self::assertEquals(
|
||||
[$id4, $id3, $id1, $id2],
|
||||
self::createidarray(outagedb::get_all_unended($now)),
|
||||
'Wrong future data.'
|
||||
);
|
||||
|
||||
$id5 = self::saveoutage(false, $now, -1, 2, 3, 'Another outage in warning period.');
|
||||
$id5 = self::saveoutage($now, -1, 2, 3, 'Another outage in warning period.');
|
||||
self::assertEquals(
|
||||
[$id4, $id5, $id3, $id1, $id2],
|
||||
self::createidarray(outagedb::get_all_unended($now)),
|
||||
'Wrong future data.'
|
||||
);
|
||||
|
||||
$id6 = self::saveoutage(false, $now, -3, -2, 2, 'An ongoing outage.');
|
||||
$id6 = self::saveoutage($now, -3, -2, 2, 'An ongoing outage.');
|
||||
self::assertEquals(
|
||||
[$id6, $id4, $id5, $id3, $id1, $id2],
|
||||
self::createidarray(outagedb::get_all_unended($now)),
|
||||
'Wrong future data.'
|
||||
);
|
||||
|
||||
$id7 = self::saveoutage(false, $now, -3, -1, 1, 'Another ongoing outage.');
|
||||
$id7 = self::saveoutage($now, -3, -1, 1, 'Another ongoing outage.');
|
||||
self::assertEquals(
|
||||
[$id6, $id7, $id4, $id5, $id3, $id1, $id2],
|
||||
self::createidarray(outagedb::get_all_unended($now)),
|
||||
'Wrong future data.'
|
||||
);
|
||||
|
||||
$id8 = self::saveoutage(false, $now, -3, -2, 1, 'Yet another ongoing outage.');
|
||||
$id8 = self::saveoutage($now, -3, -2, 1, 'Yet another ongoing outage.');
|
||||
self::assertEquals(
|
||||
[$id6, $id8, $id7, $id4, $id5, $id3, $id1, $id2],
|
||||
self::createidarray(outagedb::get_all_unended($now)),
|
||||
@@ -375,37 +368,37 @@ final class dml_outagedb_test extends base_testcase {
|
||||
self::assertEquals([], outagedb::get_all(), 'Ensure there are no other outages that can affect the test.');
|
||||
self::assertEquals([], outagedb::get_all_ended($now), 'There should be no future outages at this point.');
|
||||
|
||||
self::saveoutage(false, $now, -2, 1, 2, 'An outage in warning period.');
|
||||
self::saveoutage($now, -2, 1, 2, 'An outage in warning period.');
|
||||
self::assertEquals([], outagedb::get_all_ended($now), 'No past outages yet.');
|
||||
|
||||
self::saveoutage(false, $now, -3, -2, 2, 'An ongoing outage.');
|
||||
self::saveoutage($now, -3, -2, 2, 'An ongoing outage.');
|
||||
self::assertEquals([], outagedb::get_all_ended($now), 'No past outages yet.');
|
||||
|
||||
self::saveoutage(false, $now, 2, 3, 4, 'A future outage.');
|
||||
self::saveoutage($now, 2, 3, 4, 'A future outage.');
|
||||
self::assertEquals([], outagedb::get_all_ended($now), 'No past outages yet.');
|
||||
|
||||
$id1 = self::saveoutage(false, $now, -8, -6, -4, 'A past outage.');
|
||||
$id1 = self::saveoutage($now, -8, -6, -4, 'A past outage.');
|
||||
self::assertEquals(
|
||||
[$id1],
|
||||
self::createidarray(outagedb::get_all_ended($now)),
|
||||
'Wrong past data.'
|
||||
);
|
||||
|
||||
$id2 = self::saveoutage(false, $now, -8, -7, -5, 'Another past outage.');
|
||||
$id2 = self::saveoutage($now, -8, -7, -5, 'Another past outage.');
|
||||
self::assertEquals(
|
||||
[$id1, $id2],
|
||||
self::createidarray(outagedb::get_all_ended($now)),
|
||||
'Wrong past data.'
|
||||
);
|
||||
|
||||
$id3 = self::saveoutage(false, $now, -8, -5, -3, 'Yet another past outage.');
|
||||
$id3 = self::saveoutage($now, -8, -5, -3, 'Yet another past outage.');
|
||||
self::assertEquals(
|
||||
[$id3, $id1, $id2],
|
||||
self::createidarray(outagedb::get_all_ended($now)),
|
||||
'Wrong past data.'
|
||||
);
|
||||
|
||||
$id4 = self::saveoutage(false, $now, -3, -2, 2, 'A finished outage.', -1);
|
||||
$id4 = self::saveoutage($now, -3, -2, 2, 'A finished outage.', -1);
|
||||
self::assertEquals(
|
||||
[$id4, $id3, $id1, $id2],
|
||||
self::createidarray(outagedb::get_all_ended($now)),
|
||||
@@ -500,7 +493,6 @@ final class dml_outagedb_test extends base_testcase {
|
||||
$this->resetAfterTest(true);
|
||||
$time = time();
|
||||
$outage = new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $time + (60 * 60 * 24 * 1),
|
||||
'starttime' => $time + (60 * 60 * 24 * 2),
|
||||
'stoptime' => $time + (60 * 60 * 24 * 3),
|
||||
@@ -524,15 +516,6 @@ final class dml_outagedb_test extends base_testcase {
|
||||
outagedb::get_next_starting(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the outagedb::get_next_autostarting() with an invalid parameter.
|
||||
*/
|
||||
public function test_getnextautostartinginvalid(): void {
|
||||
$this->resetAfterTest(true);
|
||||
$this->set_expected_exception('coding_exception');
|
||||
outagedb::get_next_autostarting(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to create an outage for tests.
|
||||
* @param int $i Used to populate the information.
|
||||
@@ -540,7 +523,6 @@ final class dml_outagedb_test extends base_testcase {
|
||||
*/
|
||||
private function createoutage($i) {
|
||||
return new outage([
|
||||
'autostart' => ($i % 2 == 0),
|
||||
'starttime' => $i * 100,
|
||||
'stoptime' => $i * 100 + 50,
|
||||
'warntime' => $i * 60,
|
||||
Vendored
-7
@@ -1,7 +0,0 @@
|
||||
a {
|
||||
font-size: 200%;
|
||||
}
|
||||
|
||||
div {
|
||||
background-image: url('/moodle/auth/outage/tests/fixtures/catalyst.png');
|
||||
}
|
||||
Vendored
-7
@@ -1,7 +0,0 @@
|
||||
a {
|
||||
font-size: 200%;
|
||||
}
|
||||
|
||||
div {
|
||||
background-image: url(/moodle/auth/outage/tests/fixtures/catalyst.png);
|
||||
}
|
||||
@@ -23,13 +23,12 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace auth_outage\form\outage;
|
||||
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\form\outage\delete;
|
||||
use auth_outage\form\outage\finish;
|
||||
use auth_outage\form\outage\edit;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once(__DIR__ . '/base_testcase.php');
|
||||
require_once(__DIR__ . '/../../base_testcase.php');
|
||||
|
||||
/**
|
||||
* forms_test test class.
|
||||
@@ -40,11 +39,7 @@ require_once(__DIR__ . '/base_testcase.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\form\outage\edit
|
||||
*/
|
||||
final class forms_test extends base_testcase {
|
||||
public function tearDown(): void {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
final class forms_test extends \auth_outage\base_testcase {
|
||||
/**
|
||||
* Create a delete form.
|
||||
*/
|
||||
@@ -72,7 +67,6 @@ final class forms_test extends base_testcase {
|
||||
self::assertFalse($edit->is_cancelled());
|
||||
$outage = $edit->get_data();
|
||||
self::assertInstanceOf('\\auth_outage\\local\\outage', $outage);
|
||||
self::assertSame(false, $outage->autostart);
|
||||
self::assertSame(60, $outage->get_warning_duration());
|
||||
self::assertSame(mktime(14, 15, 0, 2, 1, 2013), $outage->starttime);
|
||||
self::assertSame(2 * 60 * 60, $outage->get_duration_planned());
|
||||
@@ -160,7 +154,6 @@ final class forms_test extends base_testcase {
|
||||
*/
|
||||
public function test_setdata(): void {
|
||||
$outage = new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => time() - 60,
|
||||
'starttime' => time(),
|
||||
'stoptime' => time() + 60,
|
||||
+3
-1
@@ -14,6 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace auth_outage;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once(__DIR__ . '/base_testcase.php');
|
||||
require_once(__DIR__ . '/../lib.php');
|
||||
@@ -27,7 +29,7 @@ require_once(__DIR__ . '/../lib.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers ::auth_outage_get_climaintenance_resource_file
|
||||
*/
|
||||
final class lib_test extends \core_phpunit\testcase {
|
||||
final class lib_test extends base_testcase {
|
||||
/**
|
||||
* Test this plugin gets climaintenance resource file.
|
||||
*/
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use auth_outage\local\cli\cli_exception;
|
||||
use auth_outage\local\cli\create;
|
||||
namespace auth_outage\local\cli;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once(__DIR__ . '/cli_testcase.php');
|
||||
@@ -39,10 +38,6 @@ require_once(__DIR__ . '/cli_testcase.php');
|
||||
* @covers \auth_outage\local\cli\create
|
||||
*/
|
||||
final class cli_test extends cli_testcase {
|
||||
public function tearDown(): void {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests providing an unknown parameter.
|
||||
*/
|
||||
@@ -23,8 +23,10 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace auth_outage\local\cli;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once(__DIR__ . '/base_testcase.php');
|
||||
require_once(__DIR__ . '/../../base_testcase.php');
|
||||
|
||||
/**
|
||||
* cli_testcase class.
|
||||
@@ -34,11 +36,7 @@ require_once(__DIR__ . '/base_testcase.php');
|
||||
* @copyright 2016 Catalyst IT
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class cli_testcase extends base_testcase {
|
||||
public function tearDown(): void {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
abstract class cli_testcase extends \auth_outage\base_testcase {
|
||||
/**
|
||||
* Always enable the auth outage plugin, resets after test and set no parameters.
|
||||
*/
|
||||
@@ -75,7 +73,7 @@ abstract class cli_testcase extends base_testcase {
|
||||
*
|
||||
* @return string The output text.
|
||||
*/
|
||||
protected function execute(mixed $cli) {
|
||||
protected function execute(clibase $cli) {
|
||||
ob_start();
|
||||
try {
|
||||
$cli->execute();
|
||||
@@ -23,10 +23,10 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace auth_outage\local\cli;
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\cli\create;
|
||||
use auth_outage\local\cli\cli_exception;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once(__DIR__ . '/cli_testcase.php');
|
||||
@@ -40,11 +40,7 @@ require_once(__DIR__ . '/cli_testcase.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\local\cli\create
|
||||
*/
|
||||
final class cli_create_test extends cli_testcase {
|
||||
public function tearDown(): void {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
final class create_test extends cli_testcase {
|
||||
/**
|
||||
* Tests without any arguments.
|
||||
*/
|
||||
@@ -151,7 +147,6 @@ final class cli_create_test extends cli_testcase {
|
||||
*/
|
||||
public function test_create_withoptions(): void {
|
||||
$this->set_parameters([
|
||||
'--autostart=true',
|
||||
'--warn=10',
|
||||
'--start=0',
|
||||
'--duration=30',
|
||||
@@ -181,7 +176,6 @@ final class cli_create_test extends cli_testcase {
|
||||
public function test_create_onlyid(): void {
|
||||
$this->set_parameters([
|
||||
'--onlyid',
|
||||
'--autostart=N',
|
||||
'--warn=10',
|
||||
'--start=0',
|
||||
'--duration=30',
|
||||
@@ -192,8 +186,10 @@ final class cli_create_test extends cli_testcase {
|
||||
$cli = new create();
|
||||
$cli->set_referencetime($now);
|
||||
$id = $this->execute($cli);
|
||||
// Check if the id contains is only a number (parameter onlyid).
|
||||
$id = trim($id);
|
||||
// Extracting only the id digits from the output.
|
||||
preg_match('/(\d+)\s*$/', $id, $matches);
|
||||
// Passing the proper id into the id variable.
|
||||
$id = $matches ? $matches[1] : null;
|
||||
self::assertTrue(is_number($id));
|
||||
$id = (int)$id;
|
||||
// Check creted outage.
|
||||
@@ -218,7 +214,6 @@ final class cli_create_test extends cli_testcase {
|
||||
$cli = new create();
|
||||
$cli->set_referencetime($now);
|
||||
$cli->set_defaults([
|
||||
'autostart' => false,
|
||||
'warn' => 50,
|
||||
'start' => 200,
|
||||
'duration' => 300,
|
||||
@@ -247,7 +242,6 @@ final class cli_create_test extends cli_testcase {
|
||||
$now = time();
|
||||
// Create the outage to clone.
|
||||
$original = new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now - 120,
|
||||
'starttime' => $now,
|
||||
'stoptime' => $now + 120,
|
||||
@@ -263,10 +257,13 @@ final class cli_create_test extends cli_testcase {
|
||||
]);
|
||||
$cli = new create();
|
||||
$cli->set_referencetime($now);
|
||||
$id = trim($this->execute($cli));
|
||||
// Extracting only the id digits from the output.
|
||||
preg_match('/(\d+)\s*$/', $id, $matches);
|
||||
// Passing the proper id into the id variable.
|
||||
$id = $matches ? (int)$matches[1] : null;
|
||||
// Check cloned data.
|
||||
$cloned = outagedb::get_by_id((int)$id);
|
||||
self::assertSame($now + 60, $cloned->starttime);
|
||||
self::assertSame($now, $cloned->starttime);
|
||||
self::assertSame($original->get_warning_duration(), $cloned->get_warning_duration());
|
||||
self::assertSame($original->get_duration_planned(), $cloned->get_duration_planned());
|
||||
self::assertSame($original->title, $cloned->title);
|
||||
@@ -292,7 +289,6 @@ final class cli_create_test extends cli_testcase {
|
||||
public function test_create_withblock(): void {
|
||||
// Not an extensive test in the blocking API, cliwaitforit tests should cover them deeper.
|
||||
$this->set_parameters([
|
||||
'--autostart=N',
|
||||
'--block',
|
||||
'--warn=60',
|
||||
'--start=0',
|
||||
@@ -316,21 +312,4 @@ final class cli_create_test extends cli_testcase {
|
||||
$this->set_expected_exception('coding_exception');
|
||||
$cli->set_defaults(['aninvalidparameter' => 'value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests with an invalud autostart bool value.
|
||||
*/
|
||||
public function test_invalid_bool(): void {
|
||||
$this->set_parameters([
|
||||
'--autostart=maybe',
|
||||
'--warn=60',
|
||||
'--start=0',
|
||||
'--duration=600',
|
||||
'--title=Title',
|
||||
'--description=Description',
|
||||
]);
|
||||
$cli = new create();
|
||||
$this->set_expected_cli_exception(cli_exception::ERROR_PARAMETER_INVALID);
|
||||
$cli->execute();
|
||||
}
|
||||
}
|
||||
@@ -23,10 +23,10 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace auth_outage\local\cli;
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\cli\finish;
|
||||
use auth_outage\local\cli\cli_exception;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once(__DIR__ . '/cli_testcase.php');
|
||||
@@ -40,11 +40,7 @@ require_once(__DIR__ . '/cli_testcase.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\local\cli\finish
|
||||
*/
|
||||
final class cli_finish_test extends cli_testcase {
|
||||
public function tearDown(): void {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
final class finish_test extends cli_testcase {
|
||||
/**
|
||||
* Tests the constructor.
|
||||
*/
|
||||
@@ -97,7 +93,6 @@ final class cli_finish_test extends cli_testcase {
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
$id = outagedb::save(new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now - 200,
|
||||
'starttime' => $now - 100,
|
||||
'stoptime' => $now - 50,
|
||||
@@ -118,7 +113,6 @@ final class cli_finish_test extends cli_testcase {
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
$id = outagedb::save(new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now - 200,
|
||||
'starttime' => $now - 100,
|
||||
'stoptime' => $now + 100,
|
||||
@@ -23,10 +23,10 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace auth_outage\local\cli;
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\cli\waitforit;
|
||||
use auth_outage\local\cli\cli_exception;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once(__DIR__ . '/cli_testcase.php');
|
||||
@@ -40,11 +40,7 @@ require_once(__DIR__ . '/cli_testcase.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\local\cli\waitforit
|
||||
*/
|
||||
final class cli_waitforit_test extends cli_testcase {
|
||||
public function tearDown(): void {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
final class waitforit_test extends cli_testcase {
|
||||
/**
|
||||
* Tests the constructor.
|
||||
*/
|
||||
@@ -124,7 +120,6 @@ final class cli_waitforit_test extends cli_testcase {
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
$id = outagedb::save(new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now - 200,
|
||||
'starttime' => $now - 100,
|
||||
'stoptime' => $now - 50,
|
||||
@@ -145,7 +140,6 @@ final class cli_waitforit_test extends cli_testcase {
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
outagedb::save(new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now - 10,
|
||||
'starttime' => $now + 1,
|
||||
'stoptime' => $now + 10,
|
||||
@@ -168,7 +162,6 @@ final class cli_waitforit_test extends cli_testcase {
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
outagedb::save(new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now,
|
||||
'starttime' => $now + 45,
|
||||
'stoptime' => $now + (60 * 60),
|
||||
@@ -197,7 +190,6 @@ final class cli_waitforit_test extends cli_testcase {
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
$id = outagedb::save(new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now,
|
||||
'starttime' => $now + (2 * 60 * 60),
|
||||
'stoptime' => $now + (60 * 60),
|
||||
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
@@ -0,0 +1,7 @@
|
||||
a {
|
||||
font-size: 200%;
|
||||
}
|
||||
|
||||
div {
|
||||
background-image: url('/moodle/auth/outage/tests/local/controllers/fixtures/catalyst.png');
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
a {
|
||||
font-size: 200%;
|
||||
}
|
||||
|
||||
div {
|
||||
background-image: url(/moodle/auth/outage/tests/local/controllers/fixtures/catalyst.png);
|
||||
}
|
||||
@@ -23,11 +23,13 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace auth_outage\local\controllers;
|
||||
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\controllers\infopage;
|
||||
use context_system;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once(__DIR__ . '/base_testcase.php');
|
||||
require_once(__DIR__ . '/../../base_testcase.php');
|
||||
|
||||
/**
|
||||
* Tests performed on infopage controller class and update_static_page task class.
|
||||
@@ -38,11 +40,7 @@ require_once(__DIR__ . '/base_testcase.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\local\controllers\infopage
|
||||
*/
|
||||
final class controllers_infopage_test extends base_testcase {
|
||||
public function tearDown(): void {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
final class infopage_test extends \auth_outage\base_testcase {
|
||||
/**
|
||||
* Tests the constructor.
|
||||
*/
|
||||
+18
-49
@@ -23,13 +23,13 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace auth_outage\local\controllers;
|
||||
|
||||
use auth_outage\task\update_static_page;
|
||||
use auth_outage\local\controllers\maintenance_static_page;
|
||||
use auth_outage\local\controllers\maintenance_static_page_io;
|
||||
use auth_outage\local\controllers\maintenance_static_page_generator;
|
||||
use DOMDocument;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once(__DIR__ . '/base_testcase.php');
|
||||
require_once(__DIR__ . '/../../base_testcase.php');
|
||||
|
||||
/**
|
||||
* maintenance_static_page_test class.
|
||||
@@ -40,11 +40,7 @@ require_once(__DIR__ . '/base_testcase.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\local\controllers\maintenance_static_page_generator
|
||||
*/
|
||||
final class controllers_maintenance_static_page_test extends base_testcase {
|
||||
public function tearDown(): void {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
final class maintenance_static_page_test extends \auth_outage\base_testcase {
|
||||
/**
|
||||
* Test template file.
|
||||
*/
|
||||
@@ -128,10 +124,12 @@ final class controllers_maintenance_static_page_test extends base_testcase {
|
||||
$page->generate();
|
||||
|
||||
// Check for css file.
|
||||
self::assertFileExists($page->get_io()->get_resources_folder() . '/b09bd4b66cc3964d5fc5978752fc554f5666daa3.dGV4dC9wbGFpbg');
|
||||
self::assertFileExists($page->get_io()->get_resources_folder() .
|
||||
'/53365950336b070c0b26ca50e7d0dad962c364e6.dGV4dC9wbGFpbg');
|
||||
|
||||
// Check for catalyst.png file referenced in url(..) of css.
|
||||
self::assertFileExists($page->get_io()->get_resources_folder() . '/ff7f7f87a26a908fc72930eaefb6b57306361d16.aW1hZ2UvcG5n');
|
||||
self::assertFileExists($page->get_io()->get_resources_folder() .
|
||||
'/ff7f7f87a26a908fc72930eaefb6b57306361d16.aW1hZ2UvcG5n');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,10 +144,12 @@ final class controllers_maintenance_static_page_test extends base_testcase {
|
||||
$page->generate();
|
||||
|
||||
// Check for css file.
|
||||
self::assertFileExists($page->get_io()->get_resources_folder() . '/2ec04228cc8bb37782f511aaeb01ee553cc884a4.dGV4dC9wbGFpbg');
|
||||
self::assertFileExists($page->get_io()->get_resources_folder()
|
||||
. '/e0b34925c1f939c247a4b50d6bf08c76088def39.dGV4dC9wbGFpbg');
|
||||
|
||||
// Check for catalyst.png file referenced in url(..) of css.
|
||||
self::assertFileExists($page->get_io()->get_resources_folder() . '/ff7f7f87a26a908fc72930eaefb6b57306361d16.aW1hZ2UvcG5n');
|
||||
self::assertFileExists($page->get_io()->get_resources_folder()
|
||||
. '/ff7f7f87a26a908fc72930eaefb6b57306361d16.aW1hZ2UvcG5n');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,10 +164,12 @@ final class controllers_maintenance_static_page_test extends base_testcase {
|
||||
$page->generate();
|
||||
|
||||
// Check for css file.
|
||||
self::assertFileExists($page->get_io()->get_resources_folder() . '/beb44281e23b9d872056bf0230cea34535e8cdea.dGV4dC9wbGFpbg');
|
||||
self::assertFileExists($page->get_io()->get_resources_folder() .
|
||||
'/beb44281e23b9d872056bf0230cea34535e8cdea.dGV4dC9wbGFpbg');
|
||||
|
||||
// Check for file referenced in url(..) of css.
|
||||
self::assertFileExists($page->get_io()->get_resources_folder() . '/a02a8a442fa82d5205ffb24722d9df7f35161f56.dGV4dC9wbGFpbg');
|
||||
self::assertFileExists($page->get_io()->get_resources_folder() .
|
||||
'/a02a8a442fa82d5205ffb24722d9df7f35161f56.dGV4dC9wbGFpbg');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,7 +346,7 @@ final class controllers_maintenance_static_page_test extends base_testcase {
|
||||
* @return string
|
||||
*/
|
||||
private function get_fixture_path_location($file) {
|
||||
return (string)new \moodle_url('/auth/outage/tests/fixtures/' . $file);
|
||||
return (string)new \moodle_url('/auth/outage/tests/local/controllers/fixtures/' . $file);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -429,39 +431,6 @@ final class controllers_maintenance_static_page_test extends base_testcase {
|
||||
maintenance_static_page_io::file_get_data(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test file_get_data with curlsecurityblockedhosts.
|
||||
* We will use an external URL to test passing ignoresecurity inside of file_get_data works,
|
||||
* ideally in real code we should only be calling file_get_data with internal URLs.
|
||||
*/
|
||||
public function test_file_get_data_curlsecurityblockedhosts(): void {
|
||||
global $CFG, $USER;
|
||||
|
||||
$testhtml = $this->getExternalTestFileUrl('/test.html');
|
||||
$url = new \moodle_url($testhtml);
|
||||
$host = $url->get_host();
|
||||
set_config('curlsecurityblockedhosts', $host); // Blocks $host.
|
||||
|
||||
// Test a regular curl with the default security enabled does in fact get blocked.
|
||||
$curl = new \curl();
|
||||
$contents = $curl->get($testhtml);
|
||||
$expected = $curl->get_security()->get_blocked_url_string();
|
||||
self::assertSame($expected, $contents);
|
||||
self::assertSame(0, $curl->get_errno());
|
||||
if ($CFG->branch >= 403) {
|
||||
self::assertDebuggingCalled(
|
||||
"Blocked $testhtml: The URL is blocked. [user {$USER->id}]",
|
||||
DEBUG_NONE
|
||||
);
|
||||
}
|
||||
|
||||
// Test file_get_data does return the page and isn't blocked by security.
|
||||
$found = maintenance_static_page_io::file_get_data($url->out());
|
||||
$expected = '47250a973d1b88d9445f94db4ef2c97a';
|
||||
self::assertSame($expected, md5($found['contents']));
|
||||
self::assertSame('text/html', $found['mime']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test remove css selector.
|
||||
*/
|
||||
@@ -14,10 +14,10 @@
|
||||
// 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\local\outage;
|
||||
namespace auth_outage\local;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once(__DIR__ . '/base_testcase.php');
|
||||
require_once(__DIR__ . '/../base_testcase.php');
|
||||
|
||||
/**
|
||||
* outage_test test class.
|
||||
@@ -28,11 +28,7 @@ require_once(__DIR__ . '/base_testcase.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\local\outage
|
||||
*/
|
||||
final class outage_test extends base_testcase {
|
||||
public function tearDown(): void {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
final class outage_test extends \auth_outage\base_testcase {
|
||||
/**
|
||||
* Tests the constructor.
|
||||
*/
|
||||
@@ -52,7 +48,6 @@ final class outage_test extends base_testcase {
|
||||
public function test_constructor_object(): void {
|
||||
$obj = new \stdClass();
|
||||
$obj->id = 1;
|
||||
$obj->autostart = true;
|
||||
$obj->warntime = 2;
|
||||
$obj->starttime = 3;
|
||||
$obj->finished = 4;
|
||||
@@ -61,7 +56,6 @@ final class outage_test extends base_testcase {
|
||||
$obj->description = 'Description';
|
||||
$outage = new outage($obj);
|
||||
self::assertSame($obj->id, $outage->id);
|
||||
self::assertSame($obj->autostart, $outage->autostart);
|
||||
self::assertSame($obj->warntime, $outage->warntime);
|
||||
self::assertSame($obj->starttime, $outage->starttime);
|
||||
self::assertSame($obj->finished, $outage->finished);
|
||||
@@ -14,14 +14,14 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace auth_outage\local;
|
||||
|
||||
use auth_outage\dml\outagedb;
|
||||
use auth_outage\local\outage;
|
||||
use auth_outage\local\outagelib;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once(__DIR__ . '/base_testcase.php');
|
||||
require_once(__DIR__ . '/../base_testcase.php');
|
||||
|
||||
/**
|
||||
* outagelib_test test class.
|
||||
@@ -32,50 +32,7 @@ require_once(__DIR__ . '/base_testcase.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \auth_outage\local\outagelib
|
||||
*/
|
||||
final class outagelib_test extends base_testcase {
|
||||
public function tearDown(): void {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if maintenance message is disabled as needed.
|
||||
*/
|
||||
public function test_maintenancemessage(): void {
|
||||
$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.');
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if maintenance later is removed if no outage set.
|
||||
*/
|
||||
public function test_maintenancelater_nonext(): void {
|
||||
$this->resetAfterTest(true);
|
||||
set_config('maintenance_later', time() + (60 * 60 * 24 * 7)); // In 1 week.
|
||||
self::assertNotEmpty(get_config('moodle', 'maintenance_later'));
|
||||
outagelib::prepare_next_outage();
|
||||
self::assertEmpty(get_config('moodle', 'maintenance_later'));
|
||||
}
|
||||
|
||||
final class outagelib_test extends \auth_outage\base_testcase {
|
||||
/**
|
||||
* Check outagelib::inject() works as expected.
|
||||
*/
|
||||
@@ -86,7 +43,6 @@ final class outagelib_test extends base_testcase {
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
$outage = new outage([
|
||||
'autostart' => true,
|
||||
'warntime' => $now,
|
||||
'starttime' => $now + 100,
|
||||
'stoptime' => $now + 200,
|
||||
@@ -97,7 +53,6 @@ final class outagelib_test extends base_testcase {
|
||||
$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.
|
||||
@@ -132,7 +87,6 @@ final class outagelib_test extends base_testcase {
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
$outage = new outage([
|
||||
'autostart' => true,
|
||||
'warntime' => $now,
|
||||
'starttime' => $now + 100,
|
||||
'stoptime' => $now + 200,
|
||||
@@ -143,7 +97,6 @@ final class outagelib_test extends base_testcase {
|
||||
$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,7 +128,6 @@ final class outagelib_test extends base_testcase {
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
$outage = new outage([
|
||||
'autostart' => true,
|
||||
'warntime' => $now,
|
||||
'starttime' => $now + 100,
|
||||
'stoptime' => $now + 200,
|
||||
@@ -186,7 +138,6 @@ final class outagelib_test extends base_testcase {
|
||||
$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();
|
||||
@@ -209,7 +160,6 @@ final class outagelib_test extends base_testcase {
|
||||
$this->resetAfterTest(true);
|
||||
$keys = [
|
||||
'css',
|
||||
'default_autostart',
|
||||
'default_description',
|
||||
'default_duration',
|
||||
'default_title',
|
||||
@@ -240,7 +190,6 @@ final class outagelib_test extends base_testcase {
|
||||
$keys = [
|
||||
'allowedips',
|
||||
'css',
|
||||
'default_autostart',
|
||||
'default_description',
|
||||
'default_duration',
|
||||
'default_title',
|
||||
@@ -261,7 +210,6 @@ final class outagelib_test extends base_testcase {
|
||||
// Set config with invalid values.
|
||||
set_config('allowedips', " \n", 'auth_outage');
|
||||
set_config('css', " \n", 'auth_outage');
|
||||
set_config('default_autostart', " \n", 'auth_outage');
|
||||
set_config('default_description', " \n", 'auth_outage');
|
||||
set_config('default_duration', " \n", 'auth_outage');
|
||||
set_config('default_title', " \n", 'auth_outage');
|
||||
@@ -285,7 +233,6 @@ final class outagelib_test extends base_testcase {
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
$outage = new outage([
|
||||
'autostart' => true,
|
||||
'warntime' => $now,
|
||||
'starttime' => $now + 100,
|
||||
'stoptime' => $now + 200,
|
||||
@@ -296,7 +243,6 @@ final class outagelib_test extends base_testcase {
|
||||
$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.
|
||||
@@ -356,6 +302,11 @@ e.e.e.e/20');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
header('Accept-Ranges: none');
|
||||
header('X-Moodle-Maintenance: manager');
|
||||
if (!empty('testmeta')) {
|
||||
header('X-Outage-Metadata: ' . 'testmeta');
|
||||
}
|
||||
header('X-Outage-StartTime: ' . '123');
|
||||
header('X-Outage-EndTime: ' . '456');
|
||||
}
|
||||
|
||||
if (!$isphpunit && ((defined('AJAX_SCRIPT') && AJAX_SCRIPT) || (defined('WS_SERVER') && WS_SERVER))) {
|
||||
@@ -363,11 +314,11 @@ e.e.e.e/20');
|
||||
}
|
||||
|
||||
if (true && $ipblocked) {
|
||||
echo '<!-- Blocked by ip, your ip: '.getremoteaddr('n/a').' -->';
|
||||
echo '<!-- auth_outage blocked your ip: '.getremoteaddr('n/a').' -->';
|
||||
}
|
||||
|
||||
if (true && $accesskeyblocked) {
|
||||
echo '<!-- Blocked by missing or incorrect access key, access key given: '. $useraccesskey .' -->';
|
||||
echo '<!-- auth_outage blocked by missing or incorrect access key, access key given: '. $useraccesskey .' -->';
|
||||
}
|
||||
|
||||
if (!$isphpunit) {
|
||||
@@ -381,7 +332,7 @@ e.e.e.e/20');
|
||||
}
|
||||
}
|
||||
EOT;
|
||||
$found = outagelib::create_climaintenancephp_code(123, 456, "hey'\"you\na.b.c.d\ne.e.e.e/20", '12345');
|
||||
$found = outagelib::create_climaintenancephp_code(123, 456, "hey'\"you\na.b.c.d\ne.e.e.e/20", '12345', 'testmeta');
|
||||
self::assertSame($expected, $found);
|
||||
}
|
||||
|
||||
@@ -435,6 +386,11 @@ if ((time() >= 123) && (time() < 456)) {
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
header('Accept-Ranges: none');
|
||||
header('X-Moodle-Maintenance: manager');
|
||||
if (!empty(NULL)) {
|
||||
header('X-Outage-Metadata: ' . NULL);
|
||||
}
|
||||
header('X-Outage-StartTime: ' . '123');
|
||||
header('X-Outage-EndTime: ' . '456');
|
||||
}
|
||||
|
||||
if (!$isphpunit && ((defined('AJAX_SCRIPT') && AJAX_SCRIPT) || (defined('WS_SERVER') && WS_SERVER))) {
|
||||
@@ -442,11 +398,11 @@ if ((time() >= 123) && (time() < 456)) {
|
||||
}
|
||||
|
||||
if (true && $ipblocked) {
|
||||
echo '<!-- Blocked by ip, your ip: '.getremoteaddr('n/a').' -->';
|
||||
echo '<!-- auth_outage blocked your ip: '.getremoteaddr('n/a').' -->';
|
||||
}
|
||||
|
||||
if (true && $accesskeyblocked) {
|
||||
echo '<!-- Blocked by missing or incorrect access key, access key given: '. $useraccesskey .' -->';
|
||||
echo '<!-- auth_outage blocked by missing or incorrect access key, access key given: '. $useraccesskey .' -->';
|
||||
}
|
||||
|
||||
if (!$isphpunit) {
|
||||
@@ -525,21 +481,6 @@ EOT;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Related to Issue #70: Creating ongoing outage does not trigger maintenance file creation.
|
||||
*/
|
||||
public function test_preparenextoutage_notautostart(): void {
|
||||
global $CFG;
|
||||
|
||||
$this->create_outage();
|
||||
|
||||
// The method outagelib::prepare_next_outage() should have been called by save().
|
||||
foreach ([$CFG->dataroot . '/climaintenance.template.html', $CFG->dataroot . '/climaintenance.php'] as $file) {
|
||||
self::assertFileExists($file);
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression Test - Issue #82: When changing the IP address list it should recreate the maintenance files.
|
||||
*/
|
||||
@@ -576,36 +517,6 @@ EOT;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Related to Issue #72: IP Block still triggers cli maintenance mode even without autostart.
|
||||
*/
|
||||
public function test_preparenextoutage_noautostarttrigger(): void {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
$outage = new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now - 200,
|
||||
'starttime' => $now - 100,
|
||||
'stoptime' => $now + 200,
|
||||
'title' => 'Title',
|
||||
'description' => 'Description',
|
||||
]);
|
||||
outagedb::save($outage);
|
||||
|
||||
// The method outagelib::prepare_next_outage() should have been called by save().
|
||||
self::assertFalse(get_config('moodle', 'maintenance_later'));
|
||||
// This file should not exist even if the statement above fails as Moodle does not create it immediately but test anyway.
|
||||
// Backwards compatibility with older PHPUnit - use old assertFile method.
|
||||
if (method_exists($this, 'assertFileDoesNotExist')) {
|
||||
self::assertFileDoesNotExist($CFG->dataroot . '/climaintenance.html');
|
||||
} else {
|
||||
self::assertFileNotExists($CFG->dataroot . '/climaintenance.html');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression test for issue #85.
|
||||
*/
|
||||
@@ -616,7 +527,6 @@ EOT;
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
$outage = new outage([
|
||||
'autostart' => true,
|
||||
'warntime' => $now,
|
||||
'starttime' => $now + 100,
|
||||
'stoptime' => $now + 200,
|
||||
@@ -627,7 +537,6 @@ EOT;
|
||||
$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';
|
||||
@@ -646,7 +555,6 @@ EOT;
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
$outage = new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now - 200,
|
||||
'starttime' => $now - 100,
|
||||
'stoptime' => $now + 200,
|
||||
@@ -667,8 +575,8 @@ EOT;
|
||||
* @return array
|
||||
*/
|
||||
public static function evaluation_maintenancepage_provider(): array {
|
||||
$blockedipout = '<!-- Blocked by ip, your ip:';
|
||||
$blockedaccesskeyout = '<!-- Blocked by missing or incorrect access key, access key given:';
|
||||
$blockedipout = '<!-- auth_outage blocked your ip:';
|
||||
$blockedaccesskeyout = '<!-- auth_outage blocked by missing or incorrect access key, access key given:';
|
||||
|
||||
return [
|
||||
// IP set up, access key not set up.
|
||||
@@ -746,7 +654,7 @@ EOT;
|
||||
*
|
||||
* We need this because we modify the request headers,
|
||||
* see https://github.com/sebastianbergmann/phpunit/issues/720#issuecomment-10421092
|
||||
* @runClassInSeparateProcess
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function test_evaluation_maintenancepage(
|
||||
?string $allowedips,
|
||||
@@ -762,7 +670,6 @@ EOT;
|
||||
self::setAdminUser();
|
||||
$now = time();
|
||||
$outage = new outage([
|
||||
'autostart' => false,
|
||||
'warntime' => $now - 200,
|
||||
'starttime' => $now - 100,
|
||||
'stoptime' => $now + 200,
|
||||
+3
-2
@@ -28,8 +28,9 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = "auth_outage";
|
||||
$plugin->version = 2024081902; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = 2024081902; // Human-readable release information.
|
||||
$plugin->version = 2024081905; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->release = 2024081905; // 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, 405]; // A range of branch numbers of supported moodle versions.
|
||||
$plugin->incompatible = 501;
|
||||
|
||||
@@ -39,15 +39,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
<b><?php echo get_string('infountil', 'auth_outage'); ?></b>
|
||||
<?php echo userdate($viewbag['outage']->stoptime, get_string('datetimeformat', 'auth_outage')); ?>
|
||||
</div>
|
||||
<div class="auth_outage_info_description">
|
||||
<?php
|
||||
echo format_text(
|
||||
$viewbag['outage']->get_description(),
|
||||
FORMAT_HTML,
|
||||
['context' => context_system::instance()]
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
<div class="auth_outage_info_description"><?php echo $viewbag['outage']->get_description(); ?></div>
|
||||
|
||||
<?php if ($viewbag['admin']) : ?>
|
||||
<?php
|
||||
|
||||
@@ -49,11 +49,17 @@ if (!$viewbag['static']) {
|
||||
if (is_siteadmin()) {
|
||||
$link = html_writer::link(
|
||||
new moodle_url('/auth/outage/finish.php', ['id' => $viewbag['outage']->id]),
|
||||
$OUTPUT->pix_icon('t/check', get_string('finish', 'auth_outage'), 'moodle', ['class' => 'iconsmall']) . get_string('finish', 'auth_outage'),
|
||||
$OUTPUT->pix_icon(
|
||||
't/check',
|
||||
get_string('finish', 'auth_outage'),
|
||||
'moodle',
|
||||
['class' => 'iconsmall']
|
||||
)
|
||||
. get_string('finish', 'auth_outage'),
|
||||
[
|
||||
'title' => get_string('finish', 'auth_outage'),
|
||||
'class' => 'auth_outage_warningbar_box_finish',
|
||||
]
|
||||
'title' => get_string('finish', 'auth_outage'),
|
||||
'class' => 'auth_outage_warningbar_box_finish',
|
||||
]
|
||||
);
|
||||
$title .= ' ' . html_writer::span($link, '', ['id' => 'auth_outage_warningbar_button']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user