aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Import/AbstractImport.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-08-19 23:52:19 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-08-20 01:17:26 +0200
commit19d9efab32b5c6403e9ee95fb70a2ce56a27f14b (patch)
tree325d2724ae5e5988b2ab77a33cf3f4cfe88c3647 /src/Wallabag/ImportBundle/Import/AbstractImport.php
parente408d7e895e784271a55c3a200666034db0af80a (diff)
downloadwallabag-19d9efab32b5c6403e9ee95fb70a2ce56a27f14b.tar.gz
wallabag-19d9efab32b5c6403e9ee95fb70a2ce56a27f14b.tar.zst
wallabag-19d9efab32b5c6403e9ee95fb70a2ce56a27f14b.zip
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.
Diffstat (limited to 'src/Wallabag/ImportBundle/Import/AbstractImport.php')
-rw-r--r--src/Wallabag/ImportBundle/Import/AbstractImport.php47
1 files changed, 47 insertions, 0 deletions
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 @@
1<?php
2
3namespace Wallabag\ImportBundle\Import;
4
5use Psr\Log\LoggerInterface;
6use Psr\Log\NullLogger;
7use Doctrine\ORM\EntityManager;
8use Wallabag\CoreBundle\Helper\ContentProxy;
9use Wallabag\CoreBundle\Entity\Entry;
10
11abstract class AbstractImport implements ImportInterface
12{
13 protected $em;
14 protected $logger;
15 protected $contentProxy;
16
17 public function __construct(EntityManager $em, ContentProxy $contentProxy)
18 {
19 $this->em = $em;
20 $this->logger = new NullLogger();
21 $this->contentProxy = $contentProxy;
22 }
23
24 public function setLogger(LoggerInterface $logger)
25 {
26 $this->logger = $logger;
27 }
28
29 /**
30 * Fetch content from the ContentProxy (using graby).
31 * If it fails return false instead of the updated entry.
32 *
33 * @param Entry $entry Entry to update
34 * @param string $url Url to grab content for
35 * @param array $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url
36 *
37 * @return Entry|false
38 */
39 protected function fetchContent(Entry $entry, $url, array $content = [])
40 {
41 try {
42 return $this->contentProxy->updateEntry($entry, $url, $content);
43 } catch (\Exception $e) {
44 return false;
45 }
46 }
47}