fullAction = $fullActionFactory->create(['data' => $data]); $this->indexerHandlerFactory = $indexerHandlerFactory; $this->fulltextResource = $fulltextResource; $this->data = $data; $this->indexSwitcher = $indexSwitcher; $this->indexScopeState = $indexScopeStateFactory->create(); $this->dimensionProvider = $dimensionProvider; $this->processManager = $processManager ?: \Magento\Framework\App\ObjectManager::getInstance()->get( ProcessManager::class ); } /** * Execute materialization on ids entities * * @param int[] $entityIds * @return void * @throws \InvalidArgumentException */ public function execute($entityIds) { foreach ($this->dimensionProvider->getIterator() as $dimension) { $this->executeByDimensions($dimension, new \ArrayIterator($entityIds)); } } /** * @inheritdoc * * @throws \InvalidArgumentException * @since 101.0.0 */ public function executeByDimensions(array $dimensions, \Traversable $entityIds = null) { if (count($dimensions) > 1 || !isset($dimensions[StoreDimensionProvider::DIMENSION_NAME])) { throw new \InvalidArgumentException('Indexer "' . self::INDEXER_ID . '" support only Store dimension'); } $storeId = $dimensions[StoreDimensionProvider::DIMENSION_NAME]->getValue(); $saveHandler = $this->indexerHandlerFactory->create([ 'data' => $this->data ]); if (null === $entityIds) { $this->indexScopeState->useTemporaryIndex(); $saveHandler->cleanIndex($dimensions); $saveHandler->saveIndex($dimensions, $this->fullAction->rebuildStoreIndex($storeId)); $this->indexSwitcher->switchIndex($dimensions); $this->indexScopeState->useRegularIndex(); $this->fulltextResource->resetSearchResultsByStore($storeId); } else { // internal implementation works only with array $entityIds = iterator_to_array($entityIds); $productIds = array_unique( array_merge($entityIds, $this->fulltextResource->getRelationsByChild($entityIds)) ); if ($saveHandler->isAvailable($dimensions)) { $saveHandler->deleteIndex($dimensions, new \ArrayIterator($productIds)); $saveHandler->saveIndex($dimensions, $this->fullAction->rebuildStoreIndex($storeId, $productIds)); } } } /** * Execute full indexation * * @return void * @throws \InvalidArgumentException */ public function executeFull() { $userFunctions = []; foreach ($this->dimensionProvider->getIterator() as $dimension) { $userFunctions[] = function () use ($dimension) { $this->executeByDimensions($dimension); }; } $this->processManager->execute($userFunctions); } /** * Execute partial indexation by ID list * * @param int[] $ids * @return void */ public function executeList(array $ids) { $this->execute($ids); } /** * Execute partial indexation by ID * * @param int $id * @return void */ public function executeRow($id) { $this->execute([$id]); } }