|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2017 SURFnet B.V. |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Surfnet\StepupMiddleware\MiddlewareBundle\Console\Command; |
|
20
|
|
|
|
|
21
|
|
|
use Surfnet\StepupMiddleware\MiddlewareBundle\EventSourcing\EventCollection; |
|
22
|
|
|
use Surfnet\StepupMiddleware\MiddlewareBundle\EventSourcing\ProjectorCollection; |
|
23
|
|
|
use Surfnet\StepupMiddleware\MiddlewareBundle\Service\PastEventsService; |
|
|
|
|
|
|
24
|
|
|
use Surfnet\StepupMiddleware\MiddlewareBundle\Service\TransactionAwareEventDispatcher; |
|
|
|
|
|
|
25
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
|
26
|
|
|
use Symfony\Component\Console\Attribute\Option; |
|
27
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
|
28
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
29
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
30
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
|
31
|
|
|
|
|
32
|
|
|
#[AsCommand( |
|
33
|
|
|
name: 'stepup:event:replay', |
|
34
|
|
|
description: 'replay specified events for specified projectors' |
|
35
|
|
|
)] |
|
36
|
|
|
class ReplaySpecificEventsCommand |
|
37
|
|
|
{ |
|
38
|
|
|
public const OPTION_LIST_EVENTS = 'list-events'; |
|
39
|
|
|
public const OPTION_LIST_PROJECTORS = 'list-projectors'; |
|
40
|
|
|
|
|
41
|
|
|
public function __construct( |
|
42
|
|
|
private readonly EventCollection $collection, |
|
43
|
|
|
private readonly ProjectorCollection $projectorCollection, |
|
44
|
|
|
private readonly PastEventsService $pastEventsService, |
|
45
|
|
|
private readonly TransactionAwareEventDispatcher $eventDispatcher |
|
46
|
|
|
) { |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function __invoke( |
|
50
|
|
|
InputInterface $input, |
|
51
|
|
|
OutputInterface $output, |
|
52
|
|
|
#[Option(description: 'List all events available to replay', name: self::OPTION_LIST_EVENTS)] |
|
53
|
|
|
bool $listEvents = false, |
|
54
|
|
|
#[Option(description: 'List all projectors available for which events can be replayed', name: self::OPTION_LIST_PROJECTORS)] |
|
55
|
|
|
bool $listProjectors = false, |
|
56
|
|
|
): int { |
|
57
|
|
|
$availableEvents = $this->collection->getEventNames(); |
|
58
|
|
|
$availableProjectors = $this->projectorCollection->getProjectorNames(); |
|
59
|
|
|
|
|
60
|
|
|
if ($listEvents) { |
|
61
|
|
|
$output->writeln('<info>The following events can be replayed:</info>'); |
|
62
|
|
|
$output->writeln($availableEvents === [] ? 'None.' : $availableEvents); |
|
63
|
|
|
|
|
64
|
|
|
return 0; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if ($listProjectors) { |
|
68
|
|
|
$output->writeln('<info>Events can be replayed for the following projectors:</info>'); |
|
69
|
|
|
$output->writeln($availableProjectors === [] ? 'None.' : $availableProjectors); |
|
70
|
|
|
|
|
71
|
|
|
return 0; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if ($availableProjectors === []) { |
|
75
|
|
|
$output->writeln('<error>There are no projectors configured to replay events for</error>'); |
|
76
|
|
|
|
|
77
|
|
|
return 1; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$questionHelper = new QuestionHelper(); |
|
81
|
|
|
|
|
82
|
|
|
$selectEventsQuestion = new ChoiceQuestion( |
|
83
|
|
|
'Which events would you like to replay? Please supply a comma-separated list of numbers.', |
|
84
|
|
|
$availableEvents, |
|
85
|
|
|
); |
|
86
|
|
|
$selectEventsQuestion->setMultiselect(true); |
|
87
|
|
|
|
|
88
|
|
|
$chosenEvents = $questionHelper->ask($input, $output, $selectEventsQuestion); |
|
89
|
|
|
$eventSelection = $this->collection->select($chosenEvents); |
|
90
|
|
|
|
|
91
|
|
|
$selectProjectorsQuestion = new ChoiceQuestion( |
|
92
|
|
|
'For which projectors would you like to replay the selected events? ' |
|
93
|
|
|
. 'Please supply a comma-separated list of numbers.', |
|
94
|
|
|
$availableProjectors, |
|
95
|
|
|
); |
|
96
|
|
|
$selectProjectorsQuestion->setMultiselect(true); |
|
97
|
|
|
|
|
98
|
|
|
$chosenProjectors = $questionHelper->ask($input, $output, $selectProjectorsQuestion); |
|
99
|
|
|
$projectorSelection = $this->projectorCollection->selectByNames($chosenProjectors); |
|
100
|
|
|
|
|
101
|
|
|
$events = $this->pastEventsService->findEventsBy($eventSelection); |
|
102
|
|
|
|
|
103
|
|
|
$output->writeln('<info>Registering projectors</info>'); |
|
104
|
|
|
foreach ($projectorSelection as $projector) { |
|
105
|
|
|
$this->eventDispatcher->registerProjector($projector); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$output->writeln('<info>Dispatching events</info>'); |
|
109
|
|
|
$this->eventDispatcher->dispatch($events); |
|
110
|
|
|
return 0; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths