Skip to content

Commit

Permalink
Merge pull request #404 from patchlevel/add-rebuild-command
Browse files Browse the repository at this point in the history
add rebuild command & error message in projectionist status command
  • Loading branch information
DavidBadura authored Aug 10, 2023
2 parents f1d8f53 + 8c28e4e commit cca9058
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Console/Command/ProjectionistRebuildCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Patchlevel\EventSourcing\Console\Command;

use Patchlevel\EventSourcing\Console\OutputStyle;
use Patchlevel\EventSourcing\Projection\Projectionist\Listener\ThrowErrorListener;
use Patchlevel\EventSourcing\Projection\Projectionist\Projectionist;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

#[AsCommand(
'event-sourcing:projectionist:rebuild',
'Rebuild projections (remove & boot)',
)]
final class ProjectionistRebuildCommand extends ProjectionistCommand
{
public function __construct(
Projectionist $projectionist,
private readonly EventDispatcherInterface $eventDispatcher,
) {
parent::__construct($projectionist);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new OutputStyle($input, $output);

$criteria = $this->projectionCriteria($input);

if (!$io->confirm('do you want to rebuild all projections?', false)) {
return 1;
}

$this->eventDispatcher->addSubscriber(new ThrowErrorListener());

$this->projectionist->remove($criteria);
$this->projectionist->boot($criteria);

return 0;
}
}
2 changes: 2 additions & 0 deletions src/Console/Command/ProjectionistStatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'version',
'position',
'status',
'error message',
],
array_map(
static fn (Projection $projection) => [
$projection->id()->name(),
$projection->id()->version(),
$projection->position(),
$projection->status()->value,
$projection->errorMessage(),
],
[...$projections],
),
Expand Down

0 comments on commit cca9058

Please sign in to comment.