aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Import/AbstractImport.php
diff options
context:
space:
mode:
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}