From c8dd58aab14663691d65e6df9cbc1096470fc730 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Sun, 17 Dec 2017 02:15:59 +0100 Subject: [PATCH] Added JSON list of all CURefs and their latest versions. --- json_lastupdates.php | 27 +++++++++++++++++++++++++++ lib/TclUpdates/SQLiteReader.php | 17 +++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 json_lastupdates.php diff --git a/json_lastupdates.php b/json_lastupdates.php new file mode 100755 index 0000000..b8113f0 --- /dev/null +++ b/json_lastupdates.php @@ -0,0 +1,27 @@ +getAllRefs(); +$vars = $db->getAllVariantsFlat(); + +$output = array(); +foreach ($refs as $ref) { + $lastOta = $db->getLatestUpdate($ref, $db::OTA_ONLY); + $lastFull = $db->getLatestUpdate($ref, $db::FULL_ONLY); + + $output[$ref] = array( + 'curef' => $ref, + 'variant' => $vars[$ref], + 'last_ota' => $lastOta['tv'], + 'last_full' => $lastFull['tv'], + ); +} + +header('Content-Type: text/json'); + +echo json_encode($output); diff --git a/lib/TclUpdates/SQLiteReader.php b/lib/TclUpdates/SQLiteReader.php index f341520..b2e8156 100644 --- a/lib/TclUpdates/SQLiteReader.php +++ b/lib/TclUpdates/SQLiteReader.php @@ -71,6 +71,20 @@ class SQLiteReader return $result; } + public function getAllVariantsFlat() + { + $sql = 'SELECT f.name AS family, m.name AS model, d.ref, d.name AS variant FROM families f LEFT JOIN models m ON f.familyId=m.familyId LEFT JOIN devices d ON m.modelId=d.modelId;'; + $sqlresult = $this->pdo->query($sql); + $result = array(); + foreach ($sqlresult->fetchAll(\PDO::FETCH_ASSOC) as $row) { + $result[$row['ref']] = $row['family'] . ' ' . $row['model']; + if (strlen($row['variant'])>0) { + $result[$row['ref']] .= ' (' . $row['variant'] . ')'; + } + } + return $result; + } + public function getAllUpdates($ref, $which = self::BOTH) { $sql = 'SELECT * FROM updates u LEFT JOIN files f ON u.file_sha1=f.sha1 WHERE curef=?'; @@ -97,6 +111,9 @@ class SQLiteReader $stmt = $this->pdo->prepare($sql); $ok = $stmt->execute(array($ref)); $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); + if (count($result) == 1) { + $result = reset($result); + } return $result; }