summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Brahmer <info@b-brahmer.de>2022-05-31 15:46:01 +0200
committerGitHub <noreply@github.com>2022-05-31 15:46:01 +0200
commit1c91928e597cad6d41b10ce4b3f34b130453ad27 (patch)
tree5578acc0411c518fb442972edcc7699981277d90
parentdbb641931699e6918896691992ca4ba61d705dc0 (diff)
If items of feed do not provide an author fallback to feed author (#1803)
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
-rw-r--r--CHANGELOG.md1
-rwxr-xr-xlib/Fetcher/FeedFetcher.php16
-rw-r--r--tests/command/feeds/no_guid_feed.xml (renamed from tests/integration/feeds/no_guid_feed.xml)0
-rw-r--r--tests/command/helpers/settings.bash2
-rw-r--r--tests/command/items.bats14
5 files changed, 28 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index db792e696..2b1c5f58f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@ The format is mostly based on [Keep a Changelog](https://keepachangelog.com/en/1
# Unreleased
## [18.x.x]
### Changed
+- If items of feed do not provide an author fallback to feed author (#1803)
### Fixed
diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php
index 27421f525..209722c97 100755
--- a/lib/Fetcher/FeedFetcher.php
+++ b/lib/Fetcher/FeedFetcher.php
@@ -134,6 +134,7 @@ class FeedFetcher implements IFeedFetcher
$items = [];
$RTL = $this->determineRtl($parsedFeed);
$feedName = $parsedFeed->getTitle();
+ $feedAuthor = $parsedFeed->getAuthor();
$this->logger->debug(
'Feed {url} was modified since last fetch. #{count} items',
[
@@ -155,7 +156,7 @@ class FeedFetcher implements IFeedFetcher
}
}
- $builtItem = $this->buildItem($item, $body, $currRTL);
+ $builtItem = $this->buildItem($item, $body, $currRTL, $feedAuthor);
$this->logger->debug(
'Added item {title} for feed {feed} lastmodified: {datetime}',
[
@@ -226,11 +227,16 @@ class FeedFetcher implements IFeedFetcher
* @param ItemInterface $parsedItem The item to use
* @param string|null $body Text of the item, if not provided use description from $parsedItem
* @param bool $RTL True if the feed is RTL (Right-to-left)
+ * @param string|null $feedAuthor Author of the feed as fallback when the item has no Author
*
* @return Item
*/
- protected function buildItem(ItemInterface $parsedItem, ?string $body = null, bool $RTL = false): Item
- {
+ protected function buildItem(
+ ItemInterface $parsedItem,
+ ?string $body = null,
+ bool $RTL = false,
+ $feedAuthor = null
+ ): Item {
$item = new Item();
$item->setUnread(true);
$itemLink = $parsedItem->getLink();
@@ -272,7 +278,9 @@ class FeedFetcher implements IFeedFetcher
if ($itemTitle !== null) {
$item->setTitle($this->decodeTwice($itemTitle));
}
- $author = $parsedItem->getAuthor();
+
+ $author = $parsedItem->getAuthor() ?? $feedAuthor;
+
if ($author !== null && $author->getName() !== null) {
$item->setAuthor($this->decodeTwice($author->getName()));
}
diff --git a/tests/integration/feeds/no_guid_feed.xml b/tests/command/feeds/no_guid_feed.xml
index e27a1b07b..e27a1b07b 100644
--- a/tests/integration/feeds/no_guid_feed.xml
+++ b/tests/command/feeds/no_guid_feed.xml
diff --git a/tests/command/helpers/settings.bash b/tests/command/helpers/settings.bash
index bf58a601a..d32924ceb 100644
--- a/tests/command/helpers/settings.bash
+++ b/tests/command/helpers/settings.bash
@@ -1,4 +1,4 @@
user=admin
NC_FEED="https://nextcloud.com/blog/static-feed/"
HEISE_FEED="https://www.heise.de/rss/heise-atom.xml"
-NO_GUID_FEED="https://raw.githubusercontent.com/nextcloud/news/master/tests/integration/feeds/no_guid_feed.xml"
+NO_GUID_FEED="https://raw.githubusercontent.com/nextcloud/news/master/tests/command/feeds/no_guid_feed.xml"
diff --git a/tests/command/items.bats b/tests/command/items.bats
index 22a4c73c7..8a7111299 100644
--- a/tests/command/items.bats
+++ b/tests/command/items.bats
@@ -82,3 +82,17 @@ teardown() {
return $ret_status
fi
}
+
+@test "[$TESTSUITE] Test author fallback" {
+ ./occ news:feed:add "$user" $HEISE_FEED --title "Something-${BATS_SUITE_TEST_NUMBER}"
+ ID=$(./occ news:feed:list 'admin' | grep 'heise\.de' -1 | head -1 | grep -oE '[0-9]*')
+
+ run ./occ news:item:list-feed "$user" "$ID" --limit 200
+ [ "$status" -eq 0 ]
+
+ if ! echo "$output" | grep '"author": "heise online",'; then
+ ret_status=$?
+ echo "Author fallback did not work"
+ return $ret_status
+ fi
+} \ No newline at end of file