X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FImportBundle%2FImport%2FAbstractImport.php;h=b085dc3a65729ce107c9d3f66ea9afaf12d72fc6;hb=3849a9f3231c0109c87af085452c3ac5e4aed303;hp=5b9d65d7255d8eac6a3599c138b02c8161131735;hpb=c98db1b653b5dc8b701422190b02d9fbf10c4e68;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php index 5b9d65d7..b085dc3a 100644 --- a/src/Wallabag/ImportBundle/Import/AbstractImport.php +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php @@ -7,7 +7,7 @@ use Psr\Log\NullLogger; use Doctrine\ORM\EntityManager; use Wallabag\CoreBundle\Helper\ContentProxy; use Wallabag\CoreBundle\Entity\Entry; -use Symfony\Component\Security\Core\User\UserInterface; +use Wallabag\UserBundle\Entity\User; use OldSound\RabbitMqBundle\RabbitMq\Producer; abstract class AbstractImport implements ImportInterface @@ -46,9 +46,9 @@ abstract class AbstractImport implements ImportInterface * Set current user. * Could the current *connected* user or one retrieve by the consumer. * - * @param UserInterface $user + * @param User $user */ - public function setUser(UserInterface $user) + public function setUser(User $user) { $this->user = $user; } @@ -119,6 +119,32 @@ abstract class AbstractImport implements ImportInterface $this->em->flush(); } + /** + * Parse entries and send them to the queue. + * It should just be a simple loop on all item, no call to the database should be done + * to speedup queuing. + * + * Faster parse entries for Producer. + * We don't care to make check at this time. They'll be done by the consumer. + * + * @param array $entries + */ + protected function parseEntriesForProducer(array $entries) + { + foreach ($entries as $importedEntry) { + // set userId for the producer (it won't know which user is connected) + $importedEntry['userId'] = $this->user->getId(); + + if ($this->markAsRead) { + $importedEntry = $this->setEntryAsRead($importedEntry); + } + + ++$this->importedEntries; + + $this->producer->publish(json_encode($importedEntry)); + } + } + /** * Parse one entry. * @@ -127,4 +153,14 @@ abstract class AbstractImport implements ImportInterface * @return Entry */ abstract public function parseEntry(array $importedEntry); + + /** + * Set current imported entry to archived / read. + * Implementation is different accross all imports. + * + * @param array $importedEntry + * + * @return array + */ + abstract protected function setEntryAsRead(array $importedEntry); }