/
ProductReindexManager.php
66 lines (58 loc) · 1.79 KB
/
ProductReindexManager.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
<?php
namespace Oro\Bundle\ProductBundle\Search\Reindex;
use Oro\Bundle\ProductBundle\Entity\Product;
use Oro\Bundle\WebsiteSearchBundle\Event\ReindexationRequestEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Helps to reindex of products in search engine.
*/
class ProductReindexManager
{
private EventDispatcherInterface $dispatcher;
public function __construct(EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
}
public function reindexProduct(
Product $product,
int $websiteId = null,
bool $isScheduled = true,
array $fieldGroups = null
): void {
$this->reindexProducts([$product->getId()], $websiteId, $isScheduled, $fieldGroups);
}
public function reindexProducts(
array $productIds,
int $websiteId = null,
bool $isScheduled = true,
array $fieldGroups = null
): void {
if ($productIds) {
$this->doReindexProducts($productIds, $websiteId, $isScheduled, $fieldGroups);
}
}
public function reindexAllProducts(
int $websiteId = null,
bool $isScheduled = true,
array $fieldGroups = null
): void {
$this->doReindexProducts([], $websiteId, $isScheduled, $fieldGroups);
}
private function doReindexProducts(
array $productIds,
?int $websiteId,
bool $isScheduled,
array $fieldGroups = null
): void {
$this->dispatcher->dispatch(
new ReindexationRequestEvent(
[Product::class],
null !== $websiteId ? [$websiteId] : [],
$productIds,
$isScheduled,
$fieldGroups
),
ReindexationRequestEvent::EVENT_NAME
);
}
}