summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/api.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2017-12-21 13:23:18 +0100
committerSimon Rettberg2017-12-21 13:23:18 +0100
commit8d8362dd7ce06c4f9771c619ec4f2625ff82b877 (patch)
treec8a60af19b3edc5ff430831a494da123049e4556 /modules-available/statistics/api.inc.php
parent[locationinfo] Update translations (diff)
downloadslx-admin-8d8362dd7ce06c4f9771c619ec4f2625ff82b877.tar.gz
slx-admin-8d8362dd7ce06c4f9771c619ec4f2625ff82b877.tar.xz
slx-admin-8d8362dd7ce06c4f9771c619ec4f2625ff82b877.zip
[statistics] Properly mark disconnected sceens as such if the output name changed
Diffstat (limited to 'modules-available/statistics/api.inc.php')
-rw-r--r--modules-available/statistics/api.inc.php46
1 files changed, 29 insertions, 17 deletions
diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php
index a614658a..3cb1e961 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();
+ $ports = 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
+ $ports[] = $port;
$machinehwid = Database::insertIgnore('machine_x_hw', 'machinehwid', array(
'hwid' => $hwid,
'machineuuid' => $uuid,
@@ -302,30 +304,40 @@ 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($ports)) {
// 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 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),
+ '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') {