From 1bdf3d4ce66910f07842c7be1043938bccf0a462 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 12 Jan 2022 17:07:42 +0100 Subject: [statistics] Make query builder a bit more OOP --- modules-available/statistics/api.inc.php | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'modules-available/statistics/api.inc.php') diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index 431d4cd4..7aa6de34 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -1,26 +1,12 @@ addCompare(false, 'Memory Slot Occupied', '>=', true, 'Memory Slot Count'); - $x->addWhere(true, 'vendor', '=', '8086'); - $x->addGlobalColumn('device'); - $res = $x->query(); - foreach ($res as $row) { - error_log(json_encode($row)); - } - exit; - */ - $data = file_get_contents('/tmp/bla.json'); - Database::exec( - "UPDATE machine SET data = :data WHERE machineuuid = :uuid", - ['uuid' => $uuid, 'data' => $data]); - HardwareParser::parseMachine($uuid, json_decode($data, true)); - echo 'Kweries: ' . Database::getQueryCount(); + $q = new HardwareQuery(HardwareInfo::RAM_MODULE); + $speed = $q->addGlobalColumn('Speed'); + $q->addLocalColumn('Configured Speed')->addCondition('<', $speed); + $speed->addCondition('>', 2666); + $q->addMachineWhere('clientip', '>', 5); + echo $q->buildQuery(), "\n"; exit; } @@ -352,7 +338,7 @@ if ($type[0] === '~') { $hwid = $hwids[$screen['name']]; } else { $hwid = (int)Database::insertIgnore('statistic_hw', 'hwid', - array('hwtype' => DeviceType::SCREEN, 'hwname' => $screen['name'])); + array('hwtype' => HardwareInfo::SCREEN, 'hwname' => $screen['name'])); $hwids[$screen['name']] = $hwid; } // Now add new entries @@ -398,7 +384,7 @@ if ($type[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)); + array('uuid' => $uuid, 'type' => HardwareInfo::SCREEN)); } else { // Some screens connected, make sure old entries get removed Database::exec("UPDATE machine_x_hw x, statistic_hw h @@ -407,7 +393,7 @@ if ($type[0] === '~') { AND x.machineuuid = :uuid", array( 'pairs' => $keepPair, 'uuid' => $uuid, - 'type' => DeviceType::SCREEN, + 'type' => HardwareInfo::SCREEN, )); } } -- cgit v1.2.3-55-g7522