Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b385ef1

Browse filesBrowse 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 ------- 633c039 [Workflow] Added the workflow name in log generated by AuditTrailListener b786bcc [FrameworkBundle][Workflow] Add a way to enable the AuditTrail Logger
2 parents b77d97a + 633c039 commit b385ef1
Copy full SHA for b385ef1

File tree

Expand file treeCollapse file tree

4 files changed

+21
-8
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+21
-8
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+3Lines 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')

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+12-2Lines 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

‎src/Symfony/Component/Workflow/EventListener/AuditTrailListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/EventListener/AuditTrailListener.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ public function __construct(LoggerInterface $logger)
3030
public function onLeave(Event $event)
3131
{
3232
foreach ($event->getTransition()->getFroms() as $place) {
33-
$this->logger->info(sprintf('Leaving "%s" for subject of class "%s".', $place, get_class($event->getSubject())));
33+
$this->logger->info(sprintf('Leaving "%s" for subject of class "%s" in workflow "%s".', $place, get_class($event->getSubject()), $event->getWorkflowName()));
3434
}
3535
}
3636

3737
public function onTransition(Event $event)
3838
{
39-
$this->logger->info(sprintf('Transition "%s" for subject of class "%s".', $event->getTransition()->getName(), get_class($event->getSubject())));
39+
$this->logger->info(sprintf('Transition "%s" for subject of class "%s" in workflow "%s".', $event->getTransition()->getName(), get_class($event->getSubject()), $event->getWorkflowName()));
4040
}
4141

4242
public function onEnter(Event $event)
4343
{
4444
foreach ($event->getTransition()->getTos() as $place) {
45-
$this->logger->info(sprintf('Entering "%s" for subject of class "%s".', $place, get_class($event->getSubject())));
45+
$this->logger->info(sprintf('Entering "%s" for subject of class "%s" in workflow "%s".', $place, get_class($event->getSubject()), $event->getWorkflowName()));
4646
}
4747
}
4848

‎src/Symfony/Component/Workflow/Tests/EventListener/AuditTrailListenerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Tests/EventListener/AuditTrailListenerTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public function testItWorks()
3333
$workflow->apply($object, 't1');
3434

3535
$expected = array(
36-
'Leaving "a" for subject of class "stdClass".',
37-
'Transition "t1" for subject of class "stdClass".',
38-
'Entering "b" for subject of class "stdClass".',
36+
'Leaving "a" for subject of class "stdClass" in workflow "unnamed".',
37+
'Transition "t1" for subject of class "stdClass" in workflow "unnamed".',
38+
'Entering "b" for subject of class "stdClass" in workflow "unnamed".',
3939
);
4040

4141
$this->assertSame($expected, $logger->logs);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.