From c29cbb7b8be95fee249ed1a21dce98a4772d92e2 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 28 Dec 2024 23:58:00 +0100 Subject: Fix regressions on some array structures (#7155) regressions from https://github.com/FreshRSS/FreshRSS/pull/7131 fix https://github.com/FreshRSS/FreshRSS/issues/7154 --- app/Models/FeedDAO.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'app/Models/FeedDAO.php') diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index 676b93b7f..d4255cb63 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -325,7 +325,7 @@ SQL; return null; } $feeds = self::daoToFeeds($res); // @phpstan-ignore argument.type - return $feeds[0] ?? null; + return $feeds[$id] ?? null; } public function searchByUrl(string $url): ?FreshRSS_Feed { @@ -342,9 +342,7 @@ SQL; return $res; } - /** - * @return list - */ + /** @return array where the key is the feed ID */ public function listFeeds(): array { $sql = 'SELECT * FROM `_feed` ORDER BY name'; $res = $this->fetchAssoc($sql); @@ -373,7 +371,7 @@ SQL; /** * @param int $defaultCacheDuration Use -1 to return all feeds, without filtering them by TTL. - * @return list + * @return array where the key is the feed ID */ public function listFeedsOrderUpdate(int $defaultCacheDuration = 3600, int $limit = 0): array { $sql = 'SELECT id, url, kind, category, name, website, `lastUpdate`, `pathEntries`, `httpAuth`, ttl, attributes, `cache_nbEntries`, `cache_nbUnreads` ' @@ -409,7 +407,7 @@ SQL; /** * @param bool|null $muted to include only muted feeds * @param bool|null $errored to include only errored feeds - * @return list + * @return array where the key is the feed ID */ public function listByCategory(int $cat, ?bool $muted = null, ?bool $errored = null): array { $sql = 'SELECT * FROM `_feed` WHERE category=:category'; @@ -424,7 +422,7 @@ SQL; return []; } $feeds = self::daoToFeeds($res); // @phpstan-ignore argument.type - usort($feeds, static fn(FreshRSS_Feed $a, FreshRSS_Feed $b) => strnatcasecmp($a->name(), $b->name())); + uasort($feeds, static fn(FreshRSS_Feed $a, FreshRSS_Feed $b) => strnatcasecmp($a->name(), $b->name())); return $feeds; } @@ -569,7 +567,7 @@ SQL; /** * @param array $listDAO - * @return list + * @return array where the key is the feed ID */ public static function daoToFeeds(array $listDAO, ?int $catID = null): array { $list = []; @@ -602,7 +600,7 @@ SQL; if (isset($dao['id'])) { $myFeed->_id($dao['id']); } - $list[] = $myFeed; + $list[$myFeed->id()] = $myFeed; } return $list; -- cgit v1.2.3