Retain imported content if fetching fails, fixes #2658

This commit is contained in:
Jerome Charaoui 2016-12-02 22:41:35 -05:00
parent 1093e979ff
commit 29dca43236
2 changed files with 8 additions and 2 deletions

View File

@ -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'];

View File

@ -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