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
This commit is contained in:
Alexandre Alapetite
2023-12-27 15:18:36 +01:00
committed by GitHub
parent e968964538
commit d65f77c081
6 changed files with 11 additions and 7 deletions

View File

@@ -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:

View File

@@ -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();

View File

@@ -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()];

View File

@@ -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;
}
}

View File

@@ -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) {

View File

@@ -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);