diff options
| author | 2024-12-28 23:58:00 +0100 | |
|---|---|---|
| committer | 2024-12-28 23:58:00 +0100 | |
| commit | c29cbb7b8be95fee249ed1a21dce98a4772d92e2 (patch) | |
| tree | b116f6033ea081c6cc5f82ce83156f2a7021166c /app/Models/Category.php | |
| parent | 33cdfbb309c61167cf1c81273eb242f94ca8f996 (diff) | |
Fix regressions on some array structures (#7155)
regressions from https://github.com/FreshRSS/FreshRSS/pull/7131
fix https://github.com/FreshRSS/FreshRSS/issues/7154
Diffstat (limited to 'app/Models/Category.php')
| -rw-r--r-- | app/Models/Category.php | 18 |
1 files changed, 10 insertions, 8 deletions
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<FreshRSS_Feed>|null */ + /** @var array<int,FreshRSS_Feed>|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<FreshRSS_Feed> + * @return array<int,FreshRSS_Feed> 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<FreshRSS_Category> $categories - * @return list<FreshRSS_Feed> + * @return array<int,FreshRSS_Feed> 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; |
