Explorar o código

Merge pull request #1315 from Alkarex/import_duplicates

Fix bug JSON import duplicates
Alexandre Alapetite %!s(int64=9) %!d(string=hai) anos
pai
achega
98a0389262
Modificáronse 2 ficheiros con 14 adicións e 1 borrados
  1. 1 0
      CHANGELOG.md
  2. 13 1
      app/Controllers/importExportController.php

+ 1 - 0
CHANGELOG.md

@@ -22,6 +22,7 @@
 	* Correction of bugs related CSRF tokens introduced in version 1.5.0 [#1253](https://github.com/FreshRSS/FreshRSS/issues/1253), [44f22ab](https://github.com/FreshRSS/FreshRSS/pull/1261/commits/d9bf9b2c6f0b2cc9dec3b638841b7e3040dcf46f)
 	* Fix bug in Global view introduced in version 1.5.0 [#1269](https://github.com/FreshRSS/FreshRSS/pull/1269)
 	* Fix sharing bug [#1289](https://github.com/FreshRSS/FreshRSS/issues/1289)
+	* Fix bug during import of favourites [#1315](https://github.com/FreshRSS/FreshRSS/pull/1315), [#1312](https://github.com/FreshRSS/FreshRSS/issues/1312)
 	* Fix bug not respecting language option for new users [#1273](https://github.com/FreshRSS/FreshRSS/issues/1273)
 	* Bug in example of URL for FreshRS RSS output with token [#1274](https://github.com/FreshRSS/FreshRSS/issues/1274)
 * SimplePie

+ 13 - 1
app/Controllers/importExportController.php

@@ -360,6 +360,14 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
 			}
 		}
 
+		$newGuids = array();
+		foreach ($article_object['items'] as $item) {
+			$newGuids[] = $item['id'];
+		}
+		// For this feed, check existing GUIDs already in database.
+		$existingHashForGuids = $this->entryDAO->listHashForFeedGuids($feed->id(), $newGuids);
+		unset($newGuids);
+
 		// Then, articles are imported.
 		$this->entryDAO->beginTransaction();
 		foreach ($article_object['items'] as $item) {
@@ -395,7 +403,11 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
 			}
 
 			$values = $entry->toArray();
-			$id = $this->entryDAO->addEntry($values);
+			if (isset($existingHashForGuids[$entry->guid()])) {
+				$id = $this->entryDAO->updateEntry($values);
+			} else {
+				$id = $this->entryDAO->addEntry($values);
+			}
 
 			if (!$error && ($id === false)) {
 				$error = true;