diff options
Diffstat (limited to 'src/Wallabag/ImportBundle/Import/AbstractImport.php')
-rw-r--r-- | src/Wallabag/ImportBundle/Import/AbstractImport.php | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php index 1d4a6e27..9b624296 100644 --- a/src/Wallabag/ImportBundle/Import/AbstractImport.php +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php | |||
@@ -8,6 +8,7 @@ use Doctrine\ORM\EntityManager; | |||
8 | use Wallabag\CoreBundle\Helper\ContentProxy; | 8 | use Wallabag\CoreBundle\Helper\ContentProxy; |
9 | use Wallabag\CoreBundle\Entity\Entry; | 9 | use Wallabag\CoreBundle\Entity\Entry; |
10 | use Wallabag\CoreBundle\Entity\Tag; | 10 | use Wallabag\CoreBundle\Entity\Tag; |
11 | use Wallabag\CoreBundle\Helper\TagsAssigner; | ||
11 | use Wallabag\UserBundle\Entity\User; | 12 | use Wallabag\UserBundle\Entity\User; |
12 | use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface; | 13 | use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface; |
13 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; | 14 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
@@ -18,19 +19,22 @@ abstract class AbstractImport implements ImportInterface | |||
18 | protected $em; | 19 | protected $em; |
19 | protected $logger; | 20 | protected $logger; |
20 | protected $contentProxy; | 21 | protected $contentProxy; |
22 | protected $tagsAssigner; | ||
21 | protected $eventDispatcher; | 23 | protected $eventDispatcher; |
22 | protected $producer; | 24 | protected $producer; |
23 | protected $user; | 25 | protected $user; |
24 | protected $markAsRead; | 26 | protected $markAsRead; |
27 | protected $disableContentUpdate = false; | ||
25 | protected $skippedEntries = 0; | 28 | protected $skippedEntries = 0; |
26 | protected $importedEntries = 0; | 29 | protected $importedEntries = 0; |
27 | protected $queuedEntries = 0; | 30 | protected $queuedEntries = 0; |
28 | 31 | ||
29 | public function __construct(EntityManager $em, ContentProxy $contentProxy, EventDispatcherInterface $eventDispatcher) | 32 | public function __construct(EntityManager $em, ContentProxy $contentProxy, TagsAssigner $tagsAssigner, EventDispatcherInterface $eventDispatcher) |
30 | { | 33 | { |
31 | $this->em = $em; | 34 | $this->em = $em; |
32 | $this->logger = new NullLogger(); | 35 | $this->logger = new NullLogger(); |
33 | $this->contentProxy = $contentProxy; | 36 | $this->contentProxy = $contentProxy; |
37 | $this->tagsAssigner = $tagsAssigner; | ||
34 | $this->eventDispatcher = $eventDispatcher; | 38 | $this->eventDispatcher = $eventDispatcher; |
35 | } | 39 | } |
36 | 40 | ||
@@ -82,21 +86,34 @@ abstract class AbstractImport implements ImportInterface | |||
82 | } | 86 | } |
83 | 87 | ||
84 | /** | 88 | /** |
89 | * Set whether articles should be fetched for updated content. | ||
90 | * | ||
91 | * @param bool $disableContentUpdate | ||
92 | */ | ||
93 | public function setDisableContentUpdate($disableContentUpdate) | ||
94 | { | ||
95 | $this->disableContentUpdate = $disableContentUpdate; | ||
96 | |||
97 | return $this; | ||
98 | } | ||
99 | |||
100 | /** | ||
85 | * Fetch content from the ContentProxy (using graby). | 101 | * Fetch content from the ContentProxy (using graby). |
86 | * If it fails return the given entry to be saved in all case (to avoid user to loose the content). | 102 | * If it fails return the given entry to be saved in all case (to avoid user to loose the content). |
87 | * | 103 | * |
88 | * @param Entry $entry Entry to update | 104 | * @param Entry $entry Entry to update |
89 | * @param string $url Url to grab content for | 105 | * @param string $url Url to grab content for |
90 | * @param array $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url | 106 | * @param array $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url |
91 | * | ||
92 | * @return Entry | ||
93 | */ | 107 | */ |
94 | protected function fetchContent(Entry $entry, $url, array $content = []) | 108 | protected function fetchContent(Entry $entry, $url, array $content = []) |
95 | { | 109 | { |
96 | try { | 110 | try { |
97 | return $this->contentProxy->updateEntry($entry, $url, $content); | 111 | $this->contentProxy->updateEntry($entry, $url, $content, $this->disableContentUpdate); |
98 | } catch (\Exception $e) { | 112 | } catch (\Exception $e) { |
99 | return $entry; | 113 | $this->logger->error('Error trying to import an entry.', [ |
114 | 'entry_url' => $url, | ||
115 | 'error_msg' => $e->getMessage(), | ||
116 | ]); | ||
100 | } | 117 | } |
101 | } | 118 | } |
102 | 119 | ||