diff options
Diffstat (limited to 'src')
16 files changed, 105 insertions, 70 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index c3ba1858..93c8157e 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php | |||
@@ -231,7 +231,6 @@ class EntryRestController extends WallabagRestController | |||
231 | $this->validateAuthentication(); | 231 | $this->validateAuthentication(); |
232 | 232 | ||
233 | $urls = json_decode($request->query->get('urls', [])); | 233 | $urls = json_decode($request->query->get('urls', [])); |
234 | $results = []; | ||
235 | 234 | ||
236 | $limit = $this->container->getParameter('wallabag_core.api_limit_mass_actions'); | 235 | $limit = $this->container->getParameter('wallabag_core.api_limit_mass_actions'); |
237 | 236 | ||
@@ -239,32 +238,34 @@ class EntryRestController extends WallabagRestController | |||
239 | throw new HttpException(400, 'API limit reached'); | 238 | throw new HttpException(400, 'API limit reached'); |
240 | } | 239 | } |
241 | 240 | ||
241 | $results = []; | ||
242 | if (empty($urls)) { | ||
243 | return $this->sendResponse($results); | ||
244 | } | ||
245 | |||
242 | // handle multiple urls | 246 | // handle multiple urls |
243 | if (!empty($urls)) { | 247 | foreach ($urls as $key => $url) { |
244 | foreach ($urls as $key => $url) { | 248 | $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId( |
245 | $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId( | 249 | $url, |
246 | $url, | 250 | $this->getUser()->getId() |
247 | $this->getUser()->getId() | 251 | ); |
248 | ); | ||
249 | |||
250 | $results[$key]['url'] = $url; | ||
251 | |||
252 | if (false === $entry) { | ||
253 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry( | ||
254 | new Entry($this->getUser()), | ||
255 | $url | ||
256 | ); | ||
257 | } | ||
258 | 252 | ||
259 | $em = $this->getDoctrine()->getManager(); | 253 | $results[$key]['url'] = $url; |
260 | $em->persist($entry); | ||
261 | $em->flush(); | ||
262 | 254 | ||
263 | $results[$key]['entry'] = $entry instanceof Entry ? $entry->getId() : false; | 255 | if (false === $entry) { |
256 | $entry = new Entry($this->getUser()); | ||
264 | 257 | ||
265 | // entry saved, dispatch event about it! | 258 | $this->get('wallabag_core.content_proxy')->updateEntry($entry, $url); |
266 | $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); | ||
267 | } | 259 | } |
260 | |||
261 | $em = $this->getDoctrine()->getManager(); | ||
262 | $em->persist($entry); | ||
263 | $em->flush(); | ||
264 | |||
265 | $results[$key]['entry'] = $entry instanceof Entry ? $entry->getId() : false; | ||
266 | |||
267 | // entry saved, dispatch event about it! | ||
268 | $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); | ||
268 | } | 269 | } |
269 | 270 | ||
270 | return $this->sendResponse($results); | 271 | return $this->sendResponse($results); |
@@ -315,7 +316,7 @@ class EntryRestController extends WallabagRestController | |||
315 | } | 316 | } |
316 | 317 | ||
317 | try { | 318 | try { |
318 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry( | 319 | $this->get('wallabag_core.content_proxy')->updateEntry( |
319 | $entry, | 320 | $entry, |
320 | $url, | 321 | $url, |
321 | [ | 322 | [ |
@@ -428,7 +429,7 @@ class EntryRestController extends WallabagRestController | |||
428 | $this->validateUserAccess($entry->getUser()->getId()); | 429 | $this->validateUserAccess($entry->getUser()->getId()); |
429 | 430 | ||
430 | try { | 431 | try { |
431 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); | 432 | $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); |
432 | } catch (\Exception $e) { | 433 | } catch (\Exception $e) { |
433 | $this->get('logger')->error('Error while saving an entry', [ | 434 | $this->get('logger')->error('Error while saving an entry', [ |
434 | 'exception' => $e, | 435 | 'exception' => $e, |
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 9fe3e693..fafa49f1 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -53,22 +53,17 @@ class EntryController extends Controller | |||
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Fetch content and update entry. | 55 | * Fetch content and update entry. |
56 | * In case it fails, entry will return to avod loosing the data. | 56 | * In case it fails, $entry->getContent will return an error message. |
57 | * | 57 | * |
58 | * @param Entry $entry | 58 | * @param Entry $entry |
59 | * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded | 59 | * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded |
60 | * | ||
61 | * @return Entry | ||
62 | */ | 60 | */ |
63 | private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved') | 61 | private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved') |
64 | { | 62 | { |
65 | // put default title in case of fetching content failed | ||
66 | $entry->setTitle('No title found'); | ||
67 | |||
68 | $message = 'flashes.entry.notice.'.$prefixMessage; | 63 | $message = 'flashes.entry.notice.'.$prefixMessage; |
69 | 64 | ||
70 | try { | 65 | try { |
71 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); | 66 | $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); |
72 | } catch (\Exception $e) { | 67 | } catch (\Exception $e) { |
73 | $this->get('logger')->error('Error while saving an entry', [ | 68 | $this->get('logger')->error('Error while saving an entry', [ |
74 | 'exception' => $e, | 69 | 'exception' => $e, |
@@ -79,8 +74,6 @@ class EntryController extends Controller | |||
79 | } | 74 | } |
80 | 75 | ||
81 | $this->get('session')->getFlashBag()->add('notice', $message); | 76 | $this->get('session')->getFlashBag()->add('notice', $message); |
82 | |||
83 | return $entry; | ||
84 | } | 77 | } |
85 | 78 | ||
86 | /** | 79 | /** |
diff --git a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php index 75b37729..8b5b5744 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php | |||
@@ -41,6 +41,8 @@ class Configuration implements ConfigurationInterface | |||
41 | ->end() | 41 | ->end() |
42 | ->scalarNode('fetching_error_message') | 42 | ->scalarNode('fetching_error_message') |
43 | ->end() | 43 | ->end() |
44 | ->scalarNode('fetching_error_message_title') | ||
45 | ->end() | ||
44 | ->scalarNode('action_mark_as_read') | 46 | ->scalarNode('action_mark_as_read') |
45 | ->defaultValue(1) | 47 | ->defaultValue(1) |
46 | ->end() | 48 | ->end() |
diff --git a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php index c075c19f..a2a703cb 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php | |||
@@ -26,6 +26,7 @@ class WallabagCoreExtension extends Extension | |||
26 | $container->setParameter('wallabag_core.action_mark_as_read', $config['action_mark_as_read']); | 26 | $container->setParameter('wallabag_core.action_mark_as_read', $config['action_mark_as_read']); |
27 | $container->setParameter('wallabag_core.list_mode', $config['list_mode']); | 27 | $container->setParameter('wallabag_core.list_mode', $config['list_mode']); |
28 | $container->setParameter('wallabag_core.fetching_error_message', $config['fetching_error_message']); | 28 | $container->setParameter('wallabag_core.fetching_error_message', $config['fetching_error_message']); |
29 | $container->setParameter('wallabag_core.fetching_error_message_title', $config['fetching_error_message_title']); | ||
29 | $container->setParameter('wallabag_core.api_limit_mass_actions', $config['api_limit_mass_actions']); | 30 | $container->setParameter('wallabag_core.api_limit_mass_actions', $config['api_limit_mass_actions']); |
30 | 31 | ||
31 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | 32 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 8ba77ca9..bfaa1976 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php | |||
@@ -31,27 +31,20 @@ class ContentProxy | |||
31 | } | 31 | } |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * Fetch content using graby and hydrate given $entry with results information. | 34 | * Update entry using either fetched or provided content. |
35 | * In case we couldn't find content, we'll try to use Open Graph data. | ||
36 | * | 35 | * |
37 | * We can also force the content, in case of an import from the v1 for example, so the function won't | 36 | * @param Entry $entry Entry to update |
38 | * fetch the content from the website but rather use information given with the $content parameter. | 37 | * @param string $url Url of the content |
39 | * | 38 | * @param array $content Array with content provided for import with AT LEAST keys title, html, url to skip the fetchContent from the url |
40 | * @param Entry $entry Entry to update | 39 | * @param bool $disableContentUpdate Whether to skip trying to fetch content using Graby |
41 | * @param string $url Url to grab content for | ||
42 | * @param array $content An array with AT LEAST keys title, html, url to skip the fetchContent from the url | ||
43 | * | ||
44 | * @return Entry | ||
45 | */ | 40 | */ |
46 | public function updateEntry(Entry $entry, $url, array $content = []) | 41 | public function updateEntry(Entry $entry, $url, array $content = [], $disableContentUpdate = false) |
47 | { | 42 | { |
48 | // ensure content is a bit cleaned up | ||
49 | if (!empty($content['html'])) { | 43 | if (!empty($content['html'])) { |
50 | $content['html'] = $this->graby->cleanupHtml($content['html'], $url); | 44 | $content['html'] = $this->graby->cleanupHtml($content['html'], $url); |
51 | } | 45 | } |
52 | 46 | ||
53 | // do we have to fetch the content or the provided one is ok? | 47 | if ((empty($content) || false === $this->validateContent($content)) && false === $disableContentUpdate) { |
54 | if (empty($content) || false === $this->validateContent($content)) { | ||
55 | $fetchedContent = $this->graby->fetchContent($url); | 48 | $fetchedContent = $this->graby->fetchContent($url); |
56 | 49 | ||
57 | // when content is imported, we have information in $content | 50 | // when content is imported, we have information in $content |
@@ -61,6 +54,22 @@ class ContentProxy | |||
61 | } | 54 | } |
62 | } | 55 | } |
63 | 56 | ||
57 | // be sure to keep the url in case of error | ||
58 | // so we'll be able to refetch it in the future | ||
59 | $content['url'] = !empty($content['url']) ? $content['url'] : $url; | ||
60 | |||
61 | $this->stockEntry($entry, $content); | ||
62 | } | ||
63 | |||
64 | /** | ||
65 | * Stock entry with fetched or imported content. | ||
66 | * Will fall back to OpenGraph data if available. | ||
67 | * | ||
68 | * @param Entry $entry Entry to stock | ||
69 | * @param array $content Array with at least title, url & html | ||
70 | */ | ||
71 | private function stockEntry(Entry $entry, array $content) | ||
72 | { | ||
64 | $title = $content['title']; | 73 | $title = $content['title']; |
65 | if (!$title && !empty($content['open_graph']['og_title'])) { | 74 | if (!$title && !empty($content['open_graph']['og_title'])) { |
66 | $title = $content['open_graph']['og_title']; | 75 | $title = $content['open_graph']['og_title']; |
@@ -76,7 +85,7 @@ class ContentProxy | |||
76 | } | 85 | } |
77 | } | 86 | } |
78 | 87 | ||
79 | $entry->setUrl($content['url'] ?: $url); | 88 | $entry->setUrl($content['url']); |
80 | $entry->setTitle($title); | 89 | $entry->setTitle($title); |
81 | $entry->setContent($html); | 90 | $entry->setContent($html); |
82 | $entry->setHttpStatus(isset($content['status']) ? $content['status'] : ''); | 91 | $entry->setHttpStatus(isset($content['status']) ? $content['status'] : ''); |
@@ -92,7 +101,7 @@ class ContentProxy | |||
92 | try { | 101 | try { |
93 | $entry->setPublishedAt(new \DateTime($date)); | 102 | $entry->setPublishedAt(new \DateTime($date)); |
94 | } catch (\Exception $e) { | 103 | } catch (\Exception $e) { |
95 | $this->logger->warning('Error while defining date', ['e' => $e, 'url' => $url, 'date' => $content['date']]); | 104 | $this->logger->warning('Error while defining date', ['e' => $e, 'url' => $content['url'], 'date' => $content['date']]); |
96 | } | 105 | } |
97 | } | 106 | } |
98 | 107 | ||
@@ -126,17 +135,14 @@ class ContentProxy | |||
126 | $this->tagger->tag($entry); | 135 | $this->tagger->tag($entry); |
127 | } catch (\Exception $e) { | 136 | } catch (\Exception $e) { |
128 | $this->logger->error('Error while trying to automatically tag an entry.', [ | 137 | $this->logger->error('Error while trying to automatically tag an entry.', [ |
129 | 'entry_url' => $url, | 138 | 'entry_url' => $content['url'], |
130 | 'error_msg' => $e->getMessage(), | 139 | 'error_msg' => $e->getMessage(), |
131 | ]); | 140 | ]); |
132 | } | 141 | } |
133 | |||
134 | return $entry; | ||
135 | } | 142 | } |
136 | 143 | ||
137 | /** | 144 | /** |
138 | * Validate that the given content as enough value to be used | 145 | * Validate that the given content has at least a title, an html and a url. |
139 | * instead of fetch the content from the url. | ||
140 | * | 146 | * |
141 | * @param array $content | 147 | * @param array $content |
142 | * | 148 | * |
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index a68b2fdc..a9b0d2d5 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml | |||
@@ -41,6 +41,7 @@ services: | |||
41 | arguments: | 41 | arguments: |
42 | - | 42 | - |
43 | error_message: '%wallabag_core.fetching_error_message%' | 43 | error_message: '%wallabag_core.fetching_error_message%' |
44 | error_message_title: '%wallabag_core.fetching_error_message_title%' | ||
44 | - "@wallabag_core.guzzle.http_client" | 45 | - "@wallabag_core.guzzle.http_client" |
45 | - "@wallabag_core.graby.config_builder" | 46 | - "@wallabag_core.graby.config_builder" |
46 | calls: | 47 | calls: |
diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php index ce72837a..5f1ab0af 100644 --- a/src/Wallabag/ImportBundle/Command/ImportCommand.php +++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php | |||
@@ -5,6 +5,7 @@ namespace Wallabag\ImportBundle\Command; | |||
5 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | 5 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
6 | use Symfony\Component\Config\Definition\Exception\Exception; | 6 | use Symfony\Component\Config\Definition\Exception\Exception; |
7 | use Symfony\Component\Console\Input\InputArgument; | 7 | use Symfony\Component\Console\Input\InputArgument; |
8 | use Symfony\Component\Console\Input\InputOption; | ||
8 | use Symfony\Component\Console\Input\InputInterface; | 9 | use Symfony\Component\Console\Input\InputInterface; |
9 | use Symfony\Component\Console\Output\OutputInterface; | 10 | use Symfony\Component\Console\Output\OutputInterface; |
10 | 11 | ||
@@ -17,9 +18,10 @@ class ImportCommand extends ContainerAwareCommand | |||
17 | ->setDescription('Import entries from a JSON export') | 18 | ->setDescription('Import entries from a JSON export') |
18 | ->addArgument('username', InputArgument::REQUIRED, 'User to populate') | 19 | ->addArgument('username', InputArgument::REQUIRED, 'User to populate') |
19 | ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file') | 20 | ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file') |
20 | ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, readability, firefox or chrome', 'v1') | 21 | ->addOption('importer', null, InputOption::VALUE_OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, readability, firefox or chrome', 'v1') |
21 | ->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false) | 22 | ->addOption('markAsRead', null, InputOption::VALUE_OPTIONAL, 'Mark all entries as read', false) |
22 | ->addOption('useUserId', null, InputArgument::OPTIONAL, 'Use user id instead of username to find account', false) | 23 | ->addOption('useUserId', null, InputOption::VALUE_NONE, 'Use user id instead of username to find account') |
24 | ->addOption('disableContentUpdate', null, InputOption::VALUE_NONE, 'Disable fetching updated content from URL') | ||
23 | ; | 25 | ; |
24 | } | 26 | } |
25 | 27 | ||
@@ -69,6 +71,7 @@ class ImportCommand extends ContainerAwareCommand | |||
69 | } | 71 | } |
70 | 72 | ||
71 | $import->setMarkAsRead($input->getOption('markAsRead')); | 73 | $import->setMarkAsRead($input->getOption('markAsRead')); |
74 | $import->setDisableContentUpdate($input->getOption('disableContentUpdate')); | ||
72 | $import->setUser($user); | 75 | $import->setUser($user); |
73 | 76 | ||
74 | $res = $import | 77 | $res = $import |
diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php index a61388c0..9b624296 100644 --- a/src/Wallabag/ImportBundle/Import/AbstractImport.php +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php | |||
@@ -24,6 +24,7 @@ abstract class AbstractImport implements ImportInterface | |||
24 | protected $producer; | 24 | protected $producer; |
25 | protected $user; | 25 | protected $user; |
26 | protected $markAsRead; | 26 | protected $markAsRead; |
27 | protected $disableContentUpdate = false; | ||
27 | protected $skippedEntries = 0; | 28 | protected $skippedEntries = 0; |
28 | protected $importedEntries = 0; | 29 | protected $importedEntries = 0; |
29 | protected $queuedEntries = 0; | 30 | protected $queuedEntries = 0; |
@@ -85,21 +86,34 @@ abstract class AbstractImport implements ImportInterface | |||
85 | } | 86 | } |
86 | 87 | ||
87 | /** | 88 | /** |
89 | * Set whether articles should be fetched for updated content. | ||
90 | * | ||
91 | * @param bool $disableContentUpdate | ||
92 | */ | ||
93 | public function setDisableContentUpdate($disableContentUpdate) | ||
94 | { | ||
95 | $this->disableContentUpdate = $disableContentUpdate; | ||
96 | |||
97 | return $this; | ||
98 | } | ||
99 | |||
100 | /** | ||
88 | * Fetch content from the ContentProxy (using graby). | 101 | * Fetch content from the ContentProxy (using graby). |
89 | * If it fails return the given entry to be saved in all case (to avoid user to loose the content). | 102 | * If it fails return the given entry to be saved in all case (to avoid user to loose the content). |
90 | * | 103 | * |
91 | * @param Entry $entry Entry to update | 104 | * @param Entry $entry Entry to update |
92 | * @param string $url Url to grab content for | 105 | * @param string $url Url to grab content for |
93 | * @param array $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url | 106 | * @param array $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url |
94 | * | ||
95 | * @return Entry | ||
96 | */ | 107 | */ |
97 | protected function fetchContent(Entry $entry, $url, array $content = []) | 108 | protected function fetchContent(Entry $entry, $url, array $content = []) |
98 | { | 109 | { |
99 | try { | 110 | try { |
100 | return $this->contentProxy->updateEntry($entry, $url, $content); | 111 | $this->contentProxy->updateEntry($entry, $url, $content, $this->disableContentUpdate); |
101 | } catch (\Exception $e) { | 112 | } catch (\Exception $e) { |
102 | return $entry; | 113 | $this->logger->error('Error trying to import an entry.', [ |
114 | 'entry_url' => $url, | ||
115 | 'error_msg' => $e->getMessage(), | ||
116 | ]); | ||
103 | } | 117 | } |
104 | } | 118 | } |
105 | 119 | ||
diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index ef0eeb7e..71e65e59 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php | |||
@@ -201,7 +201,7 @@ abstract class BrowserImport extends AbstractImport | |||
201 | $entry->setTitle($data['title']); | 201 | $entry->setTitle($data['title']); |
202 | 202 | ||
203 | // update entry with content (in case fetching failed, the given entry will be return) | 203 | // update entry with content (in case fetching failed, the given entry will be return) |
204 | $entry = $this->fetchContent($entry, $data['url'], $data); | 204 | $this->fetchContent($entry, $data['url'], $data); |
205 | 205 | ||
206 | if (array_key_exists('tags', $data)) { | 206 | if (array_key_exists('tags', $data)) { |
207 | $this->tagsAssigner->assignTagsToEntry( | 207 | $this->tagsAssigner->assignTagsToEntry( |
diff --git a/src/Wallabag/ImportBundle/Import/InstapaperImport.php b/src/Wallabag/ImportBundle/Import/InstapaperImport.php index c8e0cd5b..3aa12f6f 100644 --- a/src/Wallabag/ImportBundle/Import/InstapaperImport.php +++ b/src/Wallabag/ImportBundle/Import/InstapaperImport.php | |||
@@ -125,7 +125,7 @@ class InstapaperImport extends AbstractImport | |||
125 | $entry->setTitle($importedEntry['title']); | 125 | $entry->setTitle($importedEntry['title']); |
126 | 126 | ||
127 | // update entry with content (in case fetching failed, the given entry will be return) | 127 | // update entry with content (in case fetching failed, the given entry will be return) |
128 | $entry = $this->fetchContent($entry, $importedEntry['url'], $importedEntry); | 128 | $this->fetchContent($entry, $importedEntry['url'], $importedEntry); |
129 | 129 | ||
130 | if (!empty($importedEntry['tags'])) { | 130 | if (!empty($importedEntry['tags'])) { |
131 | $this->tagsAssigner->assignTagsToEntry( | 131 | $this->tagsAssigner->assignTagsToEntry( |
diff --git a/src/Wallabag/ImportBundle/Import/PinboardImport.php b/src/Wallabag/ImportBundle/Import/PinboardImport.php index 489b9257..110b0464 100644 --- a/src/Wallabag/ImportBundle/Import/PinboardImport.php +++ b/src/Wallabag/ImportBundle/Import/PinboardImport.php | |||
@@ -109,7 +109,7 @@ class PinboardImport extends AbstractImport | |||
109 | $entry->setTitle($data['title']); | 109 | $entry->setTitle($data['title']); |
110 | 110 | ||
111 | // update entry with content (in case fetching failed, the given entry will be return) | 111 | // update entry with content (in case fetching failed, the given entry will be return) |
112 | $entry = $this->fetchContent($entry, $data['url'], $data); | 112 | $this->fetchContent($entry, $data['url'], $data); |
113 | 113 | ||
114 | if (!empty($data['tags'])) { | 114 | if (!empty($data['tags'])) { |
115 | $this->tagsAssigner->assignTagsToEntry( | 115 | $this->tagsAssigner->assignTagsToEntry( |
diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php index 8835161b..c1d5b6da 100644 --- a/src/Wallabag/ImportBundle/Import/PocketImport.php +++ b/src/Wallabag/ImportBundle/Import/PocketImport.php | |||
@@ -192,7 +192,7 @@ class PocketImport extends AbstractImport | |||
192 | $entry->setUrl($url); | 192 | $entry->setUrl($url); |
193 | 193 | ||
194 | // update entry with content (in case fetching failed, the given entry will be return) | 194 | // update entry with content (in case fetching failed, the given entry will be return) |
195 | $entry = $this->fetchContent($entry, $url); | 195 | $this->fetchContent($entry, $url); |
196 | 196 | ||
197 | // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted | 197 | // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted |
198 | $entry->setArchived($importedEntry['status'] == 1 || $this->markAsRead); | 198 | $entry->setArchived($importedEntry['status'] == 1 || $this->markAsRead); |
diff --git a/src/Wallabag/ImportBundle/Import/ReadabilityImport.php b/src/Wallabag/ImportBundle/Import/ReadabilityImport.php index de320d23..002b27f4 100644 --- a/src/Wallabag/ImportBundle/Import/ReadabilityImport.php +++ b/src/Wallabag/ImportBundle/Import/ReadabilityImport.php | |||
@@ -109,7 +109,7 @@ class ReadabilityImport extends AbstractImport | |||
109 | $entry->setTitle($data['title']); | 109 | $entry->setTitle($data['title']); |
110 | 110 | ||
111 | // update entry with content (in case fetching failed, the given entry will be return) | 111 | // update entry with content (in case fetching failed, the given entry will be return) |
112 | $entry = $this->fetchContent($entry, $data['url'], $data); | 112 | $this->fetchContent($entry, $data['url'], $data); |
113 | 113 | ||
114 | $entry->setArchived($data['is_archived']); | 114 | $entry->setArchived($data['is_archived']); |
115 | $entry->setStarred($data['is_starred']); | 115 | $entry->setStarred($data['is_starred']); |
diff --git a/src/Wallabag/ImportBundle/Import/WallabagImport.php b/src/Wallabag/ImportBundle/Import/WallabagImport.php index 0e5382cf..c64ccd64 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagImport.php +++ b/src/Wallabag/ImportBundle/Import/WallabagImport.php | |||
@@ -108,7 +108,7 @@ abstract class WallabagImport extends AbstractImport | |||
108 | $entry->setTitle($data['title']); | 108 | $entry->setTitle($data['title']); |
109 | 109 | ||
110 | // update entry with content (in case fetching failed, the given entry will be return) | 110 | // update entry with content (in case fetching failed, the given entry will be return) |
111 | $entry = $this->fetchContent($entry, $data['url'], $data); | 111 | $this->fetchContent($entry, $data['url'], $data); |
112 | 112 | ||
113 | if (array_key_exists('tags', $data)) { | 113 | if (array_key_exists('tags', $data)) { |
114 | $this->tagsAssigner->assignTagsToEntry( | 114 | $this->tagsAssigner->assignTagsToEntry( |
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index 59e3ce02..1f0df646 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php | |||
@@ -4,6 +4,17 @@ namespace Wallabag\ImportBundle\Import; | |||
4 | 4 | ||
5 | class WallabagV1Import extends WallabagImport | 5 | class WallabagV1Import extends WallabagImport |
6 | { | 6 | { |
7 | protected $fetchingErrorMessage; | ||
8 | protected $fetchingErrorMessageTitle; | ||
9 | |||
10 | public function __construct($em, $contentProxy, $tagsAssigner, $eventDispatcher, $fetchingErrorMessageTitle, $fetchingErrorMessage) | ||
11 | { | ||
12 | $this->fetchingErrorMessageTitle = $fetchingErrorMessageTitle; | ||
13 | $this->fetchingErrorMessage = $fetchingErrorMessage; | ||
14 | |||
15 | parent::__construct($em, $contentProxy, $tagsAssigner, $eventDispatcher); | ||
16 | } | ||
17 | |||
7 | /** | 18 | /** |
8 | * {@inheritdoc} | 19 | * {@inheritdoc} |
9 | */ | 20 | */ |
@@ -43,10 +54,11 @@ class WallabagV1Import extends WallabagImport | |||
43 | 'created_at' => '', | 54 | 'created_at' => '', |
44 | ]; | 55 | ]; |
45 | 56 | ||
46 | // force content to be refreshed in case on bad fetch in the v1 installation | 57 | // In case of a bad fetch in v1, replace title and content with v2 error strings |
58 | // If fetching fails again, they will get this instead of the v1 strings | ||
47 | if (in_array($entry['title'], $this->untitled)) { | 59 | if (in_array($entry['title'], $this->untitled)) { |
48 | $data['title'] = ''; | 60 | $data['title'] = $this->fetchingErrorMessageTitle; |
49 | $data['html'] = ''; | 61 | $data['html'] = $this->fetchingErrorMessage; |
50 | } | 62 | } |
51 | 63 | ||
52 | if (array_key_exists('tags', $entry) && $entry['tags'] != '') { | 64 | if (array_key_exists('tags', $entry) && $entry['tags'] != '') { |
diff --git a/src/Wallabag/ImportBundle/Resources/config/services.yml b/src/Wallabag/ImportBundle/Resources/config/services.yml index 661dc7e1..b224a6a2 100644 --- a/src/Wallabag/ImportBundle/Resources/config/services.yml +++ b/src/Wallabag/ImportBundle/Resources/config/services.yml | |||
@@ -35,6 +35,8 @@ services: | |||
35 | - "@wallabag_core.content_proxy" | 35 | - "@wallabag_core.content_proxy" |
36 | - "@wallabag_core.tags_assigner" | 36 | - "@wallabag_core.tags_assigner" |
37 | - "@event_dispatcher" | 37 | - "@event_dispatcher" |
38 | - "%wallabag_core.fetching_error_message_title%" | ||
39 | - "%wallabag_core.fetching_error_message%" | ||
38 | calls: | 40 | calls: |
39 | - [ setLogger, [ "@logger" ]] | 41 | - [ setLogger, [ "@logger" ]] |
40 | tags: | 42 | tags: |