getAllStockIds = $getAllStockIds; $this->indexStructure = $indexStructure; $this->indexHandler = $indexHandler; $this->indexNameBuilder = $indexNameBuilder; $this->indexDataByStockIdProvider = $indexDataByStockIdProvider; $this->indexTableSwitcher = $indexTableSwitcher; $this->defaultStockProvider = $defaultStockProvider; } /** * @return void * @throws StateException */ public function executeFull() { $stockIds = $this->getAllStockIds->execute(); $this->executeList($stockIds); } /** * @param int $stockId * @return void * @throws StateException */ public function executeRow(int $stockId) { $this->executeList([$stockId]); } /** * @param array $stockIds * @return void * @throws StateException */ public function executeList(array $stockIds) { foreach ($stockIds as $stockId) { if ($this->defaultStockProvider->getId() === $stockId) { continue; } $mainIndexName = $this->indexNameBuilder ->setIndexId(InventoryIndexer::INDEXER_ID) ->addDimension('stock_', (string)$stockId) ->setAlias(Alias::ALIAS_MAIN) ->build(); if (!$this->indexStructure->isExist($mainIndexName, ResourceConnection::DEFAULT_CONNECTION)) { $this->indexStructure->create($mainIndexName, ResourceConnection::DEFAULT_CONNECTION); } $indexData = $this->indexDataByStockIdProvider->execute((int)$stockId); $this->indexHandler->cleanIndex( $mainIndexName, $indexData, ResourceConnection::DEFAULT_CONNECTION ); $this->indexHandler->saveIndex( $mainIndexName, $indexData, ResourceConnection::DEFAULT_CONNECTION ); } } }