From 913d17605723f9b947f55e6981771a9f33addfa5 Mon Sep 17 00:00:00 2001 From: Ben Vidulich Date: Tue, 6 Aug 2024 00:14:24 +1000 Subject: [PATCH 1/3] fix: store http last modified data from response headers Signed-off-by: Ben Vidulich --- lib/Fetcher/FeedFetcher.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php index c0477407c6..0204f9e87d 100755 --- a/lib/Fetcher/FeedFetcher.php +++ b/lib/Fetcher/FeedFetcher.php @@ -142,7 +142,8 @@ public function fetch( $feed = $this->buildFeed( $parsedFeed, $url, - $location + $location, + $resource->getResponse()->getLastModified() ); $items = []; @@ -485,7 +486,7 @@ protected function getFavicon(FeedInterface $feed, string $url): ?string * * @return Feed */ - protected function buildFeed(FeedInterface $feed, string $url, string $location): Feed + protected function buildFeed(FeedInterface $feed, string $url, string $location, ?DateTime $httpLastModified): Feed { $newFeed = new Feed(); @@ -497,8 +498,8 @@ protected function buildFeed(FeedInterface $feed, string $url, string $location) $newFeed->setUrl($url); // the url used to add the feed $newFeed->setLocation($location); // the url where the feed was found $newFeed->setLink($feed->getLink()); // attribute in the feed - if ($feed->getLastModified() instanceof DateTime) { - $newFeed->setHttpLastModified($feed->getLastModified()->format(DateTime::RSS)); + if ($httpLastModified instanceof DateTime) { + $newFeed->setHttpLastModified($httpLastModified->format(DateTime::RSS)); } $newFeed->setAdded($this->time->getTime()); From ccdf92d0d4981409e3fb5a3284e3c0cbf4736104 Mon Sep 17 00:00:00 2001 From: Ben Vidulich Date: Thu, 8 Aug 2024 19:39:37 +1000 Subject: [PATCH 2/3] fix: preserve last modified when unchanged Signed-off-by: Ben Vidulich --- CHANGELOG.md | 3 ++- lib/Fetcher/FeedFetcher.php | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb7f5a3221..e4aaf4e9cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the ### Fixed -- Allow feed title to be null in DB. #2745 +- Allow feed title to be null in DB. (#2745) +- Store HTTP last modified date from response header (#2724) # Releases ## [25.0.0-alpha8] - 2024-07-07 diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php index 0204f9e87d..30999c78b0 100755 --- a/lib/Fetcher/FeedFetcher.php +++ b/lib/Fetcher/FeedFetcher.php @@ -142,10 +142,15 @@ public function fetch( $feed = $this->buildFeed( $parsedFeed, $url, - $location, - $resource->getResponse()->getLastModified() + $location ); + if (!is_null($resource->getResponse()->getLastModified())) { + $feed->setHttpLastModified($resource->getResponse()->getLastModified()->format(DateTime::RSS)); + } elseif (!is_null($lastModified)) { + $feed->setHttpLastModified($lastModified->format(DateTime::RSS)); + } + $items = []; $RTL = $this->determineRtl($parsedFeed); $feedName = $parsedFeed->getTitle(); @@ -486,7 +491,7 @@ protected function getFavicon(FeedInterface $feed, string $url): ?string * * @return Feed */ - protected function buildFeed(FeedInterface $feed, string $url, string $location, ?DateTime $httpLastModified): Feed + protected function buildFeed(FeedInterface $feed, string $url, string $location): Feed { $newFeed = new Feed(); @@ -498,8 +503,8 @@ protected function buildFeed(FeedInterface $feed, string $url, string $location, $newFeed->setUrl($url); // the url used to add the feed $newFeed->setLocation($location); // the url where the feed was found $newFeed->setLink($feed->getLink()); // attribute in the feed - if ($httpLastModified instanceof DateTime) { - $newFeed->setHttpLastModified($httpLastModified->format(DateTime::RSS)); + if ($feed->getLastModified() instanceof DateTime) { + $newFeed->setHttpLastModified($feed->getLastModified()->format(DateTime::RSS)); } $newFeed->setAdded($this->time->getTime()); From 008c189157b89db859f6ae12bae736d74d95340c Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Sat, 21 Sep 2024 07:53:42 +0200 Subject: [PATCH 3/3] remove deprecated code Signed-off-by: Benjamin Brahmer --- lib/Fetcher/FeedFetcher.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php index 30999c78b0..f826461b4e 100755 --- a/lib/Fetcher/FeedFetcher.php +++ b/lib/Fetcher/FeedFetcher.php @@ -73,7 +73,7 @@ class FeedFetcher implements IFeedFetcher * @var FetcherConfig */ private $fetcherConfig; - + /** * @var Cache */ @@ -379,11 +379,11 @@ protected function getFavicon(FeedInterface $feed, string $url): ?string $favicon = null; // trim the string because authors do funny things $feed_logo = $feed->getLogo(); - + if (!is_null($feed_logo)) { $favicon = trim($feed_logo); } - + ini_set('user_agent', FetcherConfig::DEFAULT_USER_AGENT); $base_url = new Net_URL2($url); @@ -500,16 +500,12 @@ protected function buildFeed(FeedInterface $feed, string $url, string $location) $title = strip_tags($this->decodeTwice($feed->getTitle())); $newFeed->setTitle($title); } + $newFeed->setUrl($url); // the url used to add the feed $newFeed->setLocation($location); // the url where the feed was found $newFeed->setLink($feed->getLink()); // attribute in the feed - if ($feed->getLastModified() instanceof DateTime) { - $newFeed->setHttpLastModified($feed->getLastModified()->format(DateTime::RSS)); - } $newFeed->setAdded($this->time->getTime()); - - $favicon = $this->getFavicon($feed, $url); $newFeed->setFaviconLink($favicon);