summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics
diff options
context:
space:
mode:
authorSimon Rettberg2017-12-21 13:52:21 +0100
committerSimon Rettberg2017-12-21 13:52:21 +0100
commit2b10bb89d4c4a6c2d1f5860b9b1811363ec73e34 (patch)
treef3f79f5b11d1c6f6bb1de5b7c29550d651f78fe0 /modules-available/statistics
parent[inc/Database] Support nested arrays in query (diff)
downloadslx-admin-2b10bb89d4c4a6c2d1f5860b9b1811363ec73e34.tar.gz
slx-admin-2b10bb89d4c4a6c2d1f5860b9b1811363ec73e34.tar.xz
slx-admin-2b10bb89d4c4a6c2d1f5860b9b1811363ec73e34.zip
[statistics] Cleaner version for screen connection state handling by using nested array feature for queries
Diffstat (limited to 'modules-available/statistics')
-rw-r--r--modules-available/statistics/api.inc.php22
1 files changed, 6 insertions, 16 deletions
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') {