public function testExecuteWithIndex()
 {
     $this->configMock->expects($this->any())->method('getIndexer')->will($this->returnValueMap([['id_indexerOne', ['title' => 'Title_indexerOne', 'shared_index' => null]], ['id_indexerTwo', ['title' => 'Title_indexerTwo', 'shared_index' => 'with_indexer_3']], ['id_indexer3', ['title' => 'Title_indexer3', 'shared_index' => 'with_indexer_3']]]));
     $this->configureAdminArea();
     $indexerOne = $this->getMock('Magento\\Indexer\\Model\\Indexer', [], [], '', false);
     $indexerOne->expects($this->once())->method('reindexAll');
     $indexerOne->expects($this->once())->method('getTitle')->willReturn('Title_indexerOne');
     $indexerOne->expects($this->any())->method('getId')->willReturn('id_indexerOne');
     $indexerOne->expects($this->once())->method('load')->with('id_indexerOne')->willReturn($indexerOne);
     $indexerTwo = $this->getMock('Magento\\Indexer\\Model\\Indexer', [], [], '', false);
     $indexerTwo->expects($this->once())->method('reindexAll');
     $indexerTwo->expects($this->once())->method('getTitle')->willReturn('Title_indexerTwo');
     $indexerTwo->expects($this->any())->method('getId')->willReturn('id_indexerTwo');
     $indexerTwo->expects($this->once())->method('load')->with('id_indexerTwo')->willReturn($indexerTwo);
     $indexer3 = $this->getMock('Magento\\Indexer\\Model\\Indexer', [], [], '', false);
     $indexer3->expects($this->never())->method('reindexAll');
     $indexer3->expects($this->once())->method('getTitle')->willReturn('Title_indexer3');
     $indexer3->expects($this->any())->method('getId')->willReturn('id_indexer3');
     $indexer3->expects($this->once())->method('load')->with('id_indexer3')->willReturn($indexer3);
     $stateMock = $this->getMock(\Magento\Indexer\Model\Indexer\State::class, [], [], '', false);
     $stateMock->expects($this->once())->method('setStatus')->will($this->returnSelf());
     $stateMock->expects($this->once())->method('save');
     $indexer3->expects($this->once())->method('getState')->willReturn($stateMock);
     $this->collectionFactory->expects($this->never())->method('create');
     $this->indexerFactory->expects($this->at(0))->method('create')->willReturn($indexerOne);
     $this->indexerFactory->expects($this->at(1))->method('create')->willReturn($indexerTwo);
     $this->indexerFactory->expects($this->at(2))->method('create')->willReturn($indexer3);
     $this->command = new IndexerReindexCommand($this->objectManagerFactory);
     $commandTester = new CommandTester($this->command);
     $commandTester->execute(['index' => ['id_indexerOne', 'id_indexerTwo', 'id_indexer3']]);
     $actualValue = $commandTester->getDisplay();
     $this->assertStringStartsWith('Title_indexerOne index has been rebuilt successfully in', $actualValue);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
 {
     /** @var State[] $stateIndexers */
     $stateIndexers = [];
     $states = $this->statesFactory->create();
     foreach ($states->getItems() as $state) {
         /** @var State $state */
         $stateIndexers[$state->getIndexerId()] = $state;
     }
     foreach ($this->config->getIndexers() as $indexerId => $indexerConfig) {
         $expectedHashConfig = $this->encryptor->hash($this->encoder->encode($indexerConfig), Encryptor::HASH_VERSION_MD5);
         if (isset($stateIndexers[$indexerId])) {
             if ($stateIndexers[$indexerId]->getHashConfig() != $expectedHashConfig) {
                 $stateIndexers[$indexerId]->setStatus(StateInterface::STATUS_INVALID);
                 $stateIndexers[$indexerId]->setHashConfig($expectedHashConfig);
                 $stateIndexers[$indexerId]->save();
             }
         } else {
             /** @var State $state */
             $state = $this->stateFactory->create();
             $state->loadByIndexer($indexerId);
             $state->setHashConfig($expectedHashConfig);
             $state->setStatus(StateInterface::STATUS_INVALID);
             $state->save();
         }
     }
 }
Esempio n. 3
0
 /**
  * @param \Magento\Store\Model\Store $store
  * @return void
  */
 private function clearIndex(\Magento\Store\Model\Store $store)
 {
     $dimensions = [$this->dimensionFactory->create(['name' => 'scope', 'value' => $store->getId()])];
     $configData = $this->indexerConfig->getIndexer(FulltextIndexer::INDEXER_ID);
     /** @var \Magento\CatalogSearch\Model\Indexer\IndexerHandler $indexHandler */
     $indexHandler = $this->indexerHandlerFactory->create(['data' => $configData]);
     $indexHandler->cleanIndex($dimensions);
 }
Esempio n. 4
0
 /**
  * Regenerate indexes for all invalid indexers
  *
  * @return void
  */
 public function reindexAllInvalid()
 {
     foreach (array_keys($this->config->getIndexers()) as $indexerId) {
         $indexer = $this->indexerFactory->create();
         $indexer->load($indexerId);
         if ($indexer->isInvalid()) {
             $indexer->reindexAll();
         }
     }
 }
 public function testReindexAllInvalid()
 {
     $indexers = ['indexer1' => [], 'indexer2' => []];
     $this->configMock->expects($this->once())->method('getIndexers')->will($this->returnValue($indexers));
     $state1Mock = $this->getMock('Magento\\Indexer\\Model\\Indexer\\State', ['getStatus', '__wakeup'], [], '', false);
     $state1Mock->expects($this->once())->method('getStatus')->will($this->returnValue(StateInterface::STATUS_INVALID));
     $indexer1Mock = $this->getMock('Magento\\Indexer\\Model\\Indexer', ['load', 'getState', 'reindexAll'], [], '', false);
     $indexer1Mock->expects($this->once())->method('getState')->will($this->returnValue($state1Mock));
     $indexer1Mock->expects($this->once())->method('reindexAll');
     $state2Mock = $this->getMock('Magento\\Indexer\\Model\\Indexer\\State', ['getStatus', '__wakeup'], [], '', false);
     $state2Mock->expects($this->once())->method('getStatus')->will($this->returnValue(StateInterface::STATUS_VALID));
     $indexer2Mock = $this->getMock('Magento\\Indexer\\Model\\Indexer', ['load', 'getState', 'reindexAll'], [], '', false);
     $indexer2Mock->expects($this->never())->method('reindexAll');
     $indexer2Mock->expects($this->once())->method('getState')->will($this->returnValue($state2Mock));
     $this->indexerFactoryMock->expects($this->at(0))->method('create')->will($this->returnValue($indexer1Mock));
     $this->indexerFactoryMock->expects($this->at(1))->method('create')->will($this->returnValue($indexer2Mock));
     $this->model->reindexAllInvalid();
 }
Esempio n. 6
0
 /**
  * Fill indexer data from config
  *
  * @param string $indexerId
  * @return IdxInterface
  * @throws \InvalidArgumentException
  */
 public function load($indexerId)
 {
     $indexer = $this->config->getIndexer($indexerId);
     if (empty($indexer) || empty($indexer['indexer_id']) || $indexer['indexer_id'] != $indexerId) {
         throw new \InvalidArgumentException("{$indexerId} indexer does not exist.");
     }
     $this->setId($indexerId);
     $this->setData($indexer);
     return $this;
 }
Esempio n. 7
0
 /**
  * Load data
  *
  * @param bool $printQuery
  * @param bool $logQuery
  * @return \Magento\Indexer\Model\Indexer\Collection
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function loadData($printQuery = false, $logQuery = false)
 {
     if (!$this->isLoaded()) {
         $states = $this->statesFactory->create();
         foreach (array_keys($this->config->getIndexers()) as $indexerId) {
             /** @var \Magento\Framework\Indexer\IndexerInterface $indexer */
             $indexer = $this->getNewEmptyItem();
             $indexer->load($indexerId);
             foreach ($states->getItems() as $state) {
                 /** @var \Magento\Indexer\Model\Indexer\State $state */
                 if ($state->getIndexerId() == $indexerId) {
                     $indexer->setState($state);
                     break;
                 }
             }
             $this->_addItem($indexer);
         }
         $this->_setIsLoaded(true);
     }
     return $this;
 }
