Skip to content

Commit bb9de74

Browse files
committed
MAGE-1251 Simplify eligible store ID logic
1 parent dcd5eb7 commit bb9de74

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

Setup/Patch/Data/RebuildReplicasPatch.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,14 @@ public function apply(): PatchInterface
6262
// Area code is already set - nothing to do
6363
}
6464

65-
$storeIds = array_filter(
66-
array_keys($this->storeManager->getStores()),
67-
function (int $storeId) { return $this->replicaManager->isReplicaSyncEnabled($storeId); }
68-
);
65+
$storeIds = $this->getStoreIdsEligibleForPatch();
6966

7067
try {
7168
// Delete all replicas before resyncing in case of incorrect replica assignments
7269
foreach ($storeIds as $storeId) {
73-
if (!$this->algoliaCredentialsManager->checkCredentialsWithSearchOnlyAPIKey($storeId)) {
74-
$this->logger->warning("Algolia credentials are not configured for store $storeId. Skipping auto replica rebuild for this store. If you need to rebuild your replicas run `bin/magento algolia:replicas:rebuild`");
75-
continue;
76-
}
77-
7870
$this->retryDeleteReplica($storeId);
7971
}
8072
foreach ($storeIds as $storeId) {
81-
if (!$this->algoliaCredentialsManager->checkCredentialsWithSearchOnlyAPIKey($storeId)) {
82-
continue;
83-
}
8473
$this->replicaState->setChangeState(ReplicaState::REPLICA_STATE_CHANGED, $storeId); // avoids latency
8574
$this->replicaManager->syncReplicasToAlgolia($storeId, $this->productHelper->getIndexSettings($storeId));
8675
}
@@ -94,6 +83,21 @@ function (int $storeId) { return $this->replicaManager->isReplicaSyncEnabled($st
9483
return $this;
9584
}
9685

86+
protected function getStoreIdsEligibleForPatch(): array
87+
{
88+
return array_filter(
89+
array_keys($this->storeManager->getStores()),
90+
function (int $storeId) {
91+
if (!$this->replicaManager->isReplicaSyncEnabled($storeId)) return false;
92+
if (!$this->algoliaCredentialsManager->checkCredentials($storeId)) {
93+
$this->logger->warning("Algolia credentials are not configured for store $storeId. Skipping auto replica rebuild for this store. If you need to rebuild your replicas run `bin/magento algolia:replicas:rebuild`");
94+
return false;
95+
}
96+
return true;
97+
}
98+
);
99+
}
100+
97101
protected function retryDeleteReplica(int $storeId, int $maxRetries = 3, int $interval = 5)
98102
{
99103
for ($tries = $maxRetries - 1; $tries >= 0; $tries--) {

0 commit comments

Comments
 (0)