mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 09:53:15 +00:00
incorporate subdefWebhook into phraseanet
This commit is contained in:
@@ -88,6 +88,7 @@ use Alchemy\Phrasea\Media\PermalinkMediaResolver;
|
||||
use Alchemy\Phrasea\Media\TechnicalDataServiceProvider;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Alchemy\QueueProvider\QueueServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Event\Subscriber\WebhookSubdefEventSubscriber;
|
||||
use Alchemy\WorkerProvider\WorkerServiceProvider;
|
||||
use Doctrine\DBAL\Event\ConnectionEventArgs;
|
||||
use MediaVorus\Media\MediaInterface;
|
||||
@@ -742,6 +743,7 @@ class Application extends SilexApplication
|
||||
$dispatcher->addSubscriber(new LazaretSubscriber($app));
|
||||
$dispatcher->addSubscriber(new ValidationSubscriber($app));
|
||||
$dispatcher->addSubscriber(new WebhookUserEventSubscriber($app));
|
||||
$dispatcher->addSubscriber(new WebhookSubdefEventSubscriber($app['manipulator.webhook-event']));
|
||||
|
||||
return $dispatcher;
|
||||
})
|
||||
|
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Event\Subscriber;
|
||||
|
||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
||||
use Alchemy\Phrasea\Core\Event\Record\SubDefinitionCreatedEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\SubDefinitionCreationFailedEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\SubDefinitionsCreatedEvent;
|
||||
use Alchemy\Phrasea\Model\Entities\WebhookEvent;
|
||||
use Alchemy\Phrasea\Model\Manipulator\WebhookEventManipulator;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
class WebhookSubdefEventSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @var WebhookEventManipulator
|
||||
*/
|
||||
private $webhookManipulator;
|
||||
|
||||
public function __construct(WebhookEventManipulator $manipulator)
|
||||
{
|
||||
$this->webhookManipulator = $manipulator;
|
||||
}
|
||||
|
||||
public function onSubdefCreated(SubDefinitionCreatedEvent $event)
|
||||
{
|
||||
$eventData = [
|
||||
'databox_id' => $event->getRecord()->getDataboxId(),
|
||||
'record_id' => $event->getRecord()->getRecordId(),
|
||||
'subdef' => $event->getSubDefinitionName()
|
||||
];
|
||||
|
||||
$this->webhookManipulator->create(
|
||||
WebhookEvent::RECORD_SUBDEF_CREATED,
|
||||
WebhookEvent::RECORD_SUBDEF_TYPE,
|
||||
$eventData
|
||||
);
|
||||
}
|
||||
|
||||
public function onSubdefCreationFailed(SubDefinitionCreationFailedEvent $event)
|
||||
{
|
||||
$eventData = [
|
||||
'databox_id' => $event->getRecord()->getDataboxId(),
|
||||
'record_id' => $event->getRecord()->getRecordId(),
|
||||
'subdef' => $event->getSubDefinitionName()
|
||||
];
|
||||
|
||||
$this->webhookManipulator->create(
|
||||
WebhookEvent::RECORD_SUBDEF_FAILED,
|
||||
WebhookEvent::RECORD_SUBDEF_TYPE,
|
||||
$eventData
|
||||
);
|
||||
}
|
||||
|
||||
public function onSubdefsCreated(SubDefinitionsCreatedEvent $event)
|
||||
{
|
||||
$eventData = [
|
||||
'databox_id' => $event->getRecord()->getDataboxId(),
|
||||
'record_id' => $event->getRecord()->getRecordId(),
|
||||
'subdef_count' => count($event->getMedia())
|
||||
];
|
||||
|
||||
$this->webhookManipulator->create(
|
||||
WebhookEvent::RECORD_SUBDEFS_CREATED,
|
||||
WebhookEvent::RECORD_SUBDEF_TYPE,
|
||||
$eventData
|
||||
);
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
RecordEvents::SUB_DEFINITION_CREATED => 'onSubdefCreated',
|
||||
RecordEvents::SUB_DEFINITIONS_CREATED => 'onSubdefsCreated',
|
||||
RecordEvents::SUB_DEFINITION_CREATION_FAILED => 'onSubdefCreationFailed'
|
||||
];
|
||||
}
|
||||
}
|
@@ -12,6 +12,7 @@ use Alchemy\Phrasea\Webhook\Processor\ProcessorFactory;
|
||||
use Alchemy\Phrasea\Webhook\Processor\ProcessorInterface;
|
||||
use Alchemy\Phrasea\Webhook\Processor\UserDeletedProcessorFactory;
|
||||
use Alchemy\Phrasea\Webhook\Processor\UserRegistrationProcessorFactory;
|
||||
use Alchemy\Phrasea\Webhook\Processor\SubdefEventProcessor;
|
||||
|
||||
class EventProcessorFactory
|
||||
{
|
||||
@@ -29,7 +30,10 @@ 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));
|
||||
$this->registerFactory(WebhookEvent::USER_DELETED_TYPE, new UserDeletedProcessorFactory());
|
||||
$this->registerCallableFactory(WebhookEvent::RECORD_SUBDEF_TYPE, function () {
|
||||
return new SubdefEventProcessor();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +47,7 @@ class EventProcessorFactory
|
||||
|
||||
/**
|
||||
* @param string $eventType
|
||||
* @param callback|callable $callable
|
||||
* @param callback|callable|\Closure $callable
|
||||
*/
|
||||
public function registerCallableFactory($eventType, $callable)
|
||||
{
|
||||
|
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Webhook\Processor;
|
||||
|
||||
use Alchemy\Phrasea\Model\Entities\WebhookEvent;
|
||||
|
||||
class SubdefEventProcessor implements ProcessorInterface
|
||||
{
|
||||
|
||||
public function process(WebhookEvent $event)
|
||||
{
|
||||
return [
|
||||
'event' => $event->getName(),
|
||||
'data' => $event->getData()
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user