]>
Commit | Line | Data |
---|---|---|
56c778b4 NL |
1 | <?php |
2 | ||
3 | namespace Wallabag\ImportBundle\Component\AMPQ; | |
4 | ||
5 | use Doctrine\ORM\EntityManager; | |
6 | use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface; | |
7 | use PhpAmqpLib\Message\AMQPMessage; | |
8 | use Wallabag\CoreBundle\Helper\ContentProxy; | |
9 | use Wallabag\CoreBundle\Repository\EntryRepository; | |
10 | ||
11 | class EntryConsumer implements ConsumerInterface | |
12 | { | |
13 | private $em; | |
14 | private $contentProxy; | |
15 | private $entryRepository; | |
16 | ||
17 | public function __construct(EntityManager $em, EntryRepository $entryRepository, ContentProxy $contentProxy) | |
18 | { | |
19 | $this->em = $em; | |
20 | $this->entryRepository = $entryRepository; | |
21 | $this->contentProxy = $contentProxy; | |
22 | } | |
23 | ||
24 | /** | |
25 | * {@inheritdoc} | |
26 | */ | |
27 | public function execute(AMQPMessage $msg) | |
28 | { | |
29 | $storedEntry = unserialize($msg->body); | |
30 | $entry = $this->entryRepository->findByUrlAndUserId($storedEntry['url'], $storedEntry['userId']); | |
31 | if ($entry) { | |
32 | $entry = $this->contentProxy->updateEntry($entry, $entry->getUrl()); | |
33 | if ($entry) { | |
34 | $this->em->persist($entry); | |
35 | $this->em->flush(); | |
36 | } | |
37 | } | |
38 | } | |
39 | } |