From a915a40a99f1b09473767db20a1b183ea69ba39a Mon Sep 17 00:00:00 2001 From: Thibaud Fabre Date: Mon, 26 Oct 2015 13:59:23 +0100 Subject: [PATCH] Clean up event processing dependencies --- .../Phrasea/Webhook/EventProcessorFactory.php | 8 +++-- .../Webhook/Processor/AbstractProcessor.php | 15 -------- .../Webhook/Processor/FeedEntryProcessor.php | 35 +++++++++++++++---- .../Processor/UserRegistrationProcessor.php | 6 ++-- .../Processor/FeedEntryProcessorTest.php | 18 ++++++++-- 5 files changed, 52 insertions(+), 30 deletions(-) delete mode 100644 lib/Alchemy/Phrasea/Webhook/Processor/AbstractProcessor.php diff --git a/lib/Alchemy/Phrasea/Webhook/EventProcessorFactory.php b/lib/Alchemy/Phrasea/Webhook/EventProcessorFactory.php index fe2f960737..cbb3de6c44 100644 --- a/lib/Alchemy/Phrasea/Webhook/EventProcessorFactory.php +++ b/lib/Alchemy/Phrasea/Webhook/EventProcessorFactory.php @@ -20,9 +20,13 @@ class EventProcessorFactory { switch ($event->getType()) { case WebhookEvent::FEED_ENTRY_TYPE: - return new FeedEntryProcessor($this->app); + return new FeedEntryProcessor( + $this->app, + $this->app['repo.feed-entries'], + $this->app['phraseanet.user-query'] + ); case WebhookEvent::USER_REGISTRATION_TYPE: - return new UserRegistrationProcessor($this->app, $this->app['repo.users']); + return new UserRegistrationProcessor($this->app['repo.users']); default: throw new \RuntimeException(sprintf('No processor found for %s', $event->getType())); } diff --git a/lib/Alchemy/Phrasea/Webhook/Processor/AbstractProcessor.php b/lib/Alchemy/Phrasea/Webhook/Processor/AbstractProcessor.php deleted file mode 100644 index af2ba14635..0000000000 --- a/lib/Alchemy/Phrasea/Webhook/Processor/AbstractProcessor.php +++ /dev/null @@ -1,15 +0,0 @@ -app = $app; - } -} diff --git a/lib/Alchemy/Phrasea/Webhook/Processor/FeedEntryProcessor.php b/lib/Alchemy/Phrasea/Webhook/Processor/FeedEntryProcessor.php index 6a9e4f527f..7fd4500c49 100644 --- a/lib/Alchemy/Phrasea/Webhook/Processor/FeedEntryProcessor.php +++ b/lib/Alchemy/Phrasea/Webhook/Processor/FeedEntryProcessor.php @@ -2,10 +2,34 @@ namespace Alchemy\Phrasea\Webhook\Processor; +use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Model\Entities\WebhookEvent; +use Alchemy\Phrasea\Model\Repositories\FeedEntryRepository; -class FeedEntryProcessor extends AbstractProcessor implements ProcessorInterface +class FeedEntryProcessor implements ProcessorInterface { + /** + * @var Application + */ + private $application; + + /** + * @var FeedEntryRepository + */ + private $entryRepository; + + /** + * @var \User_Query + */ + private $userQuery; + + public function __construct(Application $application, FeedEntryRepository $entryRepository, \User_Query $userQuery) + { + $this->application = $application; + $this->entryRepository = $entryRepository; + $this->userQuery = $userQuery; + } + public function process(WebhookEvent $event) { $data = $event->getData(); @@ -14,17 +38,16 @@ class FeedEntryProcessor extends AbstractProcessor implements ProcessorInterface return null; } - $entry = $this->app['orm.em']->getRepository('Phraseanet::Entry')->find($data->entry_id); + $entry = $this->entryRepository->find($data->entry_id); if (null === $entry) { return null; } - $data = $this->event->getData(); - + $data = $event->getData(); $feed = $entry->getFeed(); - $query = $this->app['phraseanet.user-query']; + $query = $this->userQuery; $query->include_phantoms(true) ->include_invite(false) @@ -52,7 +75,7 @@ class FeedEntryProcessor extends AbstractProcessor implements ProcessorInterface } while (count($results) > 0); return [ - 'event' => $this->event->getName(), + 'event' => $event->getName(), 'users_were_notified' => isset($data->notify_email) ?: (bool) $data->notify_email, 'feed' => [ 'id' => $feed->getId(), diff --git a/lib/Alchemy/Phrasea/Webhook/Processor/UserRegistrationProcessor.php b/lib/Alchemy/Phrasea/Webhook/Processor/UserRegistrationProcessor.php index bd146a17fe..9a67c34c42 100644 --- a/lib/Alchemy/Phrasea/Webhook/Processor/UserRegistrationProcessor.php +++ b/lib/Alchemy/Phrasea/Webhook/Processor/UserRegistrationProcessor.php @@ -6,17 +6,15 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Model\Entities\WebhookEvent; use Alchemy\Phrasea\Model\Repositories\UserRepository; -class UserRegistrationProcessor extends AbstractProcessor implements ProcessorInterface +class UserRegistrationProcessor implements ProcessorInterface { /** * @var UserRepository */ private $userRepository; - public function __construct(Application $application, UserRepository $userRepository) + public function __construct(UserRepository $userRepository) { - parent::__construct($application); - $this->userRepository = $userRepository; } diff --git a/tests/Alchemy/Tests/Phrasea/Webhook/Processor/FeedEntryProcessorTest.php b/tests/Alchemy/Tests/Phrasea/Webhook/Processor/FeedEntryProcessorTest.php index 445f787775..60b518e443 100644 --- a/tests/Alchemy/Tests/Phrasea/Webhook/Processor/FeedEntryProcessorTest.php +++ b/tests/Alchemy/Tests/Phrasea/Webhook/Processor/FeedEntryProcessorTest.php @@ -21,7 +21,11 @@ class FeedEntryProcessorTest extends \PhraseanetTestCase ]); $event->setName(WebhookEvent::NEW_FEED_ENTRY); $event->setType(WebhookEvent::FEED_ENTRY_TYPE); - $processor = new FeedEntryProcessor(self::$DI['app']); + $processor = new FeedEntryProcessor( + self::$DI['app'], + self::$DI['app']['repo.feed-entries'], + self::$DI['app']['phraseanet.user-query'] + ); $this->assertEquals($processor->process($event), null); } @@ -33,7 +37,11 @@ class FeedEntryProcessorTest extends \PhraseanetTestCase ]); $event->setName(WebhookEvent::NEW_FEED_ENTRY); $event->setType(WebhookEvent::FEED_ENTRY_TYPE); - $processor = new FeedEntryProcessor(self::$DI['app']); + $processor = new FeedEntryProcessor( + self::$DI['app'], + self::$DI['app']['repo.feed-entries'], + self::$DI['app']['phraseanet.user-query'] + ); $this->assertEquals($processor->process($event), null); } @@ -46,7 +54,11 @@ class FeedEntryProcessorTest extends \PhraseanetTestCase ]); $event->setName(WebhookEvent::NEW_FEED_ENTRY); $event->setType(WebhookEvent::FEED_ENTRY_TYPE); - $processor = new FeedEntryProcessor(self::$DI['app']); + $processor = new FeedEntryProcessor( + self::$DI['app'], + self::$DI['app']['repo.feed-entries'], + self::$DI['app']['phraseanet.user-query'] + ); $this->assertEquals($processor->process($event), null); } }