From 4c0862efe57fbdaa51a69c8dc39f6fc4ae45fa20 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 19 Mar 2021 13:54:22 +0100 Subject: [locations/rebootcontrol] Inherit openingtimes for WOL/shutdown The opening times schedule is now inherited to child locations, so it's easy to toggle WOL or shutdown for individual rooms in a building, where you only have to set the opening times once for the entire building. As of now, WOL and shutdown settings are *not* inherited to child locations, as I'm not sure if you always want to inherit those by default. Closes #3710 --- modules-available/rebootcontrol/hooks/cron.inc.php | 27 +--------------------- 1 file changed, 1 insertion(+), 26 deletions(-) (limited to 'modules-available/rebootcontrol/hooks/cron.inc.php') diff --git a/modules-available/rebootcontrol/hooks/cron.inc.php b/modules-available/rebootcontrol/hooks/cron.inc.php index c1136c98..8f5c73a0 100644 --- a/modules-available/rebootcontrol/hooks/cron.inc.php +++ b/modules-available/rebootcontrol/hooks/cron.inc.php @@ -11,32 +11,7 @@ if (in_array((int)date('G'), [6, 7, 9, 12, 15]) && in_array(date('i'), ['00', '0 } // CRON for Scheduler -$now = time(); -$res = Database::simpleQuery("SELECT s.locationid, s.action, s.nextexecution, s.options, l.openingtime - FROM reboot_scheduler s - INNER JOIN location l USING (locationid) - WHERE s.nextexecution <= :now", ['now' => $now]); -while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $options = json_decode($row['options'], true); - - // Calculate next_execution for the event. - Scheduler::updateSchedule($row['locationid'], $options, $row['openingtime']); - - if ($row['nextexecution'] + 1200 < $now) - continue; - - $machines = Database::queryAll("SELECT machineuuid, clientip, macaddr, locationid FROM machine - WHERE locationid = :locid", ['locid' => $row['locationid']]); - if ($row['action'] === Scheduler::SHUTDOWN) { - RebootControl::execute($machines, RebootControl::SHUTDOWN, 0); - } elseif ($row['action'] === Scheduler::WOL) { - RebootControl::wakeMachines($machines); - } elseif ($row['action'] === Scheduler::REBOOT) { - RebootControl::execute($machines, RebootControl::REBOOT, 0); - } else { - EventLog::warning("Invalid action '{$row['action']}' in schedule for location " . $row['locationid']); - } -} +Scheduler::cron(); /* * Client reachability test -- can be disabled -- cgit v1.2.3-55-g7522