Преглед изворни кода

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
Alexandre Alapetite пре 2 година
родитељ
комит
d65f77c081

+ 5 - 2
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:

+ 1 - 1
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();

+ 2 - 1
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()];

+ 1 - 0
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;
 				}
 			}

+ 2 - 2
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) {

+ 0 - 1
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);