aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers/feedController.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2021-01-09 20:51:33 +0100
committerGravatar GitHub <noreply@github.com> 2021-01-09 20:51:33 +0100
commitee7938ed5f26ac48c46269eb16f8e5067605ab27 (patch)
treed47851092bd757915953ca83c8c308b574dfdea5 /app/Controllers/feedController.php
parentf5fdbb9e8211500ce8ffc959808b7891646f9f3c (diff)
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
Diffstat (limited to 'app/Controllers/feedController.php')
-rwxr-xr-xapp/Controllers/feedController.php24
1 files changed, 17 insertions, 7 deletions
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index 73faf8dce..5737a8535 100755
--- a/app/Controllers/feedController.php
+++ b/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;