Skip to content

Commit 5127d84

Browse files
committed
MAGE-962 Add error handling if area code is already set in rebuild replicas patch
1 parent 33d5e74 commit 5127d84

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Setup/Patch/Data/RebuildReplicasPatch.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use Algolia\AlgoliaSearch\Helper\Entity\ProductHelper;
66
use Algolia\AlgoliaSearch\Registry\ReplicaState;
77
use Algolia\AlgoliaSearch\Service\Product\ReplicaManager;
8+
use Magento\Framework\App\Area;
89
use Magento\Framework\App\State as AppState;
10+
use Magento\Framework\Exception\LocalizedException;
911
use Magento\Framework\Setup\ModuleDataSetupInterface;
1012
use Magento\Framework\Setup\Patch\DataPatchInterface;
1113
use Magento\Framework\Setup\Patch\PatchInterface;
@@ -47,7 +49,11 @@ public function getAliases(): array
4749
public function apply(): PatchInterface
4850
{
4951
$this->moduleDataSetup->getConnection()->startSetup();
50-
$this->appState->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
52+
try {
53+
$this->appState->setAreaCode(Area::AREA_ADMINHTML);
54+
} catch (LocalizedException) {
55+
// Area code is already set - nothing to do
56+
}
5157

5258
$storeIds = array_keys($this->storeManager->getStores());
5359
// Delete all replicas before resyncing in case of incorrect replica assignments

0 commit comments

Comments
 (0)