Esempio n. 8
0
 /**
  * Regenerate indexes for all invalid indexers
  *
  * @return void
  */
 public function reindexAllInvalid()
 {
     $sharedIndexesComplete = [];
     foreach (array_keys($this->config->getIndexers()) as $indexerId) {
         /** @var Indexer $indexer */
         $indexer = $this->indexerFactory->create();
         $indexer->load($indexerId);
         $indexerConfig = $this->config->getIndexer($indexerId);
         if ($indexer->isInvalid()) {
             // Skip indexers having shared index that was already complete
             if (!in_array($indexerConfig['shared_index'], $sharedIndexesComplete)) {
                 $indexer->reindexAll();
             } else {
                 /** @var \Magento\Indexer\Model\Indexer\State $state */
                 $state = $indexer->getState();
                 $state->setStatus(StateInterface::STATUS_VALID);
                 $state->save();
             }
             if ($indexerConfig['shared_index']) {
                 $sharedIndexesComplete[] = $indexerConfig['shared_index'];
             }
         }
     }
 }
 /**
  * @param $indexId
  */
 protected function loadIndexer($indexId)
 {
     $this->configMock->expects($this->once())->method('getIndexer')->with($indexId)->will($this->returnValue($this->getIndexerData()));
     $this->model->load($indexId);
 }
