From 03362fcaa38fc0d397f78005c27bda6aefbddf6a Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Fri, 19 Jan 2018 22:18:57 +0100 Subject: [PATCH] JSON for missing OTAs from older versions. --- json_otaversions.php | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 json_otaversions.php diff --git a/json_otaversions.php b/json_otaversions.php new file mode 100644 index 0000000..a7f9301 --- /dev/null +++ b/json_otaversions.php @@ -0,0 +1,71 @@ +getAllRefs(); +$vars = $db->getAllVariantsFlat(); + +$output = array(); +foreach ($refs as $ref) { + $updates = $db->getAllUpdates($ref); + + $all_versions = array(); + $update_map = array(); + $latest_ota = ''; + foreach ($updates as $update) { + $fv = $update['fv']; + $tv = $update['tv']; + $all_versions[] = $tv; + if (!$fv) { + // FULL Update - ignore, just collect possible old version + continue; + } + $all_versions[] = $fv; + if ($tv > $latest_ota) { + $latest_ota = $tv; + } + if (!isset($update_map[$tv])) { + $update_map[$tv] = array(); + } + $update_map[$tv][] = $fv; + } + + if ($latest_ota === '') { + // Not a single OTA found + continue; + } + + $all_versions = array_unique($all_versions); + $all_versions = array_filter($all_versions, function($e) { + global $latest_ota; + return ($e < $latest_ota); + }); + + $missing_froms = array_diff($all_versions, array($latest_ota), $update_map[$latest_ota]); + rsort($missing_froms); + + if (count($missing_froms) > 0) { + $output[$ref] = array( + 'curef' => $ref, + 'variant' => $vars[$ref], + 'num_missing' => count($missing_froms), + 'missing_froms' => $missing_froms, + 'latest_ota' => $latest_ota, + ); + } +} + +header('Content-Type: text/json'); + +$output = json_encode($output, JSON_PRETTY_PRINT); +if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) { + ini_set('zlib.output_compression', 'Off'); + header('Content-Encoding: gzip'); + $output = gzencode($output); +} + +echo $output;