From a0127d980c37b69c48db6982733fac60eaf8601c Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 15 Oct 2016 01:27:39 +0200 Subject: Fix bug JSON import duplicates https://github.com/FreshRSS/FreshRSS/issues/1312 --- app/Controllers/importExportController.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'app/Controllers/importExportController.php') diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 9dfc479f0..c2e68f465 100644 --- a/app/Controllers/importExportController.php +++ b/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 = $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; -- cgit v1.2.3