Esempio n. 10
0
 /**
  * @param ResourceConnection $resource
  * @param \Magento\Catalog\Model\Product\Type $catalogProductType
  * @param \Magento\Eav\Model\Config $eavConfig
  * @param \Magento\Framework\Search\Request\Config $searchRequestConfig
  * @param \Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus
  * @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $prodAttributeCollectionFactory
  * @param \Magento\CatalogSearch\Model\ResourceModel\EngineProvider $engineProvider
  * @param \Magento\CatalogSearch\Model\Indexer\IndexerHandlerFactory $indexHandlerFactory
  * @param \Magento\Framework\Event\ManagerInterface $eventManager
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Framework\Stdlib\DateTime $dateTime
  * @param \Magento\Framework\Locale\ResolverInterface $localeResolver
  * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  * @param \Magento\CatalogSearch\Model\ResourceModel\Fulltext $fulltextResource
  * @param \Magento\Framework\Search\Request\DimensionFactory $dimensionFactory
  * @param \Magento\Framework\Indexer\ConfigInterface $indexerConfig
  * @param \Magento\CatalogSearch\Model\Indexer\Fulltext\Action\IndexIteratorFactory $indexIteratorFactory
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(ResourceConnection $resource, \Magento\Catalog\Model\Product\Type $catalogProductType, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\Search\Request\Config $searchRequestConfig, \Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus, \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $prodAttributeCollectionFactory, \Magento\CatalogSearch\Model\ResourceModel\EngineProvider $engineProvider, \Magento\CatalogSearch\Model\Indexer\IndexerHandlerFactory $indexHandlerFactory, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Stdlib\DateTime $dateTime, \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\CatalogSearch\Model\ResourceModel\Fulltext $fulltextResource, \Magento\Framework\Search\Request\DimensionFactory $dimensionFactory, \Magento\Framework\Indexer\ConfigInterface $indexerConfig, \Magento\CatalogSearch\Model\Indexer\Fulltext\Action\IndexIteratorFactory $indexIteratorFactory)
 {
     $this->resource = $resource;
     $this->connection = $resource->getConnection();
     $this->catalogProductType = $catalogProductType;
     $this->eavConfig = $eavConfig;
     $this->searchRequestConfig = $searchRequestConfig;
     $this->catalogProductStatus = $catalogProductStatus;
     $this->productAttributeCollectionFactory = $prodAttributeCollectionFactory;
     $this->eventManager = $eventManager;
     $this->scopeConfig = $scopeConfig;
     $this->storeManager = $storeManager;
     $this->engine = $engineProvider->get();
     $configData = $indexerConfig->getIndexer(Fulltext::INDEXER_ID);
     $this->indexHandler = $indexHandlerFactory->create(['data' => $configData]);
     $this->dateTime = $dateTime;
     $this->localeResolver = $localeResolver;
     $this->localeDate = $localeDate;
     $this->fulltextResource = $fulltextResource;
     $this->dimensionFactory = $dimensionFactory;
     $this->iteratorFactory = $indexIteratorFactory;
 }