3 namespace Wallabag\ImportBundle\Import
;
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 use Symfony\Component\Security\Core\User\UserInterface
;
11 use OldSound\RabbitMqBundle\RabbitMq\Producer
;
13 abstract class AbstractImport
implements ImportInterface
17 protected $contentProxy;
20 protected $markAsRead;
22 public function __construct(EntityManager
$em, ContentProxy
$contentProxy)
25 $this->logger
= new NullLogger();
26 $this->contentProxy
= $contentProxy;
29 public function setLogger(LoggerInterface
$logger)
31 $this->logger
= $logger;
35 * Set RabbitMQ Producer to send each entry to a queue.
36 * This method should be called when user has enabled RabbitMQ.
38 * @param Producer $producer
40 public function setRabbitmqProducer(Producer
$producer)
42 $this->producer
= $producer;
47 * Could the current *connected* user or one retrieve by the consumer.
49 * @param UserInterface $user
51 public function setUser(UserInterface
$user)
57 * Set whether articles must be all marked as read.
59 * @param bool $markAsRead
61 public function setMarkAsRead($markAsRead)
63 $this->markAsRead
= $markAsRead;
69 * Get whether articles must be all marked as read.
71 public function getMarkAsRead()
73 return $this->markAsRead
;
77 * Fetch content from the ContentProxy (using graby).
78 * If it fails return false instead of the updated entry.
80 * @param Entry $entry Entry to update
81 * @param string $url Url to grab content for
82 * @param array $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url
86 protected function fetchContent(Entry
$entry, $url, array $content = [])
89 return $this->contentProxy
->updateEntry($entry, $url, $content);
90 } catch (\Exception
$e) {
96 * Parse and insert all given entries.
100 protected function parseEntries($entries)
104 foreach ($entries as $importedEntry) {
105 $entry = $this->parseEntry($importedEntry);
107 if (null === $entry) {
111 // flush every 20 entries
112 if (($i %
20) === 0) {
114 $this->em
->clear($entry);
125 * @param array $importedEntry
129 abstract public function parseEntry(array $importedEntry);