X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FImportBundle%2FConsumer%2FAbstractConsumer.php;h=b035f5cc5e83604cf2890dfa035a433a99478b49;hb=f808b01692a835673f328d7221ba8c212caa9b61;hp=b893ea2956bdb2c07b73a7e518519735d9904b84;hpb=1e3d74a9cfdaf708632a97660e1811dd819f7df4;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php b/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php index b893ea29..b035f5cc 100644 --- a/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php +++ b/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php @@ -3,25 +3,29 @@ namespace Wallabag\ImportBundle\Consumer; use Doctrine\ORM\EntityManager; -use Wallabag\ImportBundle\Import\AbstractImport; -use Wallabag\UserBundle\Repository\UserRepository; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\CoreBundle\Entity\Tag; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\CoreBundle\Entity\Tag; +use Wallabag\CoreBundle\Event\EntrySavedEvent; +use Wallabag\ImportBundle\Import\AbstractImport; +use Wallabag\UserBundle\Repository\UserRepository; abstract class AbstractConsumer { protected $em; protected $userRepository; protected $import; + protected $eventDispatcher; protected $logger; - public function __construct(EntityManager $em, UserRepository $userRepository, AbstractImport $import, LoggerInterface $logger = null) + public function __construct(EntityManager $em, UserRepository $userRepository, AbstractImport $import, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger = null) { $this->em = $em; $this->userRepository = $userRepository; $this->import = $import; + $this->eventDispatcher = $eventDispatcher; $this->logger = $logger ?: new NullLogger(); } @@ -42,7 +46,8 @@ abstract class AbstractConsumer if (null === $user) { $this->logger->warning('Unable to retrieve user', ['entry' => $storedEntry]); - return false; + // return true to skip message + return true; } $this->import->setUser($user); @@ -59,6 +64,9 @@ abstract class AbstractConsumer try { $this->em->flush(); + // entry saved, dispatch event about it! + $this->eventDispatcher->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry)); + // clear only affected entities $this->em->clear(Entry::class); $this->em->clear(Tag::class); @@ -68,7 +76,7 @@ abstract class AbstractConsumer return false; } - $this->logger->info('Content with url imported! ('.$entry->getUrl().')'); + $this->logger->info('Content with url imported! (' . $entry->getUrl() . ')'); return true; }