summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/install.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2019-02-21 11:09:17 +0100
committerSimon Rettberg2019-02-21 11:09:17 +0100
commit67c915aa7094a32b0dfdd4ef60382bb1d3eeb506 (patch)
tree89e1222a4bd6ed6076e739e151b3af5a80c4aff8 /modules-available/statistics/install.inc.php
parentAAAAAnd I'm retarded (diff)
downloadslx-admin-67c915aa7094a32b0dfdd4ef60382bb1d3eeb506.tar.gz
slx-admin-67c915aa7094a32b0dfdd4ef60382bb1d3eeb506.tar.xz
slx-admin-67c915aa7094a32b0dfdd4ef60382bb1d3eeb506.zip
Fix UUID handling; refactor constraints for machineuuid
Diffstat (limited to 'modules-available/statistics/install.inc.php')
-rw-r--r--modules-available/statistics/install.inc.php39
1 files changed, 18 insertions, 21 deletions
diff --git a/modules-available/statistics/install.inc.php b/modules-available/statistics/install.inc.php
index 84e038a4..a9e8fb7b 100644
--- a/modules-available/statistics/install.inc.php
+++ b/modules-available/statistics/install.inc.php
@@ -196,32 +196,15 @@ if ($addTrigger) {
if (Module::isAvailable('locations')) {
if (tableExists('subnet')) {
AutoLocation::rebuildAll();
- } else {
- finalResponse(UPDATE_RETRY, 'Locations module not installed yet, retry later');
}
}
$res[] = UPDATE_DONE;
}
-if ($machineHwCreate === UPDATE_DONE) {
- $ret = Database::exec('ALTER TABLE `machine_x_hw`
- ADD CONSTRAINT `machine_x_hw_ibfk_1` FOREIGN KEY (`hwid`) REFERENCES `statistic_hw` (`hwid`) ON DELETE CASCADE,
- ADD CONSTRAINT `machine_x_hw_ibfk_2` FOREIGN KEY (`machineuuid`) REFERENCES `machine` (`machineuuid`) ON DELETE CASCADE');
- if ($ret === false) {
- finalResponse(UPDATE_FAILED, 'Adding constraints to machine_x_hw failed: ' . Database::lastError());
- }
- $ret = Database::exec('ALTER TABLE `machine_x_hw_prop`
- ADD CONSTRAINT `machine_x_hw_prop_ibfk_1` FOREIGN KEY (`machinehwid`) REFERENCES `machine_x_hw` (`machinehwid`) ON DELETE CASCADE');
- if ($ret === false) {
- finalResponse(UPDATE_FAILED, 'Adding constraint to machine_x_hw_prop failed: ' . Database::lastError());
- }
- $ret = Database::exec('ALTER TABLE `statistic_hw_prop`
- ADD CONSTRAINT `statistic_hw_prop_ibfk_1` FOREIGN KEY (`hwid`) REFERENCES `statistic_hw` (`hwid`) ON DELETE CASCADE');
- if ($ret === false) {
- finalResponse(UPDATE_FAILED, 'Adding constraint to statistic_hw_prop failed: ' . Database::lastError());
- }
- $res[] = UPDATE_DONE;
-}
+$res[] = tableAddConstraint('machine_x_hw', 'hwid', 'statistic_hw', 'hwid', 'ON DELETE CASCADE');
+$res[] = tableAddConstraint('machine_x_hw', 'machineuuid', 'machine', 'machineuuid', 'ON DELETE CASCADE ON UPDATE CASCADE');
+$res[] = tableAddConstraint('machine_x_hw_prop', 'machinehwid', 'machine_x_hw', 'machinehwid', 'ON DELETE CASCADE');
+$res[] = tableAddConstraint('statistic_hw_prop', 'hwid', 'statistic_hw', 'hwid', 'ON DELETE CASCADE');
// 2017-11-27: Add state column
if (!tableHasColumn('machine', 'state')) {
@@ -251,5 +234,19 @@ if (!tableHasColumn('machine', 'live_tmpsize')) {
$res[] = UPDATE_DONE;
}
+// 2019-02-20: Convert bogus UUIDs
+$res2 = Database::simpleQuery("SELECT machineuuid, macaddr FROM machine WHERE machineuuid LIKE '000000000000001-%'");
+while ($row = $res2->fetch(PDO::FETCH_ASSOC)) {
+ $new = strtoupper('baad1d00-9491-4716-b98b-' . preg_replace('/[^0-9a-f]/i', '', $row['macaddr']));
+ error_log('Replacing ' . $row['machineuuid'] . ' with ' . $new);
+ if (strlen($new) === 36) {
+ if (Database::exec("UPDATE machine SET machineuuid = :new WHERE machineuuid = :old",
+ ['old' => $row['machineuuid'], 'new' => $new]) === false) {
+ error_log('Result: ' . Database::lastError());
+ Database::exec("DELETE FROM machine WHERE machineuuid = :old", ['old' => $row['machineuuid']]);
+ }
+ }
+}
+
// Create response
responseFromArray($res);