mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
Clean up event processing dependencies
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
|
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Webhook\Processor;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
|
||||
abstract class AbstractProcessor
|
||||
{
|
||||
protected $app;
|
||||
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
}
|
@@ -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(),
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user