summaryrefslogtreecommitdiffstats
path: root/modules-available/rebootcontrol/install.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2021-03-17 14:30:14 +0100
committerSimon Rettberg2021-03-17 14:30:14 +0100
commit09c74de226f91d97fab09a6270bbab2956197813 (patch)
tree9afaac1acee211ec377348b2b7e8b33e3b7d8212 /modules-available/rebootcontrol/install.inc.php
parent[locations/rebootcontrol] Formatting (diff)
downloadslx-admin-09c74de226f91d97fab09a6270bbab2956197813.tar.gz
slx-admin-09c74de226f91d97fab09a6270bbab2956197813.tar.xz
slx-admin-09c74de226f91d97fab09a6270bbab2956197813.zip
[rebootcontrol] Simplify some logic, improve scheduler
Diffstat (limited to 'modules-available/rebootcontrol/install.inc.php')
-rw-r--r--modules-available/rebootcontrol/install.inc.php15
1 files changed, 9 insertions, 6 deletions
diff --git a/modules-available/rebootcontrol/install.inc.php b/modules-available/rebootcontrol/install.inc.php
index 008d26aa..f400129e 100644
--- a/modules-available/rebootcontrol/install.inc.php
+++ b/modules-available/rebootcontrol/install.inc.php
@@ -39,10 +39,10 @@ $output[] = tableCreate('reboot_subnet_x_subnet', "
$output[] = tableCreate('reboot_scheduler', "
`locationid` INT(11) NOT NULL,
- `action` ENUM('wol', 'sd'),
+ `action` ENUM('wol', 'sd', 'rb'),
`nextexecution` INT(10) UNSIGNED NOT NULL DEFAULT 0,
`options` BLOB,
- PRIMARY KEY (`locationid`, `action`)");
+ PRIMARY KEY (`locationid`)");
$output[] = tableAddConstraint('reboot_jumphost_x_subnet', 'hostid', 'reboot_jumphost', 'hostid',
'ON UPDATE CASCADE ON DELETE CASCADE');
@@ -55,11 +55,14 @@ $output[] = tableAddConstraint('reboot_subnet_x_subnet', 'dstid', 'reboot_subnet
$output[] = tableAddConstraint('reboot_scheduler', 'locationid', 'location', 'locationid',
'ON UPDATE CASCADE ON DELETE CASCADE');
-if (tableExists('reboot_scheduler')) {
- Database::exec("ALTER TABLE `reboot_scheduler` DROP PRIMARY KEY , ADD PRIMARY KEY (`locationid`)");
+if (tableColumnKeyType('reboot_scheduler', 'action') === 'PRI') {
+ Database::exec("DELETE FROM reboot_scheduler WHERE action <> 'wol'");
+ $res = Database::exec("ALTER TABLE `reboot_scheduler` DROP PRIMARY KEY, ADD PRIMARY KEY (`locationid`)");
+ $output[] = $res !== false ? UPDATE_DONE : UPDATE_FAILED;
}
-if (tableHasColumn('reboot_scheduler', 'action')) {
- Database::exec("ALTER TABLE `reboot_scheduler` MODIFY COLUMN `action` ENUM('wol', 'sd', 'rb')");
+if (strpos(tableColumnType('reboot_scheduler', 'action'), 'rb') === false) {
+ $res = Database::exec("ALTER TABLE `reboot_scheduler` MODIFY COLUMN `action` ENUM('wol', 'sd', 'rb')");
+ $output[] = $res !== false ? UPDATE_DONE : UPDATE_FAILED;
}