From e99728abae73ce7276d84a0706f48de5965de4bf Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Thu, 4 Aug 2022 19:21:32 +0200 Subject: change autodiscover behaviour to only run if the provided url is not already a feed Signed-off-by: Benjamin Brahmer --- CHANGELOG.md | 2 +- lib/Service/FeedServiceV2.php | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d95a84d9..fbc2aaeac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ The format is mostly based on [Keep a Changelog](https://keepachangelog.com/en/1 # Unreleased ## [18.x.x] ### Changed - +- Change autodiscover to only run after fetching the given url has failed (#1860) ### Fixed # Releases diff --git a/lib/Service/FeedServiceV2.php b/lib/Service/FeedServiceV2.php index bb1be8dcb..1d78c1549 100644 --- a/lib/Service/FeedServiceV2.php +++ b/lib/Service/FeedServiceV2.php @@ -196,13 +196,6 @@ class FeedServiceV2 extends Service throw new ServiceConflictException('Feed with this URL exists'); } - if ($full_discover) { - $feeds = $this->explorer->discover($feedUrl); - if ($feeds !== []) { - $feedUrl = array_shift($feeds); - } - } - try { /** * @var Feed $feed @@ -211,7 +204,21 @@ class FeedServiceV2 extends Service list($feed, $items) = $this->feedFetcher->fetch($feedUrl, $full_text, $user, $password); } catch (ReadErrorException $ex) { $this->logger->debug($ex->getMessage()); - throw new ServiceNotFoundException($ex->getMessage()); + # the url did not lead to a valid feed, try autodiscover + if ($full_discover) { + $this->logger->warning("No valid feed found at URL, attempting auto discovery"); + $feeds = $this->explorer->discover($feedUrl); + if ($feeds !== []) { + $feedUrl = array_shift($feeds); + } + try { + list($feed, $items) = $this->feedFetcher->fetch($feedUrl, $full_text, $user, $password); + } catch (ReadErrorException $ex) { + throw new ServiceNotFoundException($ex->getMessage()); + } + } else { + throw new ServiceNotFoundException($ex->getMessage()); + } } if ($feed === null) { -- cgit v1.2.3