From 4d51d90809da34022991e4a8c17caeb28c31bde0 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/locations/page.inc.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'modules-available/locations/page.inc.php') diff --git a/modules-available/locations/page.inc.php b/modules-available/locations/page.inc.php index d20c6068..5b3d7ff0 100644 --- a/modules-available/locations/page.inc.php +++ b/modules-available/locations/page.inc.php @@ -144,22 +144,20 @@ class Page_Locations extends Page private function deleteLocation($location) { $locationId = (int)$location['locationid']; - $ids = $locationId; if (Request::post('recursive', false) === 'on') { $rows = Location::queryLocations(); $rows = Location::buildTree($rows, $locationId); - $rows = Location::extractIds($rows); - if (!empty($rows)) { - $ids .= ',' . implode(',', $rows); - } + $ids = Location::extractIds($rows); + } else { + $ids = [$locationId]; } - $subs = Database::exec("DELETE FROM subnet WHERE locationid IN ($ids)"); - $locs = Database::exec("DELETE FROM location WHERE locationid IN ($ids)"); + $locs = Database::exec("DELETE FROM location WHERE locationid IN (:ids)", ['ids' => $ids]); Database::exec('UPDATE location SET parentlocationid = :newparent WHERE parentlocationid = :oldparent', array( 'newparent' => $location['parentlocationid'], 'oldparent' => $location['locationid'] )); - Message::addSuccess('location-deleted', $locs, $subs); + AutoLocation::rebuildAll($ids); + Message::addSuccess('location-deleted', $locs, implode(', ', $ids)); Util::redirect('?do=Locations'); } -- cgit v1.2.3-55-g7522