From 6e89e15c7844afe054ca9c214e200a44e23e1a78 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 3 Apr 2019 18:10:28 +0200 Subject: [statistics/locations] Add locationid constraints; update on delete We didn't update subnetlocationid when deleting a location, leading to machines pointing to invalid locations. --- modules-available/statistics/install.inc.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'modules-available/statistics') diff --git a/modules-available/statistics/install.inc.php b/modules-available/statistics/install.inc.php index 090f0617..2bcb6b8d 100644 --- a/modules-available/statistics/install.inc.php +++ b/modules-available/statistics/install.inc.php @@ -196,6 +196,8 @@ if ($addTrigger) { if (Module::isAvailable('locations')) { if (tableExists('subnet')) { AutoLocation::rebuildAll(); + } else { + $res[] = UPDATE_RETRY; } } $res[] = UPDATE_DONE; @@ -205,6 +207,15 @@ $res[] = tableAddConstraint('machine_x_hw', 'hwid', 'statistic_hw', 'hwid', 'ON $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'); +if (Module::isAvailable('locations')) { + if (tableExists('location')) { + $res[] = tableAddConstraint('machine', 'fixedlocationid', 'location', 'locationid', + 'ON UPDATE CASCADE ON DELETE SET NULL'); + // No constraint for subnetlocationid -- needs recalc anyways (AutoLocation::rebuildAll()) + } else { + $res[] = UPDATE_RETRY; + } +} // 2017-11-27: Add state column if (!tableHasColumn('machine', 'state')) { -- cgit v1.2.3-55-g7522