diff options
author | Simon Rettberg | 2021-03-04 15:39:18 +0100 |
---|---|---|
committer | Simon Rettberg | 2021-03-04 15:39:18 +0100 |
commit | d2e9f25c02f800138c3fcc571ec4e611847a8b3d (patch) | |
tree | 1f56698bec106b1182635938b80db913b7de1af5 /modules-available/statistics/install.inc.php | |
parent | [locationinfo] Ignore position of machines with mismatching location (diff) | |
download | slx-admin-d2e9f25c02f800138c3fcc571ec4e611847a8b3d.tar.gz slx-admin-d2e9f25c02f800138c3fcc571ec4e611847a8b3d.tar.xz slx-admin-d2e9f25c02f800138c3fcc571ec4e611847a8b3d.zip |
[statistics] Better check if locationid trigger exists
Diffstat (limited to 'modules-available/statistics/install.inc.php')
-rw-r--r-- | modules-available/statistics/install.inc.php | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/modules-available/statistics/install.inc.php b/modules-available/statistics/install.inc.php index 54e844e0..3becce8f 100644 --- a/modules-available/statistics/install.inc.php +++ b/modules-available/statistics/install.inc.php @@ -1,8 +1,5 @@ <?php -// locationid trigger -$addTrigger = false; - $res = array(); // The main statistic table used for log entries @@ -24,7 +21,7 @@ $res[] = tableCreate('statistic', " // Main table containing all known clients -$res[] = $machineCreate = tableCreate('machine', " +$res[] = tableCreate('machine', " `machineuuid` char(36) CHARACTER SET ascii NOT NULL, `fixedlocationid` int(11) DEFAULT NULL COMMENT 'Manually set location (e.g. roomplanner)', `subnetlocationid` int(11) DEFAULT NULL COMMENT 'Automatically determined location (e.g. from subnet match)', @@ -117,11 +114,6 @@ $res[] = tableCreate('setting_machine', ' KEY `setting` (`setting`) '); -// need trigger? -if ($machineCreate === UPDATE_DONE) { - $addTrigger = true; -} - // // This was added/changed later -- keep update path // @@ -177,7 +169,6 @@ if (!tableHasColumn('machine', 'subnetlocationid')) { finalResponse(UPDATE_FAILED, 'Adding subnetlocationid to machine failed: ' . Database::lastError()); } $res[] = UPDATE_DONE; - $addTrigger = true; } // And fixedlocationid - manually set location, currently used by roomplanner if (!tableHasColumn('machine', 'fixedlocationid')) { @@ -189,10 +180,10 @@ if (!tableHasColumn('machine', 'fixedlocationid')) { // Now copy over the values from locationid, since this was used before Database::exec("UPDATE machine SET fixedlocationid = locationid"); $res[] = UPDATE_DONE; - $addTrigger = true; } -// If any of these was added, create the trigger -if ($addTrigger) { + +$checkTrigger = Database::queryFirst("show triggers where `Trigger` = 'set_automatic_locationid'"); +if ($checkTrigger === false) { $ret = Database::exec(" CREATE TRIGGER set_automatic_locationid BEFORE UPDATE ON machine FOR EACH ROW |