diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-08-22 23:03:16 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-08-22 23:03:16 +0200 |
commit | 79efca1e6ff28362d4bd2713f68205294cdd07de (patch) | |
tree | c20482071f97b5ba0f075d59a9a097b08b26b910 /src/Wallabag/ImportBundle/Import/AbstractImport.php | |
parent | 9c545fe028013b30417c1a932cd6b9027bff752d (diff) | |
parent | 80bb0b73445092c4aa3e94f90cc5f8667fa123ba (diff) | |
download | wallabag-79efca1e6ff28362d4bd2713f68205294cdd07de.tar.gz wallabag-79efca1e6ff28362d4bd2713f68205294cdd07de.tar.zst wallabag-79efca1e6ff28362d4bd2713f68205294cdd07de.zip |
Merge remote-tracking branch 'origin/master' into 2.1
Diffstat (limited to 'src/Wallabag/ImportBundle/Import/AbstractImport.php')
-rw-r--r-- | src/Wallabag/ImportBundle/Import/AbstractImport.php | 47 |
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 | |||
3 | namespace Wallabag\ImportBundle\Import; | ||
4 | |||
5 | use Psr\Log\LoggerInterface; | ||
6 | use Psr\Log\NullLogger; | ||
7 | use Doctrine\ORM\EntityManager; | ||
8 | use Wallabag\CoreBundle\Helper\ContentProxy; | ||
9 | use Wallabag\CoreBundle\Entity\Entry; | ||
10 | |||
11 | abstract 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 | } | ||