vendor/shopware/core/Framework/DataAbstractionLayer/Indexing/Subscriber/RegisteredIndexerSubscriber.php line 37

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\DataAbstractionLayer\Indexing\Subscriber;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Indexing\EntityIndexerRegistry;
  4. use Shopware\Core\Framework\Migration\IndexerQueuer;
  5. use Shopware\Core\Framework\Store\Event\FirstRunWizardFinishedEvent;
  6. use Shopware\Core\Framework\Update\Event\UpdatePreFinishEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class RegisteredIndexerSubscriber implements EventSubscriberInterface
  9. {
  10.     private IndexerQueuer $indexerQueuer;
  11.     private EntityIndexerRegistry $indexerRegistry;
  12.     public function __construct(IndexerQueuer $indexerQueuerEntityIndexerRegistry $indexerRegistry)
  13.     {
  14.         $this->indexerQueuer $indexerQueuer;
  15.         $this->indexerRegistry $indexerRegistry;
  16.     }
  17.     /**
  18.      * @return array<string, string|array{0: string, 1: int}|list<array{0: string, 1?: int}>>
  19.      */
  20.     public static function getSubscribedEvents()
  21.     {
  22.         return [
  23.             UpdatePreFinishEvent::class => 'runRegisteredIndexers',
  24.             FirstRunWizardFinishedEvent::class => 'runRegisteredIndexers',
  25.         ];
  26.     }
  27.     /**
  28.      * @internal
  29.      */
  30.     public function runRegisteredIndexers(): void
  31.     {
  32.         $queuedIndexers $this->indexerQueuer->getIndexers();
  33.         if (empty($queuedIndexers)) {
  34.             return;
  35.         }
  36.         $this->indexerQueuer->finishIndexer(array_keys($queuedIndexers));
  37.         foreach ($queuedIndexers as $indexerName => $options) {
  38.             $indexer $this->indexerRegistry->getIndexer($indexerName);
  39.             if ($indexer === null) {
  40.                 continue;
  41.             }
  42.             // If we don't have any required indexer, schedule all
  43.             if ($options === []) {
  44.                 $this->indexerRegistry->sendIndexingMessage([$indexerName]);
  45.                 continue;
  46.             }
  47.             $skipList array_values(array_diff($indexer->getOptions(), $options));
  48.             $this->indexerRegistry->sendIndexingMessage([$indexerName], $skipList);
  49.         }
  50.     }
  51. }