From 19d9efab32b5c6403e9ee95fb70a2ce56a27f14b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 19 Aug 2016 23:52:19 +0200 Subject: Avoid breaking import when fetching fail graby will throw an Exception in some case (like a bad url, a restricted url or a secured pdf). Import doesn't handle that case and break the whole import. With that commit the import isn't stopped but the entry is just skipped. Also, as a bonus, I've added extra test on WallabagImportV2 when the json is empty. --- .../ImportBundle/Import/AbstractImport.php | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/Wallabag/ImportBundle/Import/AbstractImport.php (limited to 'src/Wallabag/ImportBundle/Import/AbstractImport.php') diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php new file mode 100644 index 00000000..14377a35 --- /dev/null +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php @@ -0,0 +1,47 @@ +em = $em; + $this->logger = new NullLogger(); + $this->contentProxy = $contentProxy; + } + + public function setLogger(LoggerInterface $logger) + { + $this->logger = $logger; + } + + /** + * Fetch content from the ContentProxy (using graby). + * If it fails return false instead of the updated entry. + * + * @param Entry $entry Entry to update + * @param string $url Url to grab content for + * @param array $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url + * + * @return Entry|false + */ + protected function fetchContent(Entry $entry, $url, array $content = []) + { + try { + return $this->contentProxy->updateEntry($entry, $url, $content); + } catch (\Exception $e) { + return false; + } + } +} -- cgit v1.2.3