diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index ea9ea67636..63251b9727 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -26,6 +26,7 @@ use Alchemy\Phrasea\Core\Event\Subscriber\LazaretSubscriber; use Alchemy\Phrasea\Core\Event\Subscriber\PhraseaInstallSubscriber; use Alchemy\Phrasea\Core\Event\Subscriber\RegistrationSubscriber; use Alchemy\Phrasea\Core\Event\Subscriber\ValidationSubscriber; +use Alchemy\Phrasea\Core\Event\Subscriber\WebhookUserEventSubscriber; use Alchemy\Phrasea\Core\MetaProvider\DatabaseMetaProvider; use Alchemy\Phrasea\Core\MetaProvider\HttpStackMetaProvider; use Alchemy\Phrasea\Core\MetaProvider\MediaUtilitiesMetaServiceProvider; @@ -717,6 +718,7 @@ class Application extends SilexApplication $dispatcher->addSubscriber(new BasketSubscriber($app)); $dispatcher->addSubscriber(new LazaretSubscriber($app)); $dispatcher->addSubscriber(new ValidationSubscriber($app)); + $dispatcher->addSubscriber(new WebhookUserEventSubscriber($app)); return $dispatcher; }) diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/WebhookUserEventSubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/WebhookUserEventSubscriber.php new file mode 100644 index 0000000000..a2f935bf89 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/WebhookUserEventSubscriber.php @@ -0,0 +1,57 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Alchemy\Phrasea\Core\Event\Subscriber; + +use Alchemy\Phrasea\Application; +use Alchemy\Phrasea\Core\Event\User\DeletedEvent; +use Alchemy\Phrasea\Core\Event\User\UserEvents; +use Alchemy\Phrasea\Model\Entities\WebhookEvent; +use Alchemy\Phrasea\Model\Manipulator\WebhookEventManipulator; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +class WebhookUserEventSubscriber implements EventSubscriberInterface +{ + /** + * @var Application + */ + private $app; + + /** + * @param Application $application + */ + public function __construct(Application $application) + { + $this->app = $application; + } + + /** + * @param DeletedEvent $event + */ + public function onUserDeleted(DeletedEvent $event) + { + /** @var WebhookEventManipulator $manipulator */ + $manipulator = $this->app['manipulator.webhook-event']; + + $manipulator->create(WebhookEvent::USER_DELETED, WebhookEvent::USER_DELETED_TYPE, [ + 'user_id' => $event->getUserId(), + 'email' => $event->getEmailAddress(), + 'login' => $event->getLogin() + ]); + } + + public static function getSubscribedEvents() + { + return [ + UserEvents::DELETED => 'onUserDeleted' + ]; + } +} diff --git a/lib/Alchemy/Phrasea/Webhook/EventProcessorFactory.php b/lib/Alchemy/Phrasea/Webhook/EventProcessorFactory.php index 2665ef27b5..90edefc10c 100644 --- a/lib/Alchemy/Phrasea/Webhook/EventProcessorFactory.php +++ b/lib/Alchemy/Phrasea/Webhook/EventProcessorFactory.php @@ -10,6 +10,7 @@ use Alchemy\Phrasea\Webhook\Processor\FeedEntryProcessorFactory; use Alchemy\Phrasea\Webhook\Processor\OrderNotificationProcessorFactory; use Alchemy\Phrasea\Webhook\Processor\ProcessorFactory; use Alchemy\Phrasea\Webhook\Processor\ProcessorInterface; +use Alchemy\Phrasea\Webhook\Processor\UserDeletedProcessorFactory; use Alchemy\Phrasea\Webhook\Processor\UserRegistrationProcessorFactory; class EventProcessorFactory @@ -28,6 +29,7 @@ class EventProcessorFactory $this->registerFactory(WebhookEvent::FEED_ENTRY_TYPE, new FeedEntryProcessorFactory($app)); $this->registerFactory(WebhookEvent::USER_REGISTRATION_TYPE, new UserRegistrationProcessorFactory($app)); $this->registerFactory(WebhookEvent::ORDER_TYPE, new OrderNotificationProcessorFactory($app)); + $this->registerFactory(WebhookEvent::USER_DELETED_TYPE, new UserDeletedProcessorFactory($app)); } /** diff --git a/lib/Alchemy/Phrasea/Webhook/Processor/UserDeletedProcessor.php b/lib/Alchemy/Phrasea/Webhook/Processor/UserDeletedProcessor.php new file mode 100644 index 0000000000..3b7f998a77 --- /dev/null +++ b/lib/Alchemy/Phrasea/Webhook/Processor/UserDeletedProcessor.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Alchemy\Phrasea\Webhook\Processor; + +use Alchemy\Phrasea\Model\Entities\WebhookEvent; + +class UserDeletedProcessor implements ProcessorInterface +{ + + public function process(WebhookEvent $event) + { + $data = $event->getData(); + + if (! isset($data['user_id'])) { + return null; + } + + return array( + 'event' => $event->getName(), + 'user' => array( + 'id' => $data['user_id'], + 'email' => $data['email'], + 'login' => $data['login'] + ) + ); + } +} diff --git a/lib/Alchemy/Phrasea/Webhook/Processor/UserDeletedProcessorFactory.php b/lib/Alchemy/Phrasea/Webhook/Processor/UserDeletedProcessorFactory.php new file mode 100644 index 0000000000..4dfacf6554 --- /dev/null +++ b/lib/Alchemy/Phrasea/Webhook/Processor/UserDeletedProcessorFactory.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Alchemy\Phrasea\Webhook\Processor; + +class UserDeletedProcessorFactory implements ProcessorFactory +{ + + /** + * @return ProcessorInterface + */ + public function createProcessor() + { + return new UserDeletedProcessor(); + } +}