|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace CultuurNet\UDB3\Event; |
|
6
|
|
|
|
|
7
|
|
|
use Broadway\CommandHandling\CommandBusInterface; |
|
8
|
|
|
use Broadway\Domain\DomainMessage; |
|
9
|
|
|
use Broadway\EventHandling\EventListenerInterface; |
|
10
|
|
|
use CultuurNet\UDB3\Event\Commands\UpdateLocation; |
|
11
|
|
|
use CultuurNet\UDB3\Event\ReadModel\Relations\RepositoryInterface; |
|
12
|
|
|
use CultuurNet\UDB3\Event\ValueObjects\LocationId; |
|
13
|
|
|
use CultuurNet\UDB3\Place\Events\MarkedAsDuplicate; |
|
14
|
|
|
|
|
15
|
|
|
final class LocationMarkedAsDuplicateProcessManager implements EventListenerInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var RepositoryInterface |
|
19
|
|
|
*/ |
|
20
|
|
|
private $relationsRepository; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var CommandBusInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
private $commandBus; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct( |
|
28
|
|
|
RepositoryInterface $relationsRepository, |
|
29
|
|
|
CommandBusInterface $commandBus |
|
30
|
|
|
) { |
|
31
|
|
|
$this->relationsRepository = $relationsRepository; |
|
32
|
|
|
$this->commandBus = $commandBus; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function handle(DomainMessage $domainMessage) |
|
36
|
|
|
{ |
|
37
|
|
|
$domainEvent = $domainMessage->getPayload(); |
|
38
|
|
|
|
|
39
|
|
|
// Only handle (Place)MarkedAsDuplicate events. |
|
40
|
|
|
if (!($domainEvent instanceof MarkedAsDuplicate)) { |
|
41
|
|
|
return; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$duplicatePlaceId = $domainEvent->getPlaceId(); |
|
45
|
|
|
$canonicalPlaceId = $domainEvent->getDuplicateOf(); |
|
46
|
|
|
|
|
47
|
|
|
$eventIds = $this->relationsRepository->getEventsLocatedAtPlace($duplicatePlaceId); |
|
48
|
|
|
|
|
49
|
|
|
foreach ($eventIds as $eventId) { |
|
50
|
|
|
$this->commandBus->dispatch( |
|
51
|
|
|
new UpdateLocation($eventId, new LocationId($canonicalPlaceId)) |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|