summaryrefslogtreecommitdiffstats
path: root/modules-available/rebootcontrol/inc/scheduler.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/rebootcontrol/inc/scheduler.inc.php')
-rw-r--r--modules-available/rebootcontrol/inc/scheduler.inc.php16
1 files changed, 10 insertions, 6 deletions
diff --git a/modules-available/rebootcontrol/inc/scheduler.inc.php b/modules-available/rebootcontrol/inc/scheduler.inc.php
index 613fbbee..45aedcc1 100644
--- a/modules-available/rebootcontrol/inc/scheduler.inc.php
+++ b/modules-available/rebootcontrol/inc/scheduler.inc.php
@@ -3,6 +3,10 @@
class Scheduler
{
+ const SHUTDOWN = 'SHUTDOWN';
+ const REBOOT = 'REBOOT';
+ const WOL = 'WOL';
+
public static function updateSchedule($locationid, $options, $openingTimes)
{
if (empty($openingTimes)) {
@@ -57,11 +61,11 @@ class Scheduler
foreach ($openingTimes as $row) {
foreach ($row['days'] as $day) {
if ($options['wol']) {
- $events[] = ['action' => 'wol',
+ $events[] = ['action' => self::WOL,
'time' => self::calculateTimestamp($now, $day, $row['openingtime'])];
}
if ($options['sd']) {
- $events[] = ['action' => 'sd',
+ $events[] = ['action' => self::SHUTDOWN,
'time' => self::calculateTimestamp($now, $day, $row['closingtime'])];
}
}
@@ -75,9 +79,9 @@ class Scheduler
$prev = PHP_INT_MAX;
for ($i = count($events) - 1; $i >= 0; --$i) {
$event =& $events[$i];
- if ($event['action'] === 'wol') {
+ if ($event['action'] === self::WOL) {
$event['time'] -= $wolOffset;
- } elseif ($event['action'] === 'sd') {
+ } elseif ($event['action'] === self::SHUTDOWN) {
$event['time'] += $sdOffset;
} else {
error_log('BUG Unhandled event type ' . $event['action']);
@@ -102,9 +106,9 @@ class Scheduler
// If difference to next event is < 5 min, ignore.
continue;
}
- if ($diff < 900 && $event['action'] === 'sd' && $events[$i + 1]['action'] === 'wol') {
+ if ($diff < 900 && $event['action'] === self::SHUTDOWN && $events[$i + 1]['action'] === self::WOL) {
// If difference to next WOL is < 15 min and this is a shutdown, reboot instead.
- $res['action'] = 'rb';
+ $res['action'] = self::REBOOT;
$res['time'] = $event['time'];
} else {
// Use first event.