Skip to content

Commit 9157375

Browse files
committed
feature #21933 [FrameworkBundle][Workflow] Add a way to enable the AuditTrail Logger (lyrixx)
This PR was squashed before being merged into the 3.3-dev branch (closes #21933). Discussion ---------- [FrameworkBundle][Workflow] Add a way to enable the AuditTrail Logger | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - --- This will increase the visibility of the Listener. We could encourage people to use at least `%kernel.debug%` value. --- Note for the merge: There are two commits, this is done on purpose (2 different things, but easier to do only one PR) Commits ------- 633c0393b3 [Workflow] Added the workflow name in log generated by AuditTrailListener b786bccb3a [FrameworkBundle][Workflow] Add a way to enable the AuditTrail Logger
2 parents d09da31 + b79f7df commit 9157375

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

DependencyInjection/Configuration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
247247
->fixXmlConfig('place')
248248
->fixXmlConfig('transition')
249249
->children()
250+
->arrayNode('audit_trail')
251+
->canBeEnabled()
252+
->end()
250253
->enumNode('type')
251254
->values(array('workflow', 'state_machine'))
252255
->defaultValue('workflow')

DependencyInjection/FrameworkExtension.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
3636
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
3737
use Symfony\Component\Workflow;
38-
use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy;
3938
use Symfony\Component\Console\Application;
4039

4140
/**
@@ -481,13 +480,24 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde
481480
// Add workflow to Registry
482481
if ($workflow['supports']) {
483482
foreach ($workflow['supports'] as $supportedClassName) {
484-
$strategyDefinition = new Definition(ClassInstanceSupportStrategy::class, array($supportedClassName));
483+
$strategyDefinition = new Definition(Workflow\SupportStrategy\ClassInstanceSupportStrategy::class, array($supportedClassName));
485484
$strategyDefinition->setPublic(false);
486485
$registryDefinition->addMethodCall('add', array(new Reference($workflowId), $strategyDefinition));
487486
}
488487
} elseif (isset($workflow['support_strategy'])) {
489488
$registryDefinition->addMethodCall('add', array(new Reference($workflowId), new Reference($workflow['support_strategy'])));
490489
}
490+
491+
// Enable the AuditTrail
492+
if ($workflow['audit_trail']['enabled']) {
493+
$listener = new Definition(Workflow\EventListener\AuditTrailListener::class);
494+
$listener->addTag('monolog.logger', array('channel' => 'workflow'));
495+
$listener->addTag('kernel.event_listener', array('event' => sprintf('workflow.%s.leave', $name), 'method' => 'onLeave'));
496+
$listener->addTag('kernel.event_listener', array('event' => sprintf('workflow.%s.transition', $name), 'method' => 'onTransition'));
497+
$listener->addTag('kernel.event_listener', array('event' => sprintf('workflow.%s.enter', $name), 'method' => 'onEnter'));
498+
$listener->addArgument(new Reference('logger'));
499+
$container->setDefinition(sprintf('%s.listener.audit_trail', $workflowId), $listener);
500+
}
491501
}
492502
}
493503

0 commit comments

Comments
 (0)