From 29dca43236001221be947179df0caa8aee966f6d Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Fri, 2 Dec 2016 22:41:35 -0500 Subject: [PATCH] Retain imported content if fetching fails, fixes #2658 --- src/Wallabag/CoreBundle/Helper/ContentProxy.php | 9 +++++++-- src/Wallabag/CoreBundle/Resources/config/services.yml | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index fd059325..77acbd6c 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php @@ -21,14 +21,16 @@ class ContentProxy protected $logger; protected $tagRepository; protected $mimeGuesser; + protected $fetchingErrorMessage; - public function __construct(Graby $graby, RuleBasedTagger $tagger, TagRepository $tagRepository, LoggerInterface $logger) + public function __construct(Graby $graby, RuleBasedTagger $tagger, TagRepository $tagRepository, LoggerInterface $logger, $fetchingErrorMessage) { $this->graby = $graby; $this->tagger = $tagger; $this->logger = $logger; $this->tagRepository = $tagRepository; $this->mimeGuesser = new MimeTypeExtensionGuesser(); + $this->fetchingErrorMessage = $fetchingErrorMessage; } /** @@ -48,7 +50,10 @@ class ContentProxy { // do we have to fetch the content or the provided one is ok? if (empty($content) || false === $this->validateContent($content)) { - $content = $this->graby->fetchContent($url); + $fetchedContent = $this->graby->fetchContent($url); + if (empty($content) || $fetchedContent['html'] !== $this->fetchingErrorMessage) { + $content = $fetchedContent; + } } $title = $content['title']; diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index bcf0c9ca..fadd5e49 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -86,6 +86,7 @@ services: - "@wallabag_core.rule_based_tagger" - "@wallabag_core.tag_repository" - "@logger" + - '%wallabag_core.fetching_error_message%' wallabag_core.rule_based_tagger: class: Wallabag\CoreBundle\Helper\RuleBasedTagger -- 2.41.0