mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-16 21:41:31 +02:00
Allow default start time using cron syntax #163
This commit is contained in:
@@ -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),
|
||||
|
||||
18
edit.php
18
edit.php
@@ -61,6 +61,24 @@ if ($clone) {
|
||||
} else {
|
||||
$config = outagelib::get_config();
|
||||
$time = time();
|
||||
|
||||
$default = $config->default_time;
|
||||
if ($default) {
|
||||
|
||||
// Lean on the Task API to convert the cron syntax to
|
||||
// the next valid outage date and time.
|
||||
$parts = explode(' ', $default);
|
||||
if (count($parts) == 5) {
|
||||
$task = new \core\task\calendar_cron_task();
|
||||
$task->set_minute($parts[0]);
|
||||
$task->set_hour($parts[1]);
|
||||
$task->set_day($parts[2]);
|
||||
$task->set_month($parts[3]);
|
||||
$task->set_day_of_week($parts[4]);
|
||||
$time = $task->get_next_scheduled_time();
|
||||
}
|
||||
}
|
||||
|
||||
$outage = new outage([
|
||||
'autostart' => $config->default_autostart,
|
||||
'starttime' => $time,
|
||||
|
||||
@@ -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}}';
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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!
|
||||
|
||||
Reference in New Issue
Block a user