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

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