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/Category.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'app/Models/Category.php') diff --git a/app/Models/Category.php b/app/Models/Category.php index 5f87335f3..feaf7b79c 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -19,7 +19,7 @@ class FreshRSS_Category extends Minz_Model { private string $name; private int $nbFeeds = -1; private int $nbNotRead = -1; - /** @var list|null */ + /** @var array|null where the key is the feed ID */ private ?array $feeds = null; /** @var bool|int */ private $hasFeedsWithError = false; @@ -100,7 +100,7 @@ class FreshRSS_Category extends Minz_Model { } /** - * @return list + * @return array where the key is the feed ID * @throws Minz_ConfigurationNamespaceException * @throws Minz_PDOConnectionException */ @@ -157,9 +157,11 @@ class FreshRSS_Category extends Minz_Model { if ($this->feeds === null) { $this->feeds = []; } - $feed->_category($this); - $this->feeds[] = $feed; - $this->sortFeeds(); + if ($feed->id() !== 0) { + $feed->_category($this); + $this->feeds[$feed->id()] = $feed; + $this->sortFeeds(); + } } /** @@ -243,7 +245,7 @@ class FreshRSS_Category extends Minz_Model { if ($this->feeds === null) { return; } - usort($this->feeds, static fn(FreshRSS_Feed $a, FreshRSS_Feed $b) => strnatcasecmp($a->name(), $b->name())); + uasort($this->feeds, static fn(FreshRSS_Feed $a, FreshRSS_Feed $b) => strnatcasecmp($a->name(), $b->name())); } /** @@ -265,13 +267,13 @@ class FreshRSS_Category extends Minz_Model { /** * Access cached feeds * @param array $categories - * @return list + * @return array where the key is the feed ID */ public static function findFeeds(array $categories): array { $result = []; foreach ($categories as $category) { foreach ($category->feeds() as $feed) { - $result[] = $feed; + $result[$feed->id()] = $feed; } } return $result; -- cgit v1.2.3