@@ -58,11 +58,20 @@ class AlgoliaConnector
58
58
/** @var bool */
59
59
protected bool $ userAgentsAdded = false ;
60
60
61
- protected static ?string $ lastUsedIndexName ;
61
+ /**
62
+ * @var string|null
63
+ */
64
+ protected ?string $ lastUsedIndexName ;
62
65
63
- protected static ?string $ lastTaskId ;
66
+ /**
67
+ * @var string|null
68
+ */
69
+ protected ?string $ lastTaskId ;
64
70
65
- protected static ?array $ lastTaskInfoByStore ;
71
+ /**
72
+ * @var array|null
73
+ */
74
+ protected ?array $ lastTaskInfoByStore ;
66
75
67
76
public function __construct (
68
77
protected ConfigHelper $ config ,
@@ -238,21 +247,23 @@ public function setSettings(
238
247
239
248
$ res = $ this ->getClient ($ indexOptions ->getStoreId ())->setSettings ($ indexName , $ settings , $ forwardToReplicas );
240
249
241
- self :: setLastOperationInfo ($ indexName , $ res, $ indexOptions -> getStoreId () );
250
+ $ this -> setLastOperationInfo ($ indexOptions , $ res );
242
251
}
243
252
244
253
/**
245
- * @param string $indexName
254
+ * @param IndexOptionsInterface $indexOptions
246
255
* @param array $requests
247
- * @param int|null $storeId
248
256
* @return array<string, mixed>
249
257
* @throws AlgoliaException
258
+ * @throws NoSuchEntityException
250
259
*/
251
- protected function performBatchOperation (string $ indexName , array $ requests, ? int $ storeId = null ): array
260
+ protected function performBatchOperation (IndexOptionsInterface $ indexOptions , array $ requests ): array
252
261
{
253
- $ response = $ this ->getClient ( $ storeId )-> batch ( $ indexName , [ ' requests ' => $ requests ] );
262
+ $ indexName = $ this ->getIndexName ( $ indexOptions );
254
263
255
- self ::setLastOperationInfo ($ indexName , $ response , $ storeId );
264
+ $ response = $ this ->getClient ($ indexOptions ->getStoreId ())->batch ($ indexName , [ 'requests ' => $ requests ] );
265
+
266
+ $ this ->setLastOperationInfo ($ indexOptions , $ response );
256
267
257
268
return $ response ;
258
269
}
@@ -268,14 +279,14 @@ public function deleteIndex(IndexOptionsInterface $indexOptions): void
268
279
269
280
$ res = $ this ->getClient ($ indexOptions ->getStoreId ())->deleteIndex ($ indexName );
270
281
271
- self :: setLastOperationInfo ($ indexName , $ res, $ indexOptions -> getStoreId () );
282
+ $ this -> setLastOperationInfo ($ indexOptions , $ res );
272
283
}
273
284
274
285
/**
275
286
* @param array $ids
276
287
* @param IndexOptionsInterface $indexOptions
277
288
* @return void
278
- * @throws AlgoliaException
289
+ * @throws AlgoliaException|NoSuchEntityException
279
290
*/
280
291
public function deleteObjects (array $ ids , IndexOptionsInterface $ indexOptions ): void
281
292
{
@@ -293,9 +304,7 @@ function ($id) {
293
304
)
294
305
);
295
306
296
- $ indexName = $ this ->getIndexName ($ indexOptions );
297
-
298
- $ this ->performBatchOperation ($ indexName , $ requests , $ indexOptions ->getStoreId ());
307
+ $ this ->performBatchOperation ($ indexOptions , $ requests );
299
308
}
300
309
301
310
/**
@@ -317,7 +326,7 @@ public function moveIndex(IndexOptions $fromIndexOptions, IndexOptions $toIndexO
317
326
'destination ' => $ toIndexName
318
327
]
319
328
);
320
- self :: setLastOperationInfo ($ toIndexName , $ response, $ toIndexOptions -> getStoreId () );
329
+ $ this -> setLastOperationInfo ($ toIndexOptions , $ response );
321
330
}
322
331
323
332
/**
@@ -464,22 +473,25 @@ function ($object) use ($action) {
464
473
)
465
474
);
466
475
467
- $ this ->performBatchOperation ($ indexName , $ requests, $ indexOptions -> getStoreId () );
476
+ $ this ->performBatchOperation ($ indexOptions , $ requests );
468
477
}
469
478
470
479
/**
471
- * @param string $indexName
480
+ * @param IndexOptionsInterface $indexOptions
472
481
* @param array $response
473
- * @param int|null $storeId
474
482
* @return void
483
+ * @throws NoSuchEntityException
475
484
*/
476
- protected static function setLastOperationInfo (string $ indexName , array $ response, ? int $ storeId = null ): void
485
+ protected function setLastOperationInfo (IndexOptionsInterface $ indexOptions , array $ response ): void
477
486
{
478
- self ::$ lastUsedIndexName = $ indexName ;
479
- self ::$ lastTaskId = $ response [self ::ALGOLIA_API_TASK_ID ] ?? null ;
487
+ $ indexName = $ this ->getIndexName ($ indexOptions );
488
+ $ storeId = $ indexOptions ->getStoreId ();
489
+
490
+ $ this ->lastUsedIndexName = $ indexName ;
491
+ $ this ->lastTaskId = $ response [self ::ALGOLIA_API_TASK_ID ] ?? null ;
480
492
481
493
if (!is_null ($ storeId )) {
482
- self :: $ lastTaskInfoByStore [$ storeId ] = [
494
+ $ this -> lastTaskInfoByStore [$ storeId ] = [
483
495
'indexName ' => $ indexName ,
484
496
'taskId ' => $ response [self ::ALGOLIA_API_TASK_ID ] ?? null
485
497
];
@@ -505,7 +517,7 @@ public function saveRule(array $rule, IndexOptionsInterface $indexOptions, bool
505
517
$ forwardToReplicas
506
518
);
507
519
508
- self :: setLastOperationInfo ($ indexName , $ res, $ indexOptions -> getStoreId () );
520
+ $ this -> setLastOperationInfo ($ indexOptions , $ res );
509
521
}
510
522
511
523
/**
@@ -522,7 +534,7 @@ public function saveRules(IndexOptionsInterface $indexOptions, array $rules, boo
522
534
523
535
$ res = $ this ->getClient ($ indexOptions ->getStoreId ())->saveRules ($ indexName , $ rules , $ forwardToReplicas );
524
536
525
- self :: setLastOperationInfo ($ indexName , $ res, $ indexOptions -> getStoreId () );
537
+ $ this -> setLastOperationInfo ($ indexOptions , $ res );
526
538
}
527
539
528
540
@@ -544,7 +556,7 @@ public function deleteRule(
544
556
545
557
$ res = $ this ->getClient ($ indexOptions ->getStoreId ())->deleteRule ($ indexName , $ objectID , $ forwardToReplicas );
546
558
547
- self :: setLastOperationInfo ($ indexName , $ res, $ indexOptions -> getStoreId () );
559
+ $ this -> setLastOperationInfo ($ indexOptions , $ res );
548
560
}
549
561
550
562
/**
@@ -567,7 +579,7 @@ public function copySynonyms(IndexOptionsInterface $fromIndexOptions, IndexOptio
567
579
'scope ' => ['synonyms ' ]
568
580
]
569
581
);
570
- self :: setLastOperationInfo ($ fromIndexName , $ response, $ toIndexOptions -> getStoreId () );
582
+ $ this -> setLastOperationInfo ($ fromIndexOptions , $ response );
571
583
}
572
584
573
585
/**
@@ -590,7 +602,7 @@ public function copyQueryRules(IndexOptionsInterface $fromIndexOptions, IndexOpt
590
602
'scope ' => ['rules ' ]
591
603
]
592
604
);
593
- self :: setLastOperationInfo ($ fromIndexName , $ response, $ toIndexOptions -> getStoreId () );
605
+ $ this -> setLastOperationInfo ($ fromIndexOptions , $ response );
594
606
}
595
607
596
608
/**
@@ -620,7 +632,7 @@ public function clearIndex(IndexOptionsInterface $indexOptions): void
620
632
621
633
$ res = $ this ->getClient ($ indexOptions ->getStoreId ())->clearObjects ($ indexName );
622
634
623
- self :: setLastOperationInfo ($ indexName , $ res, $ indexOptions -> getStoreId () );
635
+ $ this -> setLastOperationInfo ($ indexOptions , $ res );
624
636
}
625
637
626
638
/**
@@ -632,18 +644,18 @@ public function clearIndex(IndexOptionsInterface $indexOptions): void
632
644
public function waitLastTask (?int $ storeId = null , ?string $ lastUsedIndexName = null , ?int $ lastTaskId = null ): void
633
645
{
634
646
if (is_null ($ lastUsedIndexName )) {
635
- if (!is_null ($ storeId ) && isset (self :: $ lastTaskInfoByStore [$ storeId ])) {
636
- $ lastUsedIndexName = self :: $ lastTaskInfoByStore [$ storeId ]['indexName ' ];
637
- } elseif (isset (self :: $ lastUsedIndexName )){
638
- $ lastUsedIndexName = self :: $ lastUsedIndexName ;
647
+ if (!is_null ($ storeId ) && isset ($ this -> lastTaskInfoByStore [$ storeId ])) {
648
+ $ lastUsedIndexName = $ this -> lastTaskInfoByStore [$ storeId ]['indexName ' ];
649
+ } elseif (isset ($ this -> lastUsedIndexName )){
650
+ $ lastUsedIndexName = $ this -> lastUsedIndexName ;
639
651
}
640
652
}
641
653
642
654
if (is_null ($ lastTaskId )) {
643
- if (!is_null ($ storeId ) && isset (self :: $ lastTaskInfoByStore [$ storeId ])) {
644
- $ lastTaskId = self :: $ lastTaskInfoByStore [$ storeId ]['taskId ' ];
645
- } elseif (isset (self :: $ lastTaskId )){
646
- $ lastTaskId = self :: $ lastTaskId ;
655
+ if (!is_null ($ storeId ) && isset ($ this -> lastTaskInfoByStore [$ storeId ])) {
656
+ $ lastTaskId = $ this -> lastTaskInfoByStore [$ storeId ]['taskId ' ];
657
+ } elseif (isset ($ this -> lastTaskId )){
658
+ $ lastTaskId = $ this -> lastTaskId ;
647
659
}
648
660
}
649
661
@@ -883,10 +895,10 @@ public function getLastTaskId(?int $storeId = null): int|null
883
895
{
884
896
$ lastTaskId = null ;
885
897
886
- if (!is_null ($ storeId ) && isset (self :: $ lastTaskInfoByStore [$ storeId ])) {
887
- $ lastTaskId = self :: $ lastTaskInfoByStore [$ storeId ]['taskId ' ];
888
- } elseif (isset (self :: $ lastTaskId )){
889
- $ lastTaskId = self :: $ lastTaskId ;
898
+ if (!is_null ($ storeId ) && isset ($ this -> lastTaskInfoByStore [$ storeId ])) {
899
+ $ lastTaskId = $ this -> lastTaskInfoByStore [$ storeId ]['taskId ' ];
900
+ } elseif (isset ($ this -> lastTaskId )){
901
+ $ lastTaskId = $ this -> lastTaskId ;
890
902
}
891
903
892
904
return $ lastTaskId ;
0 commit comments