Skip to content

Commit

Permalink
Quickfix for bootstrap command to fix cache:clear
Browse files Browse the repository at this point in the history
  • Loading branch information
DRvanR committed Mar 18, 2015
1 parent 742ec03 commit 331c7c8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
namespace Surfnet\StepupMiddleware\CommandHandlingBundle\EventListener;

use Surfnet\StepupMiddleware\CommandHandlingBundle\EventHandling\BufferedEventBus;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
Expand All @@ -45,16 +43,10 @@ public function onKernelTerminate(PostResponseEvent $event)
$this->eventBus->flush();
}

public function onConsoleTerminate(ConsoleTerminateEvent $event)
{
$this->eventBus->flush();
}

public static function getSubscribedEvents()
{
return [
KernelEvents::TERMINATE => ['onKernelTerminate', 100],
ConsoleEvents::TERMINATE => ['onConsoleTerminate', 100]
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

namespace Surfnet\StepupMiddleware\MiddlewareBundle\Console\Command;

use Doctrine\DBAL\Connection;
use Exception;
use Rhumsaa\Uuid\Uuid;
use Surfnet\StepupMiddleware\CommandHandlingBundle\EventHandling\BufferedEventBus;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\BootstrapIdentityWithYubikeySecondFactorCommand
as BootstrapIdentityWithYubikeySecondFactorIdentityCommand;
use Surfnet\StepupMiddleware\CommandHandlingBundle\Pipeline\Pipeline;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -35,11 +37,23 @@ final class BootstrapIdentityWithYubikeySecondFactorCommand extends Command
*/
private $pipeline;

public function __construct(Pipeline $pipeline)
/**
* @var BufferedEventBus
*/
private $eventBus;

/**
* @var Connection
*/
private $middlewareConnection;

public function __construct(Pipeline $pipeline, BufferedEventBus $eventBus, Connection $middlewareConnection)
{
parent::__construct(null);

$this->pipeline = $pipeline;
$this->eventBus = $eventBus;
$this->middlewareConnection = $middlewareConnection;
}


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

$command = $this->pipeline->process($command);
$this->middlewareConnection->beginTransaction();

try {
$command = $this->pipeline->process($command);
$this->eventBus->flush();

$this->middlewareConnection->commit();
} catch (Exception $e) {
$output->writeln(sprintf(
'<error>An Error occurred when trying to bootstrap the identity: "%s"</error>',
$e->getMessage()
));

$this->middlewareConnection->rollBack();
throw $e;
}

$output->writeln(
sprintf(
'Successfully created identity with UUID %s and second factor with UUID %s',
'<info>Successfully created identity with UUID %s and second factor with UUID %s</info>',
$command->identityId,
$command->secondFactorId
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ services:
class: Surfnet\StepupMiddleware\MiddlewareBundle\Console\Command\BootstrapIdentityWithYubikeySecondFactorCommand
arguments:
- @pipeline
- @surfnet_stepup_middleware_command_handling.event_bus.buffered
tags:
- { name: console.command }

0 comments on commit 331c7c8

Please sign in to comment.