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