diff options
Diffstat (limited to 'src/Wallabag/CoreBundle')
5 files changed, 33 insertions, 30 deletions
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: |