2
2
3
3
namespace Algolia \AlgoliaSearch \Helper \Entity ;
4
4
5
+ use Algolia \AlgoliaSearch \Api \Product \ReplicaManagerInterface ;
5
6
use Algolia \AlgoliaSearch \Exception \ProductDeletedException ;
6
7
use Algolia \AlgoliaSearch \Exception \ProductDisabledException ;
7
8
use Algolia \AlgoliaSearch \Exception \ProductNotVisibleException ;
14
15
use Algolia \AlgoliaSearch \Helper \Entity \Product \PriceManager ;
15
16
use Algolia \AlgoliaSearch \Helper \Image as ImageHelper ;
16
17
use Algolia \AlgoliaSearch \Helper \Logger ;
17
- use Algolia \AlgoliaSearch \Model \Product \ReplicaManager ;
18
18
use Magento \Bundle \Model \Product \Type as BundleProductType ;
19
19
use Magento \Catalog \Model \Product ;
20
20
use Magento \Catalog \Model \Product \Attribute \Source \Status ;
@@ -125,7 +125,7 @@ public function __construct(
125
125
protected GroupCollection $ groupCollection ,
126
126
protected GroupExcludedWebsiteRepositoryInterface $ groupExcludedWebsiteRepository ,
127
127
protected ImageHelper $ imageHelper ,
128
- protected ReplicaManager $ replicaManager
128
+ protected ReplicaManagerInterface $ replicaManager
129
129
) {}
130
130
131
131
/**
@@ -376,7 +376,7 @@ public function setSettings(string $indexName, string $indexNameTmp, int $storeI
376
376
/*
377
377
* Handle replicas
378
378
*/
379
- $ this ->setReplicaSettings ($ indexName , $ storeId );
379
+ $ this ->replicaManager -> handleReplicas ($ indexName , $ storeId, $ indexSettings );
380
380
381
381
if ($ saveToTmpIndicesToo === true ) {
382
382
try {
@@ -403,71 +403,6 @@ public function setSettings(string $indexName, string $indexNameTmp, int $storeI
403
403
}
404
404
}
405
405
406
- protected function setReplicaSettings (string $ indexName , int $ storeId ): void
407
- {
408
- $ this ->replicaManager ->handleReplicas ($ indexName , $ storeId );
409
-
410
- return ;
411
-
412
- $ sortingIndices = $ this ->configHelper ->getSortingIndices ($ indexName , $ storeId );
413
- $ replicas = [];
414
-
415
- if ($ this ->configHelper ->isInstantEnabled ($ storeId )) {
416
- $ replicas = array_values (array_map (function ($ sortingIndex ) {
417
- return $ sortingIndex ['name ' ];
418
- }, $ sortingIndices ));
419
- }
420
-
421
- // Managing Virtual Replica
422
- if ($ this ->configHelper ->useVirtualReplica ($ storeId )) {
423
- $ replicas = $ this ->handleVirtualReplica ($ replicas );
424
- }
425
-
426
- // Merge current replicas with sorting replicas to not delete A/B testing replica indices
427
- try {
428
- $ currentSettings = $ this ->algoliaHelper ->getSettings ($ indexName );
429
- if (is_array ($ currentSettings ) && array_key_exists ('replicas ' , $ currentSettings )) {
430
- $ replicas = array_values (array_unique (array_merge ($ replicas , $ currentSettings ['replicas ' ])));
431
- }
432
- } catch (AlgoliaException $ e ) {
433
- if ($ e ->getCode () !== 404 ) {
434
- throw $ e ;
435
- }
436
- }
437
-
438
- if (count ($ replicas ) > 0 ) {
439
- $ this ->algoliaHelper ->setSettings ($ indexName , ['replicas ' => $ replicas ]);
440
- $ this ->logger ->log ('Setting replicas to " ' . $ indexName . '" index. ' );
441
- $ this ->logger ->log ('Replicas: ' . json_encode ($ replicas ));
442
- $ setReplicasTaskId = $ this ->algoliaHelper ->getLastTaskId ();
443
- if (!$ this ->configHelper ->useVirtualReplica ($ storeId )) {
444
- foreach ($ sortingIndices as $ values ) {
445
- $ replicaName = $ values ['name ' ];
446
- $ indexSettings ['ranking ' ] = $ values ['ranking ' ];
447
- $ this ->algoliaHelper ->setSettings ($ replicaName , $ indexSettings , false , true );
448
- $ this ->logger ->log ('Setting settings to " ' . $ replicaName . '" replica. ' );
449
- $ this ->logger ->log ('Settings: ' . json_encode ($ indexSettings ));
450
- }
451
- } else {
452
- foreach ($ sortingIndices as $ values ) {
453
- $ replicaName = $ values ['name ' ];
454
- array_unshift ($ customRanking , $ values ['ranking ' ][0 ]);
455
- $ replicaSetting ['customRanking ' ] = $ customRanking ;
456
- $ this ->algoliaHelper ->setSettings ($ replicaName , $ replicaSetting , false , false );
457
- $ this ->logger ->log ('Setting settings to " ' . $ replicaName . '" replica. ' );
458
- $ this ->logger ->log ('Settings: ' . json_encode ($ replicaSetting ));
459
- }
460
- }
461
- } else {
462
- $ this ->algoliaHelper ->setSettings ($ indexName , ['replicas ' => []]);
463
- $ this ->logger ->log ('Removing replicas from " ' . $ indexName . '" index ' );
464
- $ setReplicasTaskId = $ this ->algoliaHelper ->getLastTaskId ();
465
- }
466
-
467
- // Commented out as it doesn't delete anything now because of merging replica indices earlier
468
- // $this->deleteUnusedReplicas($indexName, $replicas, $setReplicasTaskId);
469
- }
470
-
471
406
/**
472
407
* @param $categoryIds
473
408
* @param $storeId
@@ -1484,7 +1419,7 @@ public function handleVirtualReplica($replicas)
1484
1419
* Return a formatted Algolia `replicas` configuration for the provided sorting indices
1485
1420
* @param mixed[] $sortingIndices Array of sorting index objects
1486
1421
* @return string[]
1487
- * @deprecated This method is moving to ReplicaManager where it is being re-envisioned
1422
+ * @deprecated This method should no longer used
1488
1423
*/
1489
1424
protected function decorateReplicasSetting (array $ sortingIndices ): array {
1490
1425
return array_map (
@@ -1508,34 +1443,35 @@ function($sort) {
1508
1443
* @throws ExceededRetriesException
1509
1444
* @throws LocalizedException
1510
1445
* @throws NoSuchEntityException
1511
- * @deprecated This function may be removed in a future release
1446
+ * @deprecated This function will be removed in a future release
1447
+ * @see Algolia::AlgoliaSearch::Api::Product::ReplicaManagerInterface
1512
1448
*/
1513
1449
public function handlingReplica (string $ indexName , int $ storeId , $ sortingAttribute = false ): void
1514
1450
{
1515
- // $sortingIndices = $this->configHelper->getSortingIndices($indexName, $storeId, null, $sortingAttribute);
1516
- // if ($this->configHelper->isInstantEnabled($storeId)) {
1517
- // $newReplicas = $this->decorateReplicasSetting($sortingIndices);
1518
- //
1519
- // try {
1520
- // $currentSettings = $this->algoliaHelper->getSettings($indexName);
1521
- // if (array_key_exists('replicas', $currentSettings)) {
1522
- // $oldReplicas = $currentSettings['replicas'];
1523
- // $replicasToDelete = array_diff($oldReplicas, $newReplicas);
1524
- // $this->algoliaHelper->setSettings($indexName, ['replicas' => $newReplicas]);
1525
- // $setReplicasTaskId = $this->algoliaHelper->getLastTaskId();
1526
- // $this->algoliaHelper->waitLastTask($indexName, $setReplicasTaskId);
1527
- // if (count($replicasToDelete) > 0) {
1528
- // foreach ($replicasToDelete as $deletedReplica) {
1529
- // $this->algoliaHelper->deleteIndex($deletedReplica);
1530
- // }
1531
- // }
1532
- // }
1533
- // } catch (AlgoliaException $e) {
1534
- // if ($e->getCode() !== 404) {
1535
- // $this->logger->log($e->getMessage());
1536
- // throw $e;
1537
- // }
1538
- // }
1539
- // }
1451
+ $ sortingIndices = $ this ->configHelper ->getSortingIndices ($ indexName , $ storeId , null , $ sortingAttribute );
1452
+ if ($ this ->configHelper ->isInstantEnabled ($ storeId )) {
1453
+ $ newReplicas = $ this ->decorateReplicasSetting ($ sortingIndices );
1454
+
1455
+ try {
1456
+ $ currentSettings = $ this ->algoliaHelper ->getSettings ($ indexName );
1457
+ if (array_key_exists ('replicas ' , $ currentSettings )) {
1458
+ $ oldReplicas = $ currentSettings ['replicas ' ];
1459
+ $ replicasToDelete = array_diff ($ oldReplicas , $ newReplicas );
1460
+ $ this ->algoliaHelper ->setSettings ($ indexName , ['replicas ' => $ newReplicas ]);
1461
+ $ setReplicasTaskId = $ this ->algoliaHelper ->getLastTaskId ();
1462
+ $ this ->algoliaHelper ->waitLastTask ($ indexName , $ setReplicasTaskId );
1463
+ if (count ($ replicasToDelete ) > 0 ) {
1464
+ foreach ($ replicasToDelete as $ deletedReplica ) {
1465
+ $ this ->algoliaHelper ->deleteIndex ($ deletedReplica );
1466
+ }
1467
+ }
1468
+ }
1469
+ } catch (AlgoliaException $ e ) {
1470
+ if ($ e ->getCode () !== 404 ) {
1471
+ $ this ->logger ->log ($ e ->getMessage ());
1472
+ throw $ e ;
1473
+ }
1474
+ }
1475
+ }
1540
1476
}
1541
1477
}
0 commit comments