diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper/ContentProxy.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Helper/ContentProxy.php | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 88873bd5..cd18c668 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php | |||
@@ -34,13 +34,17 @@ class ContentProxy | |||
34 | /** | 34 | /** |
35 | * Update existing entry by fetching from URL using Graby. | 35 | * Update existing entry by fetching from URL using Graby. |
36 | * | 36 | * |
37 | * @param Entry $entry Entry to update | 37 | * @param Entry $entry Entry to update |
38 | * @param string $url Url to grab content for | 38 | * @param string $url Url to grab content for |
39 | */ | 39 | */ |
40 | public function updateEntry(Entry $entry, $url) | 40 | public function updateEntry(Entry $entry, $url) |
41 | { | 41 | { |
42 | $content = $this->graby->fetchContent($url); | 42 | $content = $this->graby->fetchContent($url); |
43 | 43 | ||
44 | // be sure to keep the url in case of error | ||
45 | // so we'll be able to refetch it in the future | ||
46 | $content['url'] = $content['url'] ?: $url; | ||
47 | |||
44 | $this->stockEntry($entry, $content); | 48 | $this->stockEntry($entry, $content); |
45 | } | 49 | } |
46 | 50 | ||
@@ -53,7 +57,14 @@ class ContentProxy | |||
53 | */ | 57 | */ |
54 | public function importEntry(Entry $entry, array $content, $disableContentUpdate = false) | 58 | public function importEntry(Entry $entry, array $content, $disableContentUpdate = false) |
55 | { | 59 | { |
56 | $this->validateContent($content); | 60 | try { |
61 | $this->validateContent($content); | ||
62 | } catch (\Exception $e) { | ||
63 | // validation failed but do we want to disable updating content? | ||
64 | if (true === $disableContentUpdate) { | ||
65 | throw $e; | ||
66 | } | ||
67 | } | ||
57 | 68 | ||
58 | if (false === $disableContentUpdate) { | 69 | if (false === $disableContentUpdate) { |
59 | try { | 70 | try { |
@@ -79,8 +90,8 @@ class ContentProxy | |||
79 | * Stock entry with fetched or imported content. | 90 | * Stock entry with fetched or imported content. |
80 | * Will fall back to OpenGraph data if available. | 91 | * Will fall back to OpenGraph data if available. |
81 | * | 92 | * |
82 | * @param Entry $entry Entry to stock | 93 | * @param Entry $entry Entry to stock |
83 | * @param array $content Array with at least title and URL | 94 | * @param array $content Array with at least title and URL |
84 | */ | 95 | */ |
85 | private function stockEntry(Entry $entry, array $content) | 96 | private function stockEntry(Entry $entry, array $content) |
86 | { | 97 | { |
@@ -162,15 +173,15 @@ class ContentProxy | |||
162 | */ | 173 | */ |
163 | private function validateContent(array $content) | 174 | private function validateContent(array $content) |
164 | { | 175 | { |
165 | if (!empty($content['title']))) { | 176 | if (empty($content['title'])) { |
166 | throw new Exception('Missing title from imported entry!'); | 177 | throw new Exception('Missing title from imported entry!'); |
167 | } | 178 | } |
168 | 179 | ||
169 | if (!empty($content['url']))) { | 180 | if (empty($content['url'])) { |
170 | throw new Exception('Missing URL from imported entry!'); | 181 | throw new Exception('Missing URL from imported entry!'); |
171 | } | 182 | } |
172 | 183 | ||
173 | if (!empty($content['html']))) { | 184 | if (empty($content['html'])) { |
174 | throw new Exception('Missing html from imported entry!'); | 185 | throw new Exception('Missing html from imported entry!'); |
175 | } | 186 | } |
176 | } | 187 | } |