From 2b10bb89d4c4a6c2d1f5860b9b1811363ec73e34 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 21 Dec 2017 13:52:21 +0100 Subject: [statistics] Cleaner version for screen connection state handling by using nested array feature for queries --- modules-available/statistics/api.inc.php | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'modules-available/statistics') diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index 3cb1e961..a7a636b3 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -263,7 +263,7 @@ if ($type{0} === '~') { // `devicetype`, `devicename`, `subid`, `machineuuid` // Make sure all screens are in the general hardware table $hwids = array(); - $ports = array(); + $keepPair = array(); foreach ($screens as $port => $screen) { if (!array_key_exists('name', $screen)) continue; @@ -275,7 +275,7 @@ if ($type{0} === '~') { $hwids[$screen['name']] = $hwid; } // Now add new entries - $ports[] = $port; + $keepPair[] = array($hwid, $port); $machinehwid = Database::insertIgnore('machine_x_hw', 'machinehwid', array( 'hwid' => $hwid, 'machineuuid' => $uuid, @@ -312,7 +312,7 @@ if ($type{0} === '~') { } } // Remove/disable stale entries - if (empty($ports)) { + if (empty($keepPair)) { // No screens connected at all, purge all screen entries for this machine Database::exec("UPDATE machine_x_hw x, statistic_hw h SET x.disconnecttime = UNIX_TIMESTAMP() @@ -322,22 +322,12 @@ if ($type{0} === '~') { // Some screens connected, make sure old entries get removed Database::exec("UPDATE machine_x_hw x, statistic_hw h SET x.disconnecttime = UNIX_TIMESTAMP() - WHERE h.hwid = x.hwid AND x.disconnecttime = 0 AND h.hwtype = :type - AND x.machineuuid = :uuid AND x.devpath NOT IN (:ports)", array( - 'ports' => array_values($ports), + WHERE (x.hwid, x.devpath) NOT IN (:pairs) AND x.disconnecttime = 0 AND h.hwtype = :type + AND x.machineuuid = :uuid", array( + 'pairs' => $keepPair, 'uuid' => $uuid, 'type' => DeviceType::SCREEN, )); - if (!empty($hwids)) { - Database::exec("UPDATE machine_x_hw x, statistic_hw h - SET x.disconnecttime = UNIX_TIMESTAMP() - WHERE h.hwid = x.hwid AND x.disconnecttime = 0 AND h.hwtype = :type - AND x.machineuuid = :uuid AND x.hwid NOT IN (:hwids)", array( - 'hwids' => array_values($hwids), - 'uuid' => $uuid, - 'type' => DeviceType::SCREEN, - )); - } } } } else if ($type === '~suspend') { -- cgit v1.2.3-55-g7522