Skip to content

Commit 331c7c8

Browse files
author
DRvanR
committed
Quickfix for bootstrap command to fix cache:clear
1 parent 742ec03 commit 331c7c8

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/Surfnet/StepupMiddleware/CommandHandlingBundle/EventListener/FlushEventBufferEventListener.php

-8
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
namespace Surfnet\StepupMiddleware\CommandHandlingBundle\EventListener;
2020

2121
use Surfnet\StepupMiddleware\CommandHandlingBundle\EventHandling\BufferedEventBus;
22-
use Symfony\Component\Console\ConsoleEvents;
23-
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
2422
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2523
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
2624
use Symfony\Component\HttpKernel\KernelEvents;
@@ -45,16 +43,10 @@ public function onKernelTerminate(PostResponseEvent $event)
4543
$this->eventBus->flush();
4644
}
4745

48-
public function onConsoleTerminate(ConsoleTerminateEvent $event)
49-
{
50-
$this->eventBus->flush();
51-
}
52-
5346
public static function getSubscribedEvents()
5447
{
5548
return [
5649
KernelEvents::TERMINATE => ['onKernelTerminate', 100],
57-
ConsoleEvents::TERMINATE => ['onConsoleTerminate', 100]
5850
];
5951
}
6052
}

src/Surfnet/StepupMiddleware/MiddlewareBundle/Console/Command/BootstrapIdentityWithYubikeySecondFactorCommand.php

+33-4
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
namespace Surfnet\StepupMiddleware\MiddlewareBundle\Console\Command;
2020

21+
use Doctrine\DBAL\Connection;
22+
use Exception;
2123
use Rhumsaa\Uuid\Uuid;
24+
use Surfnet\StepupMiddleware\CommandHandlingBundle\EventHandling\BufferedEventBus;
2225
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\BootstrapIdentityWithYubikeySecondFactorCommand
2326
as BootstrapIdentityWithYubikeySecondFactorIdentityCommand;
2427
use Surfnet\StepupMiddleware\CommandHandlingBundle\Pipeline\Pipeline;
2528
use Symfony\Component\Console\Command\Command;
26-
use Symfony\Component\Console\Input\InputArgument;
2729
use Symfony\Component\Console\Input\InputInterface;
2830
use Symfony\Component\Console\Input\InputOption;
2931
use Symfony\Component\Console\Output\OutputInterface;
@@ -35,11 +37,23 @@ final class BootstrapIdentityWithYubikeySecondFactorCommand extends Command
3537
*/
3638
private $pipeline;
3739

38-
public function __construct(Pipeline $pipeline)
40+
/**
41+
* @var BufferedEventBus
42+
*/
43+
private $eventBus;
44+
45+
/**
46+
* @var Connection
47+
*/
48+
private $middlewareConnection;
49+
50+
public function __construct(Pipeline $pipeline, BufferedEventBus $eventBus, Connection $middlewareConnection)
3951
{
4052
parent::__construct(null);
4153

4254
$this->pipeline = $pipeline;
55+
$this->eventBus = $eventBus;
56+
$this->middlewareConnection = $middlewareConnection;
4357
}
4458

4559

@@ -71,11 +85,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
7185
$command->secondFactorId = (string) Uuid::uuid4();
7286
$command->yubikeyPublicId = $input->getOption('yubikey');
7387

74-
$command = $this->pipeline->process($command);
88+
$this->middlewareConnection->beginTransaction();
89+
90+
try {
91+
$command = $this->pipeline->process($command);
92+
$this->eventBus->flush();
93+
94+
$this->middlewareConnection->commit();
95+
} catch (Exception $e) {
96+
$output->writeln(sprintf(
97+
'<error>An Error occurred when trying to bootstrap the identity: "%s"</error>',
98+
$e->getMessage()
99+
));
100+
101+
$this->middlewareConnection->rollBack();
102+
throw $e;
103+
}
75104

76105
$output->writeln(
77106
sprintf(
78-
'Successfully created identity with UUID %s and second factor with UUID %s',
107+
'<info>Successfully created identity with UUID %s and second factor with UUID %s</info>',
79108
$command->identityId,
80109
$command->secondFactorId
81110
)

src/Surfnet/StepupMiddleware/MiddlewareBundle/Resources/config/services.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ services:
33
class: Surfnet\StepupMiddleware\MiddlewareBundle\Console\Command\BootstrapIdentityWithYubikeySecondFactorCommand
44
arguments:
55
- @pipeline
6+
- @surfnet_stepup_middleware_command_handling.event_bus.buffered
67
tags:
78
- { name: console.command }

0 commit comments

Comments
 (0)