From dc516c24685518b41bcce0751caf286dc65e471f Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 17 Mar 2021 15:39:55 +0100 Subject: [locations/rebootcontrol] Change ENUM constants; display next event --- modules-available/rebootcontrol/inc/scheduler.inc.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'modules-available/rebootcontrol/inc/scheduler.inc.php') 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. -- cgit v1.2.3-55-g7522