Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix import of items when feed does not exist #1742

Merged
merged 1 commit into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions lib/Service/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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);
Expand All @@ -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);
}
}