@@ -417,23 +417,90 @@ public function reindexAll()
417
417
$ state = $ this ->getState ();
418
418
$ state ->setStatus (StateInterface::STATUS_WORKING );
419
419
$ state ->save ();
420
+
421
+ $ sharedIndexers = [];
422
+ $ indexerConfig = $ this ->config ->getIndexer ($ this ->getId ());
423
+ if ($ indexerConfig ['shared_index ' ] !== null ) {
424
+ $ sharedIndexers = $ this ->getSharedIndexers ($ indexerConfig ['shared_index ' ]);
425
+ }
426
+ if (!empty ($ sharedIndexers )) {
427
+ $ this ->suspendSharedViews ($ sharedIndexers );
428
+ }
429
+
420
430
if ($ this ->getView ()->isEnabled ()) {
421
431
$ this ->getView ()->suspend ();
422
432
}
423
433
try {
424
434
$ this ->getActionInstance ()->executeFull ();
425
435
$ state ->setStatus (StateInterface::STATUS_VALID );
426
436
$ state ->save ();
437
+ if (!empty ($ sharedIndexers )) {
438
+ $ this ->resumeSharedViews ($ sharedIndexers );
439
+ }
427
440
$ this ->getView ()->resume ();
428
441
} catch (\Throwable $ exception ) {
429
442
$ state ->setStatus (StateInterface::STATUS_INVALID );
430
443
$ state ->save ();
444
+ if (!empty ($ sharedIndexers )) {
445
+ $ this ->resumeSharedViews ($ sharedIndexers );
446
+ }
431
447
$ this ->getView ()->resume ();
432
448
throw $ exception ;
433
449
}
434
450
}
435
451
}
436
452
453
+ /**
454
+ * Get indexer ids that uses same index
455
+ *
456
+ * @param string $sharedIndex
457
+ * @return array
458
+ */
459
+ private function getSharedIndexers (string $ sharedIndex ) : array
460
+ {
461
+ $ result = [];
462
+ foreach (array_keys ($ this ->config ->getIndexers ()) as $ indexerId ) {
463
+ if ($ indexerId === $ this ->getId ()) {
464
+ continue ;
465
+ }
466
+ $ indexerConfig = $ this ->config ->getIndexer ($ indexerId );
467
+ if ($ indexerConfig ['shared_index ' ] === $ sharedIndex ) {
468
+ $ indexer = $ this ->indexersFactory ->create ();
469
+ $ indexer ->load ($ indexerId );
470
+ $ result [] = $ indexer ;
471
+ }
472
+ }
473
+ return $ result ;
474
+ }
475
+
476
+ /**
477
+ * Suspend views of shared indexers
478
+ *
479
+ * @param array $sharedIndexers
480
+ * @return void
481
+ */
482
+ private function suspendSharedViews (array $ sharedIndexers ) : void
483
+ {
484
+ foreach ($ sharedIndexers as $ indexer ) {
485
+ if ($ indexer ->getView ()->isEnabled ()) {
486
+ $ indexer ->getView ()->suspend ();
487
+ }
488
+ }
489
+ }
490
+
491
+ /**
492
+ * Suspend views of shared indexers
493
+ *
494
+ * @param array $sharedIndexers
495
+ * @return void
496
+ */
497
+ private function resumeSharedViews (array $ sharedIndexers ) : void
498
+ {
499
+ foreach ($ sharedIndexers as $ indexer ) {
500
+ $ indexer ->getView ()->resume ();
501
+ }
502
+ }
503
+
437
504
/**
438
505
* Regenerate one row in index by ID
439
506
*
0 commit comments