@@ -60,6 +60,8 @@ class AlgoliaConnector
60
60
61
61
protected static ?string $ lastTaskId ;
62
62
63
+ protected static ?array $ lastTaskInfoByStore ;
64
+
63
65
public function __construct (
64
66
protected ConfigHelper $ config ,
65
67
protected ManagerInterface $ messageManager ,
@@ -230,7 +232,7 @@ public function setSettings(
230
232
231
233
$ res = $ this ->getClient ($ storeId )->setSettings ($ indexName , $ settings , $ forwardToReplicas );
232
234
233
- self ::setLastOperationInfo ($ indexName , $ res );
235
+ self ::setLastOperationInfo ($ indexName , $ res, $ storeId );
234
236
}
235
237
236
238
/**
@@ -244,7 +246,7 @@ protected function performBatchOperation(string $indexName, array $requests, ?in
244
246
{
245
247
$ response = $ this ->getClient ($ storeId )->batch ($ indexName , [ 'requests ' => $ requests ] );
246
248
247
- self ::setLastOperationInfo ($ indexName , $ response );
249
+ self ::setLastOperationInfo ($ indexName , $ response, $ storeId );
248
250
249
251
return $ response ;
250
252
}
@@ -259,7 +261,7 @@ public function deleteIndex(string $indexName, ?int $storeId = null): void
259
261
{
260
262
$ res = $ this ->getClient ($ storeId )->deleteIndex ($ indexName );
261
263
262
- self ::setLastOperationInfo ($ indexName , $ res );
264
+ self ::setLastOperationInfo ($ indexName , $ res, $ storeId );
263
265
}
264
266
265
267
/**
@@ -285,7 +287,7 @@ function ($id) {
285
287
)
286
288
);
287
289
288
- $ this ->performBatchOperation ($ indexName , $ requests );
290
+ $ this ->performBatchOperation ($ indexName , $ requests, $ storeId );
289
291
}
290
292
291
293
/**
@@ -304,7 +306,7 @@ public function moveIndex(string $fromIndexName, string $toIndexName, ?int $stor
304
306
'destination ' => $ toIndexName
305
307
]
306
308
);
307
- self ::setLastOperationInfo ($ toIndexName , $ response );
309
+ self ::setLastOperationInfo ($ toIndexName , $ response, $ storeId );
308
310
}
309
311
310
312
/**
@@ -453,12 +455,20 @@ function ($object) use ($action) {
453
455
/**
454
456
* @param string $indexName
455
457
* @param array $response
458
+ * @param int|null $storeId
456
459
* @return void
457
460
*/
458
- protected static function setLastOperationInfo (string $ indexName , array $ response ): void
461
+ protected static function setLastOperationInfo (string $ indexName , array $ response, ? int $ storeId = null ): void
459
462
{
460
463
self ::$ lastUsedIndexName = $ indexName ;
461
- self ::$ lastTaskId = $ response [self ::ALGOLIA_API_TASK_ID ] ?? null ;
464
+ self ::$ lastTaskId = $ response [self ::ALGOLIA_API_TASK_ID ] ?? null ;
465
+
466
+ if (!is_null ($ storeId )) {
467
+ self ::$ lastTaskInfoByStore [$ storeId ] = [
468
+ 'indexName ' => $ indexName ,
469
+ 'taskId ' => $ response [self ::ALGOLIA_API_TASK_ID ] ?? null
470
+ ];
471
+ }
462
472
}
463
473
464
474
/**
@@ -478,7 +488,7 @@ public function saveRule(array $rule, string $indexName, bool $forwardToReplicas
478
488
$ forwardToReplicas
479
489
);
480
490
481
- self ::setLastOperationInfo ($ indexName , $ res );
491
+ self ::setLastOperationInfo ($ indexName , $ res, $ storeId );
482
492
}
483
493
484
494
/**
@@ -492,7 +502,7 @@ public function saveRules(string $indexName, array $rules, bool $forwardToReplic
492
502
{
493
503
$ res = $ this ->getClient ($ storeId )->saveRules ($ indexName , $ rules , $ forwardToReplicas );
494
504
495
- self ::setLastOperationInfo ($ indexName , $ res );
505
+ self ::setLastOperationInfo ($ indexName , $ res, $ storeId );
496
506
}
497
507
498
508
@@ -512,7 +522,7 @@ public function deleteRule(
512
522
{
513
523
$ res = $ this ->getClient ($ storeId )->deleteRule ($ indexName , $ objectID , $ forwardToReplicas );
514
524
515
- self ::setLastOperationInfo ($ indexName , $ res );
525
+ self ::setLastOperationInfo ($ indexName , $ res, $ storeId );
516
526
}
517
527
518
528
/**
@@ -532,7 +542,7 @@ public function copySynonyms(string $fromIndexName, string $toIndexName, ?int $s
532
542
'scope ' => ['synonyms ' ]
533
543
]
534
544
);
535
- self ::setLastOperationInfo ($ fromIndexName , $ response );
545
+ self ::setLastOperationInfo ($ fromIndexName , $ response, $ storeId );
536
546
}
537
547
538
548
/**
@@ -552,7 +562,7 @@ public function copyQueryRules(string $fromIndexName, string $toIndexName, ?int
552
562
'scope ' => ['rules ' ]
553
563
]
554
564
);
555
- self ::setLastOperationInfo ($ fromIndexName , $ response );
565
+ self ::setLastOperationInfo ($ fromIndexName , $ response, $ storeId );
556
566
}
557
567
558
568
/**
@@ -578,7 +588,7 @@ public function clearIndex(string $indexName, ?int $storeId = null): void
578
588
{
579
589
$ res = $ this ->getClient ($ storeId )->clearObjects ($ indexName );
580
590
581
- self ::setLastOperationInfo ($ indexName , $ res );
591
+ self ::setLastOperationInfo ($ indexName , $ res, $ storeId );
582
592
}
583
593
584
594
/**
@@ -589,22 +599,30 @@ public function clearIndex(string $indexName, ?int $storeId = null): void
589
599
*/
590
600
public function waitLastTask (?int $ storeId = null , ?string $ lastUsedIndexName = null , ?int $ lastTaskId = null ): void
591
601
{
592
- if (is_null ($ storeId )) {
593
- $ storeId = self ::ALGOLIA_DEFAULT_SCOPE ;
594
- }
595
-
596
- if ( $ lastUsedIndexName === null && isset ( self ::$ lastUsedIndexName)) {
597
- $ lastUsedIndexName = self :: $ lastUsedIndexName ;
602
+ if (is_null ($ lastUsedIndexName )) {
603
+ if (! is_null ( $ storeId) && isset ( self ::$ lastTaskInfoByStore [ $ storeId ])) {
604
+ $ lastUsedIndexName = self :: $ lastTaskInfoByStore [ $ storeId ][ ' indexName ' ];
605
+ } elseif ( isset ( self :: $ lastUsedIndexName )){
606
+ $ lastUsedIndexName = self ::$ lastUsedIndexName;
607
+ }
598
608
}
599
609
600
- if ($ lastTaskId === null && isset (self ::$ lastTaskId )) {
601
- $ lastTaskId = self ::$ lastTaskId ;
610
+ if (is_null ($ lastTaskId )) {
611
+ if (!is_null ($ storeId ) && isset (self ::$ lastTaskInfoByStore [$ storeId ])) {
612
+ $ lastTaskId = self ::$ lastTaskInfoByStore [$ storeId ]['taskId ' ];
613
+ } elseif (isset (self ::$ lastTaskId )){
614
+ $ lastTaskId = self ::$ lastTaskId ;
615
+ }
602
616
}
603
617
604
618
if (!$ lastUsedIndexName || !$ lastTaskId ) {
605
619
return ;
606
620
}
607
621
622
+ if (is_null ($ storeId )) {
623
+ $ storeId = self ::ALGOLIA_DEFAULT_SCOPE ;
624
+ }
625
+
608
626
$ this ->getClient ($ storeId )->waitForTask ($ lastUsedIndexName , $ lastTaskId );
609
627
}
610
628
@@ -827,31 +845,19 @@ protected function castAttribute($value): mixed
827
845
828
846
/**
829
847
* @param int|null $storeId
830
- * @return string
831
- */
832
- public function getLastIndexName (?int $ storeId = null ): string
833
- {
834
- if (is_null ($ storeId )) {
835
- $ storeId = self ::ALGOLIA_DEFAULT_SCOPE ;
836
- }
837
-
838
- if (!isset (self ::$ lastUsedIndexNames [$ storeId ])) {
839
- return '' ;
840
- }
841
-
842
- return self ::$ lastUsedIndexNames [$ storeId ];
843
- }
844
-
845
- /**
846
848
* @return int|null
847
849
*/
848
- public function getLastTaskId (): int |null
850
+ public function getLastTaskId (? int $ storeId = null ): int |null
849
851
{
850
- if (!isset (self ::$ lastUsedIndexName )) {
851
- return null ;
852
+ $ lastTaskId = null ;
853
+
854
+ if (!is_null ($ storeId ) && isset (self ::$ lastTaskInfoByStore [$ storeId ])) {
855
+ $ lastTaskId = self ::$ lastTaskInfoByStore [$ storeId ]['taskId ' ];
856
+ } elseif (isset (self ::$ lastTaskId )){
857
+ $ lastTaskId = self ::$ lastTaskId ;
852
858
}
853
859
854
- return self :: $ lastTaskId ;
860
+ return $ lastTaskId ;
855
861
}
856
862
857
863
/**
0 commit comments