indexBuilder = $indexBuilder; $this->eventManager = $eventManager; $this->cacheManager = $cacheManager; $this->cacheContext = $cacheContext; } /** * @param int[] $ids * @throws \Magento\Framework\Exception\LocalizedException */ public function execute($ids) { $this->executeList($ids); } /** * @throws \Magento\Framework\Exception\LocalizedException */ public function executeFull() { $this->indexBuilder->reindexFull(); $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this]); //was needed before MAGETWO-50668 was fixed $this->cacheManager->clean($this->getIdentities()); } /** * @param int $productId * @throws \Magento\Framework\Exception\LocalizedException */ public function executeRow($id) { if (!$id) { throw new \Magento\Framework\Exception\LocalizedException( __('We can\'t rebuild the index for an undefined entity.') ); } $this->doExecuteRow($id); } /** * @param int[] $ids * @throws \Magento\Framework\Exception\LocalizedException */ public function executeList(array $ids) { if (!$ids) { throw new \Magento\Framework\Exception\LocalizedException( __('Could not rebuild index for empty products array') ); } $this->doExecuteList($ids); } /** * @return array */ public function getIdentities() { return [ \Magento\Catalog\Model\Category::CACHE_TAG, \Magento\Catalog\Model\Product::CACHE_TAG, \Magento\Framework\App\Cache\Type\Block::CACHE_TAG ]; } /** * @param int $id */ abstract protected function doExecuteRow($id); /** * @param int[] $ids */ abstract protected function doExecuteList($ids); /** * @return IndexBuilder */ protected function getIndexBuilder() { return $this->indexBuilder; } /** * @return \Magento\Framework\Indexer\CacheContext */ protected function getCacheContext() { return $this->cacheContext; } }