Skip to content

Commit 08c57fb

Browse files
committed
MAGE-848 Implement patch to rebuild replicas after migrating settings
1 parent e277804 commit 08c57fb

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Setup\Patch\Data;
4+
5+
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
6+
use Algolia\AlgoliaSearch\Service\Product\ReplicaManager;
7+
use Magento\Framework\App\State;
8+
use Magento\Framework\Setup\ModuleDataSetupInterface;
9+
use Magento\Framework\Setup\Patch\DataPatchInterface;
10+
use Magento\Framework\Setup\Patch\PatchInterface;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
13+
class RebuildReplicasPatch implements DataPatchInterface
14+
{
15+
public function __construct(
16+
protected ModuleDataSetupInterface $moduleDataSetup,
17+
protected StoreManagerInterface $storeManager,
18+
protected ReplicaManager $replicaManager,
19+
protected ProductHelper $productHelper,
20+
protected State $state
21+
)
22+
{}
23+
24+
/**
25+
* @inheritDoc
26+
*/
27+
public static function getDependencies(): array
28+
{
29+
return [
30+
MigrateVirtualReplicaConfigPatch::class
31+
];
32+
}
33+
34+
/**
35+
* @inheritDoc
36+
*/
37+
public function getAliases(): array
38+
{
39+
return [];
40+
}
41+
42+
/**
43+
* @inheritDoc
44+
*/
45+
public function apply(): PatchInterface
46+
{
47+
$this->moduleDataSetup->getConnection()->startSetup();
48+
$this->state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
49+
50+
$storeIds = array_keys($this->storeManager->getStores());
51+
foreach ($storeIds as $storeId) {
52+
$this->replicaManager->deleteReplicasFromAlgolia($storeId);
53+
$this->replicaManager->syncReplicasToAlgolia($storeId, $this->productHelper->getIndexSettings($storeId));
54+
}
55+
56+
$this->moduleDataSetup->getConnection()->endSetup();
57+
58+
return $this;
59+
}
60+
}

0 commit comments

Comments
 (0)