@@ -456,12 +456,14 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
456
456
457
457
if ($ this ->configHelper ->isInstantEnabled ($ storeId )) {
458
458
$ replicas = array_values (array_map (function ($ sortingIndex ) {
459
- return [ $ sortingIndex ['name ' ], $ sortingIndex [ ' virtualReplica ' ] ];
459
+ rreturn $ sortingIndex ['name ' ];
460
460
}, $ sortingIndices ));
461
461
}
462
462
463
463
// Managing Virtual Replica
464
- $ replicas = $ this ->handleVirtualReplica ($ replicas , $ indexName , $ storeId );
464
+ if ($ this ->configHelper ->useVirtualReplica ($ storeId )) {
465
+ $ replicas = $ this ->handleVirtualReplica ($ replicas , $ indexName );
466
+ }
465
467
466
468
// Merge current replicas with sorting replicas to not delete A/B testing replica indices
467
469
try {
@@ -480,23 +482,24 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
480
482
$ this ->logger ->log ('Setting replicas to " ' . $ indexName . '" index. ' );
481
483
$ this ->logger ->log ('Replicas: ' . json_encode ($ replicas ));
482
484
$ setReplicasTaskId = $ this ->algoliaHelper ->getLastTaskId ();
483
- foreach ($ sortingIndices as $ values ) {
484
- if ($ values ['virtualReplica ' ]) {
485
+ if (!$ this ->configHelper ->useVirtualReplica ($ storeId )) {
486
+ foreach ($ sortingIndices as $ values ) {
487
+ $ replicaName = $ values ['name ' ];
488
+ $ indexSettings ['ranking ' ] = $ values ['ranking ' ];
489
+ $ this ->algoliaHelper ->setSettings ($ replicaName , $ indexSettings , false , true );
490
+ $ this ->logger ->log ('Setting settings to " ' . $ replicaName . '" replica. ' );
491
+ $ this ->logger ->log ('Settings: ' . json_encode ($ indexSettings ));
492
+ }
493
+ } else {
494
+ foreach ($ sortingIndices as $ values ) {
485
495
$ replicaName = $ values ['name ' ];
486
496
array_unshift ($ customRanking , $ values ['ranking ' ][0 ]);
487
497
$ replicaSetting ['customRanking ' ] = $ customRanking ;
488
498
$ this ->algoliaHelper ->setSettings ($ replicaName , $ replicaSetting , false , false );
489
499
$ this ->logger ->log ('Setting settings to " ' . $ replicaName . '" replica. ' );
490
500
$ this ->logger ->log ('Settings: ' . json_encode ($ replicaSetting ));
491
- } else {
492
- $ replicaName = $ values ['name ' ];
493
- $ indexSettings ['ranking ' ] = $ values ['ranking ' ];
494
- $ this ->algoliaHelper ->setSettings ($ replicaName , $ indexSettings , false , true );
495
- $ this ->logger ->log ('Setting settings to " ' . $ replicaName . '" replica. ' );
496
- $ this ->logger ->log ('Settings: ' . json_encode ($ indexSettings ));
497
501
}
498
502
}
499
-
500
503
} else {
501
504
$ this ->algoliaHelper ->setSettings ($ indexName , ['replicas ' => []]);
502
505
$ this ->logger ->log ('Removing replicas from " ' . $ indexName . '" index ' );
@@ -1525,17 +1528,13 @@ public function productIsInStock($product, $storeId)
1525
1528
* @param $replica
1526
1529
* @return array
1527
1530
*/
1528
- public function handleVirtualReplica ($ replicas , $ indexName, $ storeId )
1531
+ public function handleVirtualReplica ($ replicas , $ indexName )
1529
1532
{
1530
1533
$ virtualReplicaArray = [];
1531
1534
foreach ($ replicas as $ replica ) {
1532
- if ($ replica [1 ]) {
1533
- $ replicaArray [] = 'virtual( ' . $ replica [0 ] . ') ' ;
1534
- } else {
1535
- $ replicaArray [] = $ replica [0 ];
1536
- }
1535
+ $ virtualReplicaArray [] = 'virtual( ' . $ replica . ') ' ;
1537
1536
}
1538
- return $ replicaArray ;
1537
+ return $ virtualReplicaArray ;
1539
1538
}
1540
1539
1541
1540
/**
@@ -1553,14 +1552,12 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false)
1553
1552
return $ sortingIndex ['name ' ];
1554
1553
}, $ sortingIndices ));
1555
1554
try {
1556
- $ replicasFormated = $ this ->handleVirtualReplica ($ replicas );
1557
- $ availableReplicaMatch = array_merge ($ replicasFormated , $ replicas );
1558
1555
if ($ this ->configHelper ->useVirtualReplica ($ storeId )) {
1559
- $ replicas = $ replicasFormated ;
1556
+ $ replicas = $ this -> handleVirtualReplica ( $ replicas , $ indexName ) ;
1560
1557
}
1561
1558
$ currentSettings = $ this ->algoliaHelper ->getSettings ($ indexName );
1562
1559
if (is_array ($ currentSettings ) && array_key_exists ('replicas ' , $ currentSettings )) {
1563
- $ replicasRequired = array_values (array_diff ($ currentSettings ['replicas ' ], $ availableReplicaMatch ));
1560
+ $ replicasRequired = array_values (array_diff_assoc ($ currentSettings ['replicas ' ], $ replicas ));
1564
1561
$ this ->algoliaHelper ->setSettings ($ indexName , ['replicas ' => $ replicasRequired ]);
1565
1562
$ setReplicasTaskId = $ this ->algoliaHelper ->getLastTaskId ();
1566
1563
$ this ->algoliaHelper ->waitLastTask ($ indexName , $ setReplicasTaskId );
@@ -1579,4 +1576,4 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false)
1579
1576
}
1580
1577
return true ;
1581
1578
}
1582
- }
1579
+ }
0 commit comments