From a0e43d9fb99f65c0f6c9357d9fbaccab36deec5a Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 11 Jan 2017 12:19:20 +0100 Subject: [statistics/locations] Update/set subnetlocationid field in DB if the DB has been updated --- .../locations/inc/autolocation.inc.php | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 modules-available/locations/inc/autolocation.inc.php (limited to 'modules-available/locations/inc') diff --git a/modules-available/locations/inc/autolocation.inc.php b/modules-available/locations/inc/autolocation.inc.php new file mode 100644 index 00000000..cccfe9b1 --- /dev/null +++ b/modules-available/locations/inc/autolocation.inc.php @@ -0,0 +1,35 @@ +fetch(PDO::FETCH_ASSOC)) { + $loc = Location::mapIpToLocation($row['clientip']); + if ($loc === false) { + $nulls[] = $row['machineuuid']; + } else { + if (!isset($updates[$loc])) { + $updates[$loc] = array(); + } + $updates[$loc][] = $row['machineuuid']; + } + } + if (!empty($nulls)) { + $qs = '?' . str_repeat(',?', count($nulls) - 1); + Database::exec("UPDATE machine SET subnetlocationid = NULL WHERE machineuuid IN ($qs)", $nulls); + } + foreach ($updates as $lid => $machines) { + $qs = '?' . str_repeat(',?', count($machines) - 1); + $lid = (int)$lid; + Database::exec("UPDATE machine SET subnetlocationid = $lid WHERE machineuuid IN ($qs)", $machines); + } + } + +} -- cgit v1.2.3-55-g7522