aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-12-27 15:18:36 +0100
committerGravatar GitHub <noreply@github.com> 2023-12-27 15:18:36 +0100
commitd65f77c081e756997e59e602f49eeea9b09799ff (patch)
tree0094569a28b089a90ce146ee3782cfbff4fc0be9
parente9689645383d37231afa9dbbcd9bd765b804046d (diff)
More robust assignment of categories to feeds (#5986)
Several minor cases, none of which should really be necessary Might help: https://github.com/FreshRSS/FreshRSS/issues/5981 https://github.com/FreshRSS/FreshRSS/issues/5982
-rw-r--r--app/Controllers/feedController.php7
-rw-r--r--app/Controllers/statsController.php2
-rw-r--r--app/Models/Category.php3
-rw-r--r--app/Models/CategoryDAO.php1
-rw-r--r--app/Models/Context.php4
-rw-r--r--app/Services/ImportService.php1
6 files changed, 11 insertions, 7 deletions
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index cc560a224..be86afb2d 100644
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -64,7 +64,6 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
if ($cat === null) {
$catDAO->checkDefault();
}
- $cat_id = $cat === null ? FreshRSS_CategoryDAO::DEFAULTCATEGORYID : $cat->id();
$feed = new FreshRSS_Feed($url); //Throws FreshRSS_BadUrl_Exception
$title = trim($title);
@@ -74,7 +73,11 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
$feed->_kind($kind);
$feed->_attributes($attributes);
$feed->_httpAuth($http_auth);
- $feed->_categoryId($cat_id);
+ if ($cat === null) {
+ $feed->_categoryId(FreshRSS_CategoryDAO::DEFAULTCATEGORYID);
+ } else {
+ $feed->_category($cat);
+ }
switch ($kind) {
case FreshRSS_Feed::KIND_RSS:
case FreshRSS_Feed::KIND_RSS_FORCED:
diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php
index 4ecd7fa2b..f40f0dd29 100644
--- a/app/Controllers/statsController.php
+++ b/app/Controllers/statsController.php
@@ -221,7 +221,7 @@ class FreshRSS_stats_Controller extends FreshRSS_ActionController {
$id = null;
}
- $this->view->categories = $categoryDAO->listCategories() ?: [];
+ $this->view->categories = $categoryDAO->listCategories(true) ?: [];
$this->view->feed = $id === null ? null : $feedDAO->searchById($id);
$this->view->days = $statsDAO->getDays();
$this->view->months = $statsDAO->getMonths();
diff --git a/app/Models/Category.php b/app/Models/Category.php
index cc25a1ec0..49ef2d283 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -153,6 +153,7 @@ class FreshRSS_Category extends Minz_Model {
if ($this->feeds === null) {
$this->feeds = [];
}
+ $feed->_category($this);
$this->feeds[] = $feed;
$this->sortFeeds();
@@ -210,7 +211,7 @@ class FreshRSS_Category extends Minz_Model {
foreach ($dryRunCategory->feeds() as $dryRunFeed) {
if (empty($existingFeeds[$dryRunFeed->url()])) {
// The feed does not exist in the current category, so add that feed
- $dryRunFeed->_categoryId($this->id());
+ $dryRunFeed->_category($this);
$ok &= ($feedDAO->addFeedObject($dryRunFeed) !== false);
} else {
$existingFeed = $existingFeeds[$dryRunFeed->url()];
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index 417ff7a6c..a22cda420 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -401,6 +401,7 @@ SQL;
foreach ($categories as $category) {
foreach ($category->feeds() as $feed) {
if ($feed->id() === $feed_id) {
+ $feed->_category($category); // Should already be done; just to be safe
return $feed;
}
}
diff --git a/app/Models/Context.php b/app/Models/Context.php
index 3ea5a29eb..bb6fa4cbd 100644
--- a/app/Models/Context.php
+++ b/app/Models/Context.php
@@ -362,7 +362,7 @@ final class FreshRSS_Context {
if (empty(self::$categories)) {
$catDAO = FreshRSS_Factory::createCategoryDao();
- self::$categories = $catDAO->listCategories();
+ self::$categories = $catDAO->listCategories(true);
}
switch($type) {
@@ -458,7 +458,7 @@ final class FreshRSS_Context {
if (empty(self::$categories)) {
$catDAO = FreshRSS_Factory::createCategoryDao();
- self::$categories = $catDAO->listCategories();
+ self::$categories = $catDAO->listCategories(true);
}
if (FreshRSS_Context::userConf()->onread_jump_next && strlen($get) > 2) {
diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php
index 278fa4cec..dace91a22 100644
--- a/app/Services/ImportService.php
+++ b/app/Services/ImportService.php
@@ -149,7 +149,6 @@ class FreshRSS_Import_Service {
try {
// Create a Feed object and add it in DB
$feed = new FreshRSS_Feed($url);
- $feed->_categoryId($category->id());
$category->addFeed($feed);
$feed->_name($name);
$feed->_website($website);