diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-12-04 19:30:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-04 19:30:11 +0100 |
commit | 4a1f963531f04427f625f58bda45723c6e69a87c (patch) | |
tree | f6e3a5e1c27279c09df0904727066ea1b967a7b3 /src/Wallabag/CoreBundle/Helper | |
parent | 1093e979ff49f9072c30d1d576c6adf1f8e76bdf (diff) | |
parent | 106bdbcd0ab6c75937188dfce243167b878e9a8c (diff) | |
download | wallabag-4a1f963531f04427f625f58bda45723c6e69a87c.tar.gz wallabag-4a1f963531f04427f625f58bda45723c6e69a87c.tar.zst wallabag-4a1f963531f04427f625f58bda45723c6e69a87c.zip |
Merge pull request #2679 from jcharaoui/fix-2658
Fix content from imported entried being discarded when URL goes bad
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper')
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/ContentProxy.php | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index fd059325..0130bd2b 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php | |||
@@ -21,14 +21,16 @@ class ContentProxy | |||
21 | protected $logger; | 21 | protected $logger; |
22 | protected $tagRepository; | 22 | protected $tagRepository; |
23 | protected $mimeGuesser; | 23 | protected $mimeGuesser; |
24 | protected $fetchingErrorMessage; | ||
24 | 25 | ||
25 | public function __construct(Graby $graby, RuleBasedTagger $tagger, TagRepository $tagRepository, LoggerInterface $logger) | 26 | public function __construct(Graby $graby, RuleBasedTagger $tagger, TagRepository $tagRepository, LoggerInterface $logger, $fetchingErrorMessage) |
26 | { | 27 | { |
27 | $this->graby = $graby; | 28 | $this->graby = $graby; |
28 | $this->tagger = $tagger; | 29 | $this->tagger = $tagger; |
29 | $this->logger = $logger; | 30 | $this->logger = $logger; |
30 | $this->tagRepository = $tagRepository; | 31 | $this->tagRepository = $tagRepository; |
31 | $this->mimeGuesser = new MimeTypeExtensionGuesser(); | 32 | $this->mimeGuesser = new MimeTypeExtensionGuesser(); |
33 | $this->fetchingErrorMessage = $fetchingErrorMessage; | ||
32 | } | 34 | } |
33 | 35 | ||
34 | /** | 36 | /** |
@@ -48,7 +50,13 @@ class ContentProxy | |||
48 | { | 50 | { |
49 | // do we have to fetch the content or the provided one is ok? | 51 | // do we have to fetch the content or the provided one is ok? |
50 | if (empty($content) || false === $this->validateContent($content)) { | 52 | if (empty($content) || false === $this->validateContent($content)) { |
51 | $content = $this->graby->fetchContent($url); | 53 | $fetchedContent = $this->graby->fetchContent($url); |
54 | |||
55 | // when content is imported, we have information in $content | ||
56 | // in case fetching content goes bad, we'll keep the imported information instead of overriding them | ||
57 | if (empty($content) || $fetchedContent['html'] !== $this->fetchingErrorMessage) { | ||
58 | $content = $fetchedContent; | ||
59 | } | ||
52 | } | 60 | } |
53 | 61 | ||
54 | $title = $content['title']; | 62 | $title = $content['title']; |
@@ -58,7 +66,7 @@ class ContentProxy | |||
58 | 66 | ||
59 | $html = $content['html']; | 67 | $html = $content['html']; |
60 | if (false === $html) { | 68 | if (false === $html) { |
61 | $html = '<p>Unable to retrieve readable content.</p>'; | 69 | $html = $this->fetchingErrorMessage; |
62 | 70 | ||
63 | if (isset($content['open_graph']['og_description'])) { | 71 | if (isset($content['open_graph']['og_description'])) { |
64 | $html .= '<p><i>But we found a short description: </i></p>'; | 72 | $html .= '<p><i>But we found a short description: </i></p>'; |
@@ -71,8 +79,8 @@ class ContentProxy | |||
71 | $entry->setContent($html); | 79 | $entry->setContent($html); |
72 | $entry->setHttpStatus(isset($content['status']) ? $content['status'] : ''); | 80 | $entry->setHttpStatus(isset($content['status']) ? $content['status'] : ''); |
73 | 81 | ||
74 | $entry->setLanguage($content['language']); | 82 | $entry->setLanguage(isset($content['language']) ? $content['language'] : ''); |
75 | $entry->setMimetype($content['content_type']); | 83 | $entry->setMimetype(isset($content['content_type']) ? $content['content_type'] : ''); |
76 | $entry->setReadingTime(Utils::getReadingTime($html)); | 84 | $entry->setReadingTime(Utils::getReadingTime($html)); |
77 | 85 | ||
78 | $domainName = parse_url($entry->getUrl(), PHP_URL_HOST); | 86 | $domainName = parse_url($entry->getUrl(), PHP_URL_HOST); |
@@ -85,7 +93,7 @@ class ContentProxy | |||
85 | } | 93 | } |
86 | 94 | ||
87 | // if content is an image define as a preview too | 95 | // if content is an image define as a preview too |
88 | if (in_array($this->mimeGuesser->guess($content['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) { | 96 | if (isset($content['content_type']) && in_array($this->mimeGuesser->guess($content['content_type']), ['jpeg', 'jpg', 'gif', 'png'], true)) { |
89 | $entry->setPreviewPicture($content['url']); | 97 | $entry->setPreviewPicture($content['url']); |
90 | } | 98 | } |
91 | 99 | ||