|
| 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