-
Notifications
You must be signed in to change notification settings - Fork 3
/
RefreshElementInIndexHandler.php
41 lines (33 loc) · 1.34 KB
/
RefreshElementInIndexHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
namespace Valantic\ElasticaBridgeBundle\Messenger\Handler;
use Pimcore\Model\Element\AbstractElement;
use Valantic\ElasticaBridgeBundle\Messenger\Message\RefreshElementInIndex;
use Valantic\ElasticaBridgeBundle\Repository\IndexRepository;
use Valantic\ElasticaBridgeBundle\Service\LockService;
use Valantic\ElasticaBridgeBundle\Service\PropagateChanges;
/**
* @template TModel of AbstractElement
*
* @extends AbstractRefreshHandler<TModel>
*/
class RefreshElementInIndexHandler extends AbstractRefreshHandler
{
public function __construct(
private readonly PropagateChanges $propagateChanges,
private readonly LockService $lockService,
private readonly IndexRepository $indexRepository,
) {}
public function __invoke(RefreshElementInIndex $message): void
{
$index = $this->indexRepository->flattenedGet($message->index);
$element = $this->resolveElement($message);
if ($message->isEventPropagationStopped()) {
PropagateChanges::stopPropagation();
}
if ($index->usesBlueGreenIndices() && !$this->lockService->getIndexingLock($index)->acquire()) {
$this->propagateChanges->handleIndex($element, $index, $index->getBlueGreenInactiveElasticaIndex());
}
$this->propagateChanges->handleIndex($element, $index);
}
}