Skip to content

Commit dcd5eb7

Browse files
committed
MAGE-1251 Apply scoping to delete operations for multi store
1 parent a75e3ae commit dcd5eb7

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Service/Product/ReplicaManager.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,19 +371,21 @@ protected function getBareIndexNameFromReplicaSetting(string $replicaSetting): s
371371
*
372372
* @param array $replicasToDelete - which replicas to delete
373373
* @param bool $waitLastTask - wait until deleting next replica (default: false)
374-
* @param bool $prevalidate - verify replica is not attached to a primary index before attempting to delete (default: false)
374+
* @param bool $safeMode - ensure replica is not attached to a primary index before attempting to delete (default: false)
375+
* @param int|null $storeId
375376
* @return void
376377
* @throws AlgoliaException
377378
* @throws ExceededRetriesException
379+
* @throws NoSuchEntityException
378380
*/
379381
protected function deleteReplicas(
380382
array $replicasToDelete,
381383
bool $waitLastTask = false,
382-
bool $prevalidate = false,
384+
bool $safeMode = false,
383385
?int $storeId = null): void
384386
{
385387
foreach ($replicasToDelete as $deletedReplica) {
386-
$this->deleteReplica($deletedReplica, $prevalidate);
388+
$this->deleteReplica($deletedReplica, $safeMode, $storeId);
387389
if ($waitLastTask) {
388390
$this->algoliaHelper->waitLastTask($storeId, $deletedReplica);
389391
}
@@ -393,11 +395,12 @@ protected function deleteReplicas(
393395
/**
394396
* @throws AlgoliaException
395397
* @throws ExceededRetriesException
398+
* @throws NoSuchEntityException
396399
*/
397-
protected function deleteReplica(string $replicaIndexName, bool $precheck = false, ?int $storeId = null): void
400+
protected function deleteReplica(string $replicaIndexName, bool $safeMode = false, ?int $storeId = null): void
398401
{
399-
if ($precheck) {
400-
$settings = $this->algoliaHelper->getSettings($replicaIndexName);
402+
if ($safeMode) {
403+
$settings = $this->algoliaHelper->getSettings($replicaIndexName, $storeId);
401404
if (isset($settings[self::ALGOLIA_SETTINGS_KEY_PRIMARY])) {
402405
$this->detachReplica($settings[self::ALGOLIA_SETTINGS_KEY_PRIMARY], $replicaIndexName, $storeId);
403406
}
@@ -411,10 +414,11 @@ protected function deleteReplica(string $replicaIndexName, bool $precheck = fals
411414
*
412415
* @throws ExceededRetriesException
413416
* @throws AlgoliaException
417+
* @throws NoSuchEntityException
414418
*/
415419
protected function detachReplica(string $primaryIndexName, string $replicaIndexName, ?int $storeId = null): void
416420
{
417-
$settings = $this->algoliaHelper->getSettings($primaryIndexName);
421+
$settings = $this->algoliaHelper->getSettings($primaryIndexName, $storeId);
418422
if (!isset($settings[self::ALGOLIA_SETTINGS_KEY_REPLICAS])) {
419423
return;
420424
}

Test/Integration/Indexing/Product/Traits/ReplicaAssertionsTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ protected function mockSortUpdate(string $sortAttr, string $sortDir, array $attr
137137
return $item['attribute'] === $sortAttr && $item['sort'] === $sortDir;
138138
});
139139

140-
141140
if ($existing) {
142141
$idx = array_key_first($existing);
143142
$sorting[$idx] = array_merge($existing[$idx], $attr);

0 commit comments

Comments
 (0)