From c41022f4bc49ce9b76aa8bb9dee6c03d13c4f899 Mon Sep 17 00:00:00 2001 From: Marius Burkard Date: Fri, 21 Jul 2017 20:23:27 +0200 Subject: [PATCH 1/2] - fix version sorting in APS installer --- interface/lib/classes/aps_guicontroller.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/lib/classes/aps_guicontroller.inc.php b/interface/lib/classes/aps_guicontroller.inc.php index ab7f3f4daf..16dd9e82f1 100644 --- a/interface/lib/classes/aps_guicontroller.inc.php +++ b/interface/lib/classes/aps_guicontroller.inc.php @@ -166,7 +166,7 @@ class ApsGUIController extends ApsBase FROM aps_packages WHERE name = (SELECT name FROM aps_packages WHERE id = ?) AND package_status = 2 - ORDER BY REPLACE(version, '.', '')+0 DESC, `release` DESC", $id); + ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(version,'.0.0.0'),'.',4)) DESC, `release` DESC", $id); if(!empty($result) && ($id != $result['id'])) return $result['id']; -- GitLab From 40978bc72f606540af941159d6dea95739f31449 Mon Sep 17 00:00:00 2001 From: Marius Burkard Date: Sat, 22 Jul 2017 19:28:04 +0200 Subject: [PATCH 2/2] - fixed outdated tagging on aps crawler --- interface/lib/classes/aps_crawler.inc.php | 28 +++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/interface/lib/classes/aps_crawler.inc.php b/interface/lib/classes/aps_crawler.inc.php index 99db77bdbf..a8fe812d28 100644 --- a/interface/lib/classes/aps_crawler.inc.php +++ b/interface/lib/classes/aps_crawler.inc.php @@ -261,10 +261,13 @@ class ApsCrawler extends ApsBase // Get all known apps from the database and the highest known version // Note: A dirty hack is used for numerical sorting of the VARCHAR field Version: +0 -> cast // A longer but typesafe way would be: ORDER BY CAST(REPLACE(Version, '.', '') AS UNSIGNED) DESC - $existing_apps = $app->db->queryAllRecords("SELECT * FROM ( - SELECT name AS Name, CONCAT(version, '-', CAST(`release` AS CHAR)) AS CurrentVersion - FROM aps_packages ORDER BY REPLACE(version, '.', '')+0 DESC, `release` DESC - ) as Versions GROUP BY name"); + $existing_apps = array(); + $tmpres = $app->db->query("SELECT name as `Name`, CONCAT(version, '-', CAST(`release` AS CHAR)) AS CurrentVersion FROM aps_packages ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(version,'.0.0.0'),'.',4)) DESC, `release` DESC"); + while($tmp = $tmpres->get()) { + if(!array_key_exists($tmp['Name'], $existing_apps)) $existing_apps[$tmp['Name']] = $tmp; + } + $tmpres->free(); + unset($tmp); //var_dump($existing_apps); // Used for statistics later @@ -492,6 +495,23 @@ class ApsCrawler extends ApsBase $app->log($this->log_prefix.'Processed '.$apps_in_repo. ' apps from the repo. Downloaded '.$apps_updated. ' updates, '.$apps_downloaded.' new apps'); + + $prevapp = ''; + $res = $app->db->query("SELECT `id`, `name`, `version`, `release`, `package_status` FROM `aps_packages` WHERE 1 ORDER BY `name` ASC, INET_ATON(SUBSTRING_INDEX(CONCAT(version,'.0.0.0'),'.',4)) DESC, `release` DESC"); + while($curapp = $res->get()) { + if($curapp['name'] != $prevapp) { + $prevapp = $curapp['name']; + continue; + } + if($curapp['package_status'] != PACKAGE_OUTDATED) { + $app->log($this->log_prefix.'Tagging ' . $curapp['name'] . ' ' . $curapp['version'] . '-' . $curapp['release'] . ' as outdated.'); + $app->db->query("UPDATE `aps_packages` SET `package_status` = ? WHERE `id` = ?", PACKAGE_OUTDATED, $curapp['id']); + $app->db->datalogUpdate('aps_packages', array("package_status" => PACKAGE_OUTDATED), 'id', $curapp['id']); + } + } + $res->free(); + unset($curapp); + unset($prevapp); } catch(Exception $e) -- GitLab