Skip to content

Commit 41e2b4d

Browse files
author
Marius Burkard
committed
Merge branch 'patch_aps_version' into 'stable-3.1'
Fix APS crawler and listing See merge request !618
2 parents 0490950 + 40978bc commit 41e2b4d

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

interface/lib/classes/aps_crawler.inc.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,13 @@ public function startCrawler()
261261
// Get all known apps from the database and the highest known version
262262
// Note: A dirty hack is used for numerical sorting of the VARCHAR field Version: +0 -> cast
263263
// A longer but typesafe way would be: ORDER BY CAST(REPLACE(Version, '.', '') AS UNSIGNED) DESC
264-
$existing_apps = $app->db->queryAllRecords("SELECT * FROM (
265-
SELECT name AS Name, CONCAT(version, '-', CAST(`release` AS CHAR)) AS CurrentVersion
266-
FROM aps_packages ORDER BY REPLACE(version, '.', '')+0 DESC, `release` DESC
267-
) as Versions GROUP BY name");
264+
$existing_apps = array();
265+
$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");
266+
while($tmp = $tmpres->get()) {
267+
if(!array_key_exists($tmp['Name'], $existing_apps)) $existing_apps[$tmp['Name']] = $tmp;
268+
}
269+
$tmpres->free();
270+
unset($tmp);
268271
//var_dump($existing_apps);
269272

270273
// Used for statistics later
@@ -492,6 +495,23 @@ public function startCrawler()
492495
$app->log($this->log_prefix.'Processed '.$apps_in_repo.
493496
' apps from the repo. Downloaded '.$apps_updated.
494497
' updates, '.$apps_downloaded.' new apps');
498+
499+
$prevapp = '';
500+
$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");
501+
while($curapp = $res->get()) {
502+
if($curapp['name'] != $prevapp) {
503+
$prevapp = $curapp['name'];
504+
continue;
505+
}
506+
if($curapp['package_status'] != PACKAGE_OUTDATED) {
507+
$app->log($this->log_prefix.'Tagging ' . $curapp['name'] . ' ' . $curapp['version'] . '-' . $curapp['release'] . ' as outdated.');
508+
$app->db->query("UPDATE `aps_packages` SET `package_status` = ? WHERE `id` = ?", PACKAGE_OUTDATED, $curapp['id']);
509+
$app->db->datalogUpdate('aps_packages', array("package_status" => PACKAGE_OUTDATED), 'id', $curapp['id']);
510+
}
511+
}
512+
$res->free();
513+
unset($curapp);
514+
unset($prevapp);
495515
}
496516

497517
catch(Exception $e)

interface/lib/classes/aps_guicontroller.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function getNewestPackageID($id)
166166
FROM aps_packages
167167
WHERE name = (SELECT name FROM aps_packages WHERE id = ?)
168168
AND package_status = 2
169-
ORDER BY REPLACE(version, '.', '')+0 DESC, `release` DESC", $id);
169+
ORDER BY INET_ATON(SUBSTRING_INDEX(CONCAT(version,'.0.0.0'),'.',4)) DESC, `release` DESC", $id);
170170

171171
if(!empty($result) && ($id != $result['id'])) return $result['id'];
172172

0 commit comments

Comments
 (0)