Allow default start time using cron syntax #163

This commit is contained in:
Brendan Heywood
2020-03-25 22:21:35 +11:00
parent e6a63f02e6
commit 3b1b1ea0e1
5 changed files with 30 additions and 2 deletions

View File

@@ -152,6 +152,7 @@ class outagelib {
return [
'allowedips' => '',
'css' => '',
'default_time' => '',
'default_autostart' => '0',
'default_duration' => (string)(60 * 60),
'default_warning_duration' => (string)(60 * 60),

View File

@@ -61,6 +61,24 @@ if ($clone) {
} else {
$config = outagelib::get_config();
$time = time();
$default = $config->default_time;
if ($default) {
// Lean on the Task API to convert the cron syntax to
// the next valid outage date and time.
$parts = explode(' ', $default);
if (count($parts) == 5) {
$task = new \core\task\calendar_cron_task();
$task->set_minute($parts[0]);
$task->set_hour($parts[1]);
$task->set_day($parts[2]);
$task->set_month($parts[3]);
$task->set_day_of_week($parts[4]);
$time = $task->get_next_scheduled_time();
}
}
$outage = new outage([
'autostart' => $config->default_autostart,
'starttime' => $time,

View File

@@ -80,6 +80,8 @@ $string['defaultoutageduration'] = 'Outage duration';
$string['defaultoutagedurationdescription'] = 'Default duration (in minutes) of an outage.';
$string['defaultwarningduration'] = 'Warning duration';
$string['defaultwarningdurationdescription'] = 'Default warning time (in minutes) for outages.';
$string['defaulttime'] = 'Default time';
$string['defaulttimedescription'] = 'The default time for the next outage. This is expressed in cron notation, eg to say that a regular outage window is any thursday at 7pm you would set this to: <pre>0 19 * * 4</pre>';
$string['defaulttitle'] = 'Title';
$string['defaulttitledescription'] = 'Default title for outages. Use {{start}} and {{stop}} placeholders as required.';
$string['defaulttitlevalue'] = 'System down from {{start}} for {{duration}}';

View File

@@ -59,6 +59,13 @@ if ($hassiteconfig && is_enabled_auth('outage')) {
$defaults['default_duration'],
60
));
$settings->add(new admin_setting_configtext(
'auth_outage/default_time',
get_string('defaulttime', 'auth_outage'),
get_string('defaulttimedescription', 'auth_outage'),
'',
PARAM_TEXT
));
$settings->add(new admin_setting_configtext(
'auth_outage/default_title',
get_string('defaulttitle', 'auth_outage'),

View File

@@ -28,7 +28,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = "auth_outage";
$plugin->version = 2020021300; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = '1.0.11'; // Human-readable release information.
$plugin->version = 2020032500; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2020032500; // Human-readable release information.
$plugin->requires = 2017051500; // Requires 3.3 and higher.
$plugin->maturity = MATURITY_STABLE; // Suitable for PRODUCTION environments!