diff options
Diffstat (limited to 'modules-available/statistics/api.inc.php')
-rw-r--r-- | modules-available/statistics/api.inc.php | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index a614658a..a7a636b3 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -263,6 +263,7 @@ if ($type{0} === '~') { // `devicetype`, `devicename`, `subid`, `machineuuid` // Make sure all screens are in the general hardware table $hwids = array(); + $keepPair = array(); foreach ($screens as $port => $screen) { if (!array_key_exists('name', $screen)) continue; @@ -274,6 +275,7 @@ if ($type{0} === '~') { $hwids[$screen['name']] = $hwid; } // Now add new entries + $keepPair[] = array($hwid, $port); $machinehwid = Database::insertIgnore('machine_x_hw', 'machinehwid', array( 'hwid' => $hwid, 'machineuuid' => $uuid, @@ -302,30 +304,30 @@ if ($type{0} === '~') { Database::exec("DELETE FROM machine_x_hw_prop WHERE machinehwid = :machinehwid AND prop NOT LIKE '@%'", array('machinehwid' => $machinehwid)); } else { - $qs = '?' . str_repeat(',?', count($validProps) - 1); - array_unshift($validProps, $machinehwid); - Database::exec("DELETE FROM machine_x_hw_prop" - . " WHERE machinehwid = ? AND prop NOT LIKE '@%' AND prop NOT IN ($qs)", - $validProps); + Database::exec("DELETE FROM machine_x_hw_prop + WHERE machinehwid = :mhwid AND prop NOT LIKE '@%' AND prop NOT IN (:props)", array( + 'mhwid' => $machinehwid, + 'props' => array_values($validProps), + )); } } // Remove/disable stale entries - if (empty($hwids)) { + 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()" - . " WHERE x.machineuuid = :uuid AND x.hwid = h.hwid AND h.hwtype = :type AND x.disconnecttime = 0", + Database::exec("UPDATE machine_x_hw x, statistic_hw h + SET x.disconnecttime = UNIX_TIMESTAMP() + WHERE x.machineuuid = :uuid AND x.hwid = h.hwid AND h.hwtype = :type AND x.disconnecttime = 0", array('uuid' => $uuid, 'type' => DeviceType::SCREEN)); } else { // Some screens connected, make sure old entries get removed - $params = array_values($hwids); - array_unshift($params, $uuid); - array_unshift($params, DeviceType::SCREEN); - $qs = '?' . str_repeat(',?', count($hwids) - 1); - 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 = ? AND x.machineuuid = ? AND x.hwid NOT IN ($qs)", $params); - + Database::exec("UPDATE machine_x_hw x, statistic_hw h + SET x.disconnecttime = UNIX_TIMESTAMP() + 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, + )); } } } else if ($type === '~suspend') { |