mirror of
https://github.com/mbirth/tcl_update_db.git
synced 2024-12-26 12:34:07 +00:00
Added JSON list of all CURefs and their latest versions.
This commit is contained in:
parent
b598ed8d0c
commit
c8dd58aab1
27
json_lastupdates.php
Executable file
27
json_lastupdates.php
Executable file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once __DIR__ . '/lib/autoloader.php';
|
||||||
|
|
||||||
|
use \TclUpdates\SQLiteReader;
|
||||||
|
|
||||||
|
$db = new SQLiteReader();
|
||||||
|
|
||||||
|
$refs = $db->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);
|
@ -71,6 +71,20 @@ class SQLiteReader
|
|||||||
return $result;
|
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)
|
public function getAllUpdates($ref, $which = self::BOTH)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT * FROM updates u LEFT JOIN files f ON u.file_sha1=f.sha1 WHERE curef=?';
|
$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);
|
$stmt = $this->pdo->prepare($sql);
|
||||||
$ok = $stmt->execute(array($ref));
|
$ok = $stmt->execute(array($ref));
|
||||||
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
|
if (count($result) == 1) {
|
||||||
|
$result = reset($result);
|
||||||
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user