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

Do not import feed causing DB error (#3347)

* Do not import feed causing DB error

The DB error might be that the new feed tries to redirect to an already
existing feed, in which case
#fix https://github.com/FreshRSS/FreshRSS/issues/3339

* Add feed bug
Alexandre Alapetite пре 5 година
родитељ
комит
ee7938ed5f
2 измењених фајлова са 19 додато и 7 уклоњено
  1. 17 7
      app/Controllers/feedController.php
  2. 2 0
      app/Models/Entry.php

+ 17 - 7
app/Controllers/feedController.php

@@ -90,7 +90,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 			'name' => $title != '' ? $title : $feed->name(),
 			'website' => $feed->website(),
 			'description' => $feed->description(),
-			'lastUpdate' => time(),
+			'lastUpdate' => 0,
 			'httpAuth' => $feed->httpAuth(),
 			'attributes' => $feed->attributes(),
 		);
@@ -103,7 +103,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 		$feed->_id($id);
 
 		// Ok, feed has been added in database. Now we have to refresh entries.
-		self::actualizeFeed($id, $url, false, null, true);
+		self::actualizeFeed($id, $url, false, null);
 
 		return $feed;
 	}
@@ -256,7 +256,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 		}
 	}
 
-	public static function actualizeFeed($feed_id, $feed_url, $force, $simplePiePush = null, $isNewFeed = false, $noCommit = false, $maxFeeds = 10) {
+	public static function actualizeFeed($feed_id, $feed_url, $force, $simplePiePush = null, $noCommit = false, $maxFeeds = 10) {
 		@set_time_limit(300);
 
 		$feedDAO = FreshRSS_Factory::createFeedDao();
@@ -325,6 +325,8 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 				continue;
 			}
 
+			$isNewFeed = $feed->lastUpdate() <= 0;
+
 			try {
 				if ($simplePiePush) {
 					$simplePie = $simplePiePush;	//Used by WebSub
@@ -469,7 +471,13 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 				}
 			}
 			if (!empty($feedProperties)) {
-				$feedDAO->updateFeed($feed->id(), $feedProperties);
+				$ok = $feedDAO->updateFeed($feed->id(), $feedProperties);
+				if (!$ok && $isNewFeed) {
+					//Cancel adding new feed in case of database error at first actualize
+					$feedDAO->deleteFeed($feed->id());
+					$feed->unlock();
+					break;
+				}
 			}
 
 			$feed->faviconPrepare();
@@ -537,7 +545,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 			$databaseDAO = FreshRSS_Factory::createDatabaseDAO();
 			$databaseDAO->minorDbMaintenance();
 		} else {
-			list($updated_feeds, $feed, $nb_new_articles) = self::actualizeFeed($id, $url, $force, null, false, $noCommit, $maxFeeds);
+			list($updated_feeds, $feed, $nb_new_articles) = self::actualizeFeed($id, $url, $force, null, $noCommit, $maxFeeds);
 		}
 
 		if (Minz_Request::param('ajax')) {
@@ -721,6 +729,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 		}
 
 		//Re-fetch articles as if the feed was new.
+		$feedDAO->updateFeed($feed->id(), [ 'lastUpdate' => 0 ]);
 		self::actualizeFeed($feed_id, null, false, null, true);
 
 		//Extract all feed entries from database, load complete content and store them back in database.
@@ -731,8 +740,9 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 		$entryDAO2 = FreshRSS_Factory::createEntryDao();
 
 		foreach ($entries as $entry) {
-			$entry->loadCompleteContent(true);
-			$entryDAO2->updateEntry($entry->toArray());
+			if ($entry->loadCompleteContent(true)) {
+				$entryDAO2->updateEntry($entry->toArray());
+			}
 		}
 
 		Minz_ModelPdo::$usesSharedPdo = true;

+ 2 - 0
app/Models/Entry.php

@@ -442,6 +442,7 @@ class FreshRSS_Entry extends Minz_Model {
 					);
 					if ($fullContent != '') {
 						$this->content = $fullContent;
+						return true;
 					}
 				} catch (Exception $e) {
 					// rien à faire, on garde l'ancien contenu(requête a échoué)
@@ -449,6 +450,7 @@ class FreshRSS_Entry extends Minz_Model {
 				}
 			}
 		}
+		return false;
 	}
 
 	public function toArray() {