diff options
author | Christian Hofmaier | 2020-12-03 12:58:52 +0100 |
---|---|---|
committer | Christian Hofmaier | 2020-12-03 12:58:52 +0100 |
commit | 2d49c621abeff1909b7f4c90d5273157a4f70286 (patch) | |
tree | 5bf548871469c1309f4fa9d43cfd63ec52f89a43 /modules-available/rebootcontrol | |
parent | [statistics_reporting/statistics] Include system/runmode total counts (diff) | |
download | slx-admin-2d49c621abeff1909b7f4c90d5273157a4f70286.tar.gz slx-admin-2d49c621abeff1909b7f4c90d5273157a4f70286.tar.xz slx-admin-2d49c621abeff1909b7f4c90d5273157a4f70286.zip |
[locations] Add scheduler to openingtimes modal
- only load/safe without further functionality
- add backend to rebootcontrol
Diffstat (limited to 'modules-available/rebootcontrol')
-rw-r--r-- | modules-available/rebootcontrol/inc/scheduler.inc.php | 58 | ||||
-rw-r--r-- | modules-available/rebootcontrol/install.inc.php | 9 |
2 files changed, 67 insertions, 0 deletions
diff --git a/modules-available/rebootcontrol/inc/scheduler.inc.php b/modules-available/rebootcontrol/inc/scheduler.inc.php new file mode 100644 index 00000000..839d7d81 --- /dev/null +++ b/modules-available/rebootcontrol/inc/scheduler.inc.php @@ -0,0 +1,58 @@ +<?php + +class Scheduler +{ + + public static function updateSchedule($locationid, $action, $options, $openingTimes) { + if ($openingTimes == '') { + self::deleteSchedule($locationid, $action); + return false; + } + $nextwake = self::calcNextwake($action, $openingTimes); + $json_options = json_encode($options); + self::upsert($locationid, $action, $nextwake, $json_options); + return true; + } + + public static function deleteSchedule($locationid, $action) { + Database::exec("DELETE FROM `scheduler` + WHERE locationid = :lid AND action = :act", array( + 'lid' => $locationid, + 'act' => $action + )); + } + + private static function calcNextwake($action, $openingTimes) { + //TODO: Calculate nextWake based on openingTimes. Needs action to know if openTimes or closingTimes are used. + return 0; + } + + private static function upsert($locationid, $action, $nextwake, $options) { + $schedule = Database::queryFirst("SELECT locationid, action + FROM `scheduler` + WHERE locationid = :lid AND action = :act", array( + 'lid' => $locationid, + 'act' => $action + )); + if ($schedule === false) { + Database::exec("INSERT INTO `scheduler` (locationid, action, nextwake, options) + VALUES (:lid, :act, :next, :opt)", array( + 'lid' => $locationid, + 'act' => $action, + 'next' => $nextwake, + 'opt' => $options + )); + } else { + Database::exec("UPDATE `scheduler` + SET nextwake = :next, options = :opt + WHERE locationid = :lid AND action = :act", array( + 'next' => $nextwake, + 'opt' => $options, + 'lid' => $locationid, + 'act' => $action + )); + } + return true; + } + +}
\ No newline at end of file diff --git a/modules-available/rebootcontrol/install.inc.php b/modules-available/rebootcontrol/install.inc.php index 0aedfa20..6fe040ad 100644 --- a/modules-available/rebootcontrol/install.inc.php +++ b/modules-available/rebootcontrol/install.inc.php @@ -37,6 +37,13 @@ $output[] = tableCreate('reboot_subnet_x_subnet', " PRIMARY KEY (`srcid`, `dstid`), KEY `nextcheck` (`nextcheck`)"); +$output[] = tableCreate('scheduler', " + `locationid` INT(11) NOT NULL, + `action` ENUM('wol', 'sd'), + `nextwake` INT(10) UNSIGNED NOT NULL DEFAULT 0, + `options` BLOB, + PRIMARY KEY (`locationid`, `action`)"); + $output[] = tableAddConstraint('reboot_jumphost_x_subnet', 'hostid', 'reboot_jumphost', 'hostid', 'ON UPDATE CASCADE ON DELETE CASCADE'); $output[] = tableAddConstraint('reboot_jumphost_x_subnet', 'subnetid', 'reboot_subnet', 'subnetid', @@ -45,5 +52,7 @@ $output[] = tableAddConstraint('reboot_subnet_x_subnet', 'srcid', 'reboot_subnet 'ON UPDATE CASCADE ON DELETE CASCADE'); $output[] = tableAddConstraint('reboot_subnet_x_subnet', 'dstid', 'reboot_subnet', 'subnetid', 'ON UPDATE CASCADE ON DELETE CASCADE'); +$output[] = tableAddConstraint('scheduler', 'locationid', 'location', 'locationid', + 'ON UPDATE CASCADE ON DELETE CASCADE'); responseFromArray($output);
\ No newline at end of file |