-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeliveryService.php
104 lines (92 loc) · 2.63 KB
/
DeliveryService.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/**
* @author Artemii Karkusha
* @copyright Copyright (c) (https://www.linkedin.com/in/artemiy-karkusha/)
*/
declare(strict_types=1);
namespace ArtemiiKarkusha\AdobeCommercePreparingToCertification\Model\Indexer;
use ArtemiiKarkusha\AdobeCommercePreparingToCertification\Model\DeliveryServiceModel;
use ArtemiiKarkusha\AdobeCommercePreparingToCertification\Model\Indexer\DeliveryService\Action\Full
as PerformerOfFullIndexing;
use ArtemiiKarkusha\AdobeCommercePreparingToCertification\Model\Indexer\DeliveryService\Action\Rows
as PerformerOfIndexing;
use Magento\Framework\Indexer\ActionInterface as IndexerActionInterface;
use Magento\Framework\Indexer\CacheContext;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\Framework\Mview\ActionInterface as MviewActionInterface;
/**
* Delivery service indexer
*/
class DeliveryService implements IndexerActionInterface, MviewActionInterface
{
/**
* Indexer ID in configuration
*/
public const INDEXER_ID = 'delivery_service';
/**
* @param IndexerRegistry $indexerRegistry
* @param CacheContext $cacheContext
* @param PerformerOfIndexing $performerOfIndexing
* @param PerformerOfFullIndexing $performerOfFullIndexing
*/
public function __construct(
private IndexerRegistry $indexerRegistry,
private CacheContext $cacheContext,
private PerformerOfIndexing $performerOfIndexing,
private PerformerOfFullIndexing $performerOfFullIndexing
) {
}
/**
* @inheritDoc
*/
public function execute($ids): void
{
$this->registerEntities($ids);
if ($this->canNotBeIndexed()) {
return;
}
$this->performerOfIndexing->reindex($ids);
}
/**
* @inheritDoc
*/
public function executeRow($id): void
{
$this->execute([$id]);
}
/**
* @inheritDoc
*/
public function executeList(array $ids): void
{
$this->execute($ids);
}
/**
* @inheritDoc
*/
public function executeFull(): void
{
$this->performerOfFullIndexing->execute();
}
/**
* Add entities to cache context
*
* @param int[] $ids
* @return void
* @since 100.0.11
*/
private function registerEntities(array $ids): void
{
$this->cacheContext->registerEntities(DeliveryServiceModel::CACHE_TAG, $ids);
}
/**
* Checks indexer ready
*
* @return bool
*/
private function canNotBeIndexed(): bool
{
$indexer = $this->indexerRegistry->get(self::INDEXER_ID);
return !$indexer->isScheduled() || !$indexer->isWorking();
}
}