From 43b9df40a432856d53f859ca31ace3c65229476c Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Tue, 27 Mar 2018 15:01:24 +0200 Subject: [usb-lock-off] use install.php only once instead of twice to make it work... DONE --- modules-available/usblockoff/install.inc.php | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'modules-available') diff --git a/modules-available/usblockoff/install.inc.php b/modules-available/usblockoff/install.inc.php index 47a07573..31f31003 100644 --- a/modules-available/usblockoff/install.inc.php +++ b/modules-available/usblockoff/install.inc.php @@ -45,29 +45,19 @@ $res[] = tableCreate('usb_configs', ' //$ret = Database::exec("DROP TABLE `usblockoff_hw_prop`"); //$ret = Database::exec("DROP TABLE `usb_configs`"); -if ($t1 === UPDATE_DONE || $t2 === UPDATE_DONE) { - $ret = Database::exec('ALTER TABLE `usblockoff_hw` - ADD CONSTRAINT `usblockoff_hw_ibfk_1` FOREIGN KEY (`hwid`) REFERENCES `statistic_hw` (`hwid`) ON DELETE CASCADE'); - if ($ret === false) { - finalResponse(UPDATE_FAILED, 'Adding constraints to usblockoff_hw failed: ' . Database::lastError()); - } - $ret = Database::exec('ALTER TABLE `usblockoff_hw_prop` - ADD CONSTRAINT `usblockoff_hw__prop_ibfk_1` FOREIGN KEY (`hwid`, `serial`) REFERENCES `usblockoff_hw` (`hwid`, `serial`) ON DELETE CASCADE'); +if ($t4 === UPDATE_DONE) { + $ret = Database::exec("ALTER TABLE `usb_configs` ADD `configdesc` VARCHAR(200)"); if ($ret === false) { - finalResponse(UPDATE_FAILED, 'Adding constraints to usblockoff_hw_prop failed: ' . Database::lastError()); + finalResponse(UPDATE_FAILED, 'Adding column configdesc to usb_configs failed.'); } - $res[] = UPDATE_DONE; } -if ($t4 === UPDATE_NOOP) { - Database::exec("ALTER TABLE `usb_configs` - ADD `configdesc` VARCHAR(200)"); -} +$res[] = tableAddConstraint("usblockoff_hw", "hwid", "statistic_hw", "hwid", "ON DELETE CASCADE"); +// TODO: Works, as the one above already forces retry. How to write it in tableAddConstraint ? +$ret = Database::exec('ALTER TABLE `usblockoff_hw_prop` + ADD CONSTRAINT `usblockoff_hw__prop_ibfk_1` FOREIGN KEY (`hwid`, `serial`) REFERENCES `usblockoff_hw` (`hwid`, `serial`) ON DELETE CASCADE'); -if (in_array(UPDATE_DONE, $res)) { - finalResponse(UPDATE_DONE, 'Table created successfully'); -} +responseFromArray($res); -finalResponse(UPDATE_NOOP, 'Everything already up to date'); -- cgit v1.2.3-55-g7522