From be97de5fdb390b9299e073a4f62b2c7f19b4ce97 Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Sat, 16 Apr 2022 19:14:21 +0200 Subject: [PATCH] fix import of items when feed does not exist Signed-off-by: Benjamin Brahmer --- CHANGELOG.md | 1 + lib/Service/ImportService.php | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e4e50aa0b..a51c125d2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is mostly based on [Keep a Changelog](https://keepachangelog.com/en/1 ### Changed ### Fixed +- Fix import of items when feed does not exist (1742) # Releases ## [18.0.1-beta2] - 2022-03-22 diff --git a/lib/Service/ImportService.php b/lib/Service/ImportService.php index 7b593356e5..68782dbd42 100644 --- a/lib/Service/ImportService.php +++ b/lib/Service/ImportService.php @@ -75,8 +75,6 @@ public function __construct( */ public function importArticles(string $userId, array $json): ?\OCP\AppFramework\Db\Entity { - $url = 'http://nextcloud/nofeed'; - // build assoc array for fast access $feeds = $this->feedService->findAllForUser($userId); $feedsDict = []; @@ -90,21 +88,22 @@ public function importArticles(string $userId, array $json): ?\OCP\AppFramework\ // if the feed does not exist, create a separate feed for them foreach ($json as $entry) { $item = Item::fromImport($entry); - $feedLink = $entry['feedLink']; // this is not set on the item yet + $feedLink = $entry['feedLink']; // this is not set on the item if (array_key_exists($feedLink, $feedsDict)) { $feed = $feedsDict[$feedLink]; } else { + $this->logger->info("Creating new feed for import of {url}", ['url' => $feedLink]); $createdFeed = true; $feed = new Feed(); $feed->setUserId($userId) - ->setUrlHash(md5($url)) - ->setLink($url) - ->setUrl($url) - ->setTitle('Articles without feed') + ->setUrlHash(md5($feedLink)) + ->setLink($feedLink) + ->setUrl($feedLink) + ->setTitle('No Title') ->setAdded(time()) ->setFolderId(null) - ->setPreventUpdate(true); + ->setPreventUpdate(false); /** @var Feed $feed */ $feed = $this->feedService->insert($feed); @@ -121,6 +120,6 @@ public function importArticles(string $userId, array $json): ?\OCP\AppFramework\ return null; } - return $this->feedService->findByURL($userId, $url); + return $this->feedService->findByURL($userId, $feedLink); } }