aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-12-04 19:30:11 +0100
committerGitHub <noreply@github.com>2016-12-04 19:30:11 +0100
commit4a1f963531f04427f625f58bda45723c6e69a87c (patch)
treef6e3a5e1c27279c09df0904727066ea1b967a7b3 /src/Wallabag
parent1093e979ff49f9072c30d1d576c6adf1f8e76bdf (diff)
parent106bdbcd0ab6c75937188dfce243167b878e9a8c (diff)
downloadwallabag-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')
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php20
-rw-r--r--src/Wallabag/CoreBundle/Resources/config/services.yml1
-rw-r--r--src/Wallabag/ImportBundle/Import/ChromeImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/FirefoxImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/InstapaperImport.php3
-rw-r--r--src/Wallabag/ImportBundle/Import/PinboardImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/ReadabilityImport.php3
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV1Import.php2
8 files changed, 19 insertions, 16 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
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:
86 - "@wallabag_core.rule_based_tagger" 86 - "@wallabag_core.rule_based_tagger"
87 - "@wallabag_core.tag_repository" 87 - "@wallabag_core.tag_repository"
88 - "@logger" 88 - "@logger"
89 - '%wallabag_core.fetching_error_message%'
89 90
90 wallabag_core.rule_based_tagger: 91 wallabag_core.rule_based_tagger:
91 class: Wallabag\CoreBundle\Helper\RuleBasedTagger 92 class: Wallabag\CoreBundle\Helper\RuleBasedTagger
diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php
index d7620bcb..1a324934 100644
--- a/src/Wallabag/ImportBundle/Import/ChromeImport.php
+++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php
@@ -37,7 +37,7 @@ class ChromeImport extends BrowserImport
37 { 37 {
38 $data = [ 38 $data = [
39 'title' => $entry['name'], 39 'title' => $entry['name'],
40 'html' => '', 40 'html' => false,
41 'url' => $entry['url'], 41 'url' => $entry['url'],
42 'is_archived' => $this->markAsRead, 42 'is_archived' => $this->markAsRead,
43 'tags' => '', 43 'tags' => '',
diff --git a/src/Wallabag/ImportBundle/Import/FirefoxImport.php b/src/Wallabag/ImportBundle/Import/FirefoxImport.php
index e010f5a4..d3f99770 100644
--- a/src/Wallabag/ImportBundle/Import/FirefoxImport.php
+++ b/src/Wallabag/ImportBundle/Import/FirefoxImport.php
@@ -37,7 +37,7 @@ class FirefoxImport extends BrowserImport
37 { 37 {
38 $data = [ 38 $data = [
39 'title' => $entry['title'], 39 'title' => $entry['title'],
40 'html' => '', 40 'html' => false,
41 'url' => $entry['uri'], 41 'url' => $entry['uri'],
42 'is_archived' => $this->markAsRead, 42 'is_archived' => $this->markAsRead,
43 'tags' => '', 43 'tags' => '',
diff --git a/src/Wallabag/ImportBundle/Import/InstapaperImport.php b/src/Wallabag/ImportBundle/Import/InstapaperImport.php
index cf4c785c..70a53f1a 100644
--- a/src/Wallabag/ImportBundle/Import/InstapaperImport.php
+++ b/src/Wallabag/ImportBundle/Import/InstapaperImport.php
@@ -74,8 +74,7 @@ class InstapaperImport extends AbstractImport
74 'status' => $data[3], 74 'status' => $data[3],
75 'is_archived' => $data[3] === 'Archive' || $data[3] === 'Starred', 75 'is_archived' => $data[3] === 'Archive' || $data[3] === 'Starred',
76 'is_starred' => $data[3] === 'Starred', 76 'is_starred' => $data[3] === 'Starred',
77 'content_type' => '', 77 'html' => false,
78 'language' => '',
79 ]; 78 ];
80 } 79 }
81 fclose($handle); 80 fclose($handle);
diff --git a/src/Wallabag/ImportBundle/Import/PinboardImport.php b/src/Wallabag/ImportBundle/Import/PinboardImport.php
index 9bcfbc36..d9865534 100644
--- a/src/Wallabag/ImportBundle/Import/PinboardImport.php
+++ b/src/Wallabag/ImportBundle/Import/PinboardImport.php
@@ -98,8 +98,6 @@ class PinboardImport extends AbstractImport
98 $data = [ 98 $data = [
99 'title' => $importedEntry['description'], 99 'title' => $importedEntry['description'],
100 'url' => $importedEntry['href'], 100 'url' => $importedEntry['href'],
101 'content_type' => '',
102 'language' => '',
103 'is_archived' => ('no' === $importedEntry['toread']) || $this->markAsRead, 101 'is_archived' => ('no' === $importedEntry['toread']) || $this->markAsRead,
104 'is_starred' => false, 102 'is_starred' => false,
105 'created_at' => $importedEntry['time'], 103 'created_at' => $importedEntry['time'],
diff --git a/src/Wallabag/ImportBundle/Import/ReadabilityImport.php b/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
index b8c0f777..de320d23 100644
--- a/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
+++ b/src/Wallabag/ImportBundle/Import/ReadabilityImport.php
@@ -98,11 +98,10 @@ class ReadabilityImport extends AbstractImport
98 $data = [ 98 $data = [
99 'title' => $importedEntry['article__title'], 99 'title' => $importedEntry['article__title'],
100 'url' => $importedEntry['article__url'], 100 'url' => $importedEntry['article__url'],
101 'content_type' => '',
102 'language' => '',
103 'is_archived' => $importedEntry['archive'] || $this->markAsRead, 101 'is_archived' => $importedEntry['archive'] || $this->markAsRead,
104 'is_starred' => $importedEntry['favorite'], 102 'is_starred' => $importedEntry['favorite'],
105 'created_at' => $importedEntry['date_added'], 103 'created_at' => $importedEntry['date_added'],
104 'html' => false,
106 ]; 105 ];
107 106
108 $entry = new Entry($this->user); 107 $entry = new Entry($this->user);
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
index 4f001062..59e3ce02 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
@@ -37,8 +37,6 @@ class WallabagV1Import extends WallabagImport
37 'title' => $entry['title'], 37 'title' => $entry['title'],
38 'html' => $entry['content'], 38 'html' => $entry['content'],
39 'url' => $entry['url'], 39 'url' => $entry['url'],
40 'content_type' => '',
41 'language' => '',
42 'is_archived' => $entry['is_read'] || $this->markAsRead, 40 'is_archived' => $entry['is_read'] || $this->markAsRead,
43 'is_starred' => $entry['is_fav'], 41 'is_starred' => $entry['is_fav'],
44 'tags' => '', 42 'tags' => '',