Skip to content

Commit 5a62ce1

Browse files
committed
MAGE-848 Add store level replica disable via CLI
1 parent 6846698 commit 5a62ce1

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

Console/Command/ReplicaDisableVirtualCommand.php

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,53 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8787
*/
8888
protected function disableVirtualReplicas(array $storeIds = []): void
8989
{
90+
$updates = [];
9091
if (count($storeIds)) {
9192
foreach ($storeIds as $storeId) {
92-
$this->disableVirtualReplicasForStore($storeId);
93+
if ($this->disableVirtualReplicasForStore($storeId)) {
94+
$updates[] = $storeId;
95+
}
96+
}
97+
if ($updates) {
98+
$this->clearCache();
99+
foreach ($updates as $storeId) {
100+
$this->syncReplicasForStore($storeId);
101+
}
93102
}
94103
} else {
95104
$this->disableVirtualReplicasForAllStores();
96105
}
97106
}
98107

99-
protected function disableVirtualReplicasForStore(int $storeId): void
108+
protected function disableVirtualReplicasForStore(int $storeId): bool
100109
{
101110
$storeName = $this->storeNameFetcher->getStoreName($storeId);
102111
$isStoreScoped = false;
103112

113+
if ($this->configChecker->isSettingAppliedForScopeAndCode(
114+
ConfigHelper::USE_VIRTUAL_REPLICA_ENABLED,
115+
ScopeInterface::SCOPE_STORES,
116+
$storeId)
117+
) {
118+
$isStoreScoped = true;
119+
$this->removeLegacyVirtualReplicaConfig(ScopeInterface::SCOPE_STORES, $storeId);
120+
}
121+
122+
if ($this->configChecker->isSettingAppliedForScopeAndCode(
123+
ConfigHelper::SORTING_INDICES,
124+
ScopeInterface::SCOPE_STORES,
125+
$storeId)
126+
) {
127+
$isStoreScoped = true;
128+
$this->disableVirtualReplicaSortConfig(ScopeInterface::SCOPE_STORES, $storeId);
129+
}
130+
131+
if (!$isStoreScoped) {
132+
$this->output->writeln("<info>Virtual replicas are not configured at the store level for $storeName. You will need to re-run this command for all stores.</info>");
133+
return false;
134+
}
135+
136+
return true;
104137
}
105138

106139
protected function disableVirtualReplicasForAllStores(): void
@@ -109,7 +142,7 @@ protected function disableVirtualReplicasForAllStores(): void
109142

110143
$this->configChecker->checkAndApplyAllScopes(ConfigHelper::SORTING_INDICES, [$this, 'disableVirtualReplicaSortConfig']);
111144

112-
$this->cacheManager->clean(['config']);
145+
$this->clearCache();
113146

114147
$this->syncReplicasForAllStores();
115148
}
@@ -141,4 +174,9 @@ function($sort) {
141174
$this->configHelper->setSorting($sorting, $scope, $scopeId);
142175
}
143176

177+
protected function clearCache(): void
178+
{
179+
$this->cacheManager->clean(['config']);
180+
}
181+
144182
}

0 commit comments

Comments
 (0)