From 5323396863943a231776c1fd96fd4051912a8d48 Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Mon, 15 Feb 2021 15:48:23 +0100 Subject: [PATCH] add event-subscriber to throw flushed workflow events --- .../Workflow/FlushedEventSubscriber.php | 76 +++++++++++++++++++ DependencyInjection/SuluContentExtension.php | 2 + Resources/config/services.xml | 8 ++ Tests/Application/config/config.yml | 10 --- 4 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 Content/Infrastructure/Symfony/Workflow/FlushedEventSubscriber.php diff --git a/Content/Infrastructure/Symfony/Workflow/FlushedEventSubscriber.php b/Content/Infrastructure/Symfony/Workflow/FlushedEventSubscriber.php new file mode 100644 index 00000000..ad7ee719 --- /dev/null +++ b/Content/Infrastructure/Symfony/Workflow/FlushedEventSubscriber.php @@ -0,0 +1,76 @@ + 'onCompleted', + ]; + } + + /** + * @var EventDispatcherInterface + */ + private $eventDispatcher; + + /** + * @var mixed[] + */ + private $eventsToDispatch = []; + + public function __construct(EventDispatcherInterface $eventDispatcher) + { + $this->eventDispatcher = $eventDispatcher; + } + + public function onCompleted(Event $event): void + { + if ($event->getWorkflowName() !== WorkflowInterface::WORKFLOW_DEFAULT_NAME) { + return; + } + + $eventName = sprintf('workflow.%s.flushed', $event->getWorkflowName()); + + $this->eventsToDispatch[] = [$event, $eventName]; + $this->eventsToDispatch[] = [$event, sprintf('%s.%s', $eventName, $event->getTransition()->getName())]; + } + + public function postFlush(): void + { + foreach ($this->eventsToDispatch as $item) { + $this->eventDispatcher->dispatch($item[0], $item[1]); + } + + $this->eventsToDispatch = []; + } + + public function onClear(): void + { + $this->eventsToDispatch = []; + } +} diff --git a/DependencyInjection/SuluContentExtension.php b/DependencyInjection/SuluContentExtension.php index 91951ee8..822a38a5 100644 --- a/DependencyInjection/SuluContentExtension.php +++ b/DependencyInjection/SuluContentExtension.php @@ -19,6 +19,7 @@ use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\HttpKernel\Bundle\Bundle; class SuluContentExtension extends Extension implements PrependExtensionInterface { @@ -54,6 +55,7 @@ public function load(array $configs, ContainerBuilder $container): void if ($container->hasParameter('kernel.bundles')) { // TODO FIXME add test here // @codeCoverageIgnoreStart + /** @var array $bundles */ $bundles = $container->getParameter('kernel.bundles'); if (\array_key_exists('SuluAutomationBundle', $bundles)) { diff --git a/Resources/config/services.xml b/Resources/config/services.xml index fd41fa84..586880e1 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -166,5 +166,13 @@ + + + + + + + + diff --git a/Tests/Application/config/config.yml b/Tests/Application/config/config.yml index cad22d0f..58deced6 100644 --- a/Tests/Application/config/config.yml +++ b/Tests/Application/config/config.yml @@ -1,16 +1,6 @@ swiftmailer: disable_delivery: true -doctrine: - orm: - mappings: - gedmo_tree: - type: xml - prefix: Gedmo\Tree\Entity - dir: "%kernel.project_dir%/../../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity" - alias: GedmoTree - is_bundle: false - #sulu_core: # content: # structure: