Esempio n. 1
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(State::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(State::STATUS_INVALID);
             $state->save();
         }
     }
 }
Esempio n. 2
0
 /**
  * Return related state object
  *
  * @return Indexer\State
  */
 public function getState()
 {
     if (!$this->state) {
         $this->state = $this->stateFactory->create();
         $this->state->loadByIndexer($this->getId());
     }
     return $this->state;
 }
 public function testReindexList()
 {
     $ids = [1];
     $stateMock = $this->getMock('\\Magento\\Indexer\\Model\\Indexer\\State', ['load', 'save'], [], '', false);
     $actionMock = $this->getMock('Magento\\Framework\\Indexer\\ActionInterface', ['executeFull', 'executeList', 'executeRow'], [], '', false);
     $this->actionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($actionMock));
     $this->stateFactoryMock->expects($this->once())->method('create')->will($this->returnValue($stateMock));
     $stateMock->expects($this->once())->method('save')->will($this->returnSelf());
     $actionMock->expects($this->once())->method('executeList')->with($ids)->will($this->returnSelf());
     $this->model->reindexList($ids);
 }
Esempio n. 4
0
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Test exception
  */
 public function testReindexAllWithException()
 {
     $indexId = 'indexer_internal_name';
     $this->loadIndexer($indexId);
     $stateMock = $this->getMock('\\Magento\\Indexer\\Model\\Indexer\\State', ['load', 'getId', 'setIndexerId', '__wakeup', 'getStatus', 'setStatus', 'save'], [], '', false);
     $stateMock->expects($this->once())->method('load')->with($indexId, 'indexer_id')->will($this->returnSelf());
     $stateMock->expects($this->never())->method('setIndexerId');
     $stateMock->expects($this->once())->method('getId')->will($this->returnValue(1));
     $stateMock->expects($this->exactly(2))->method('setStatus')->will($this->returnSelf());
     $stateMock->expects($this->once())->method('getStatus')->will($this->returnValue('idle'));
     $stateMock->expects($this->exactly(2))->method('save')->will($this->returnSelf());
     $this->stateFactoryMock->expects($this->once())->method('create')->will($this->returnValue($stateMock));
     $this->viewMock->expects($this->once())->method('isEnabled')->will($this->returnValue(false));
     $this->viewMock->expects($this->never())->method('suspend');
     $this->viewMock->expects($this->once())->method('resume');
     $actionMock = $this->getMock('Magento\\Indexer\\Model\\ActionInterface', ['executeFull', 'executeList', 'executeRow'], [], '', false);
     $actionMock->expects($this->once())->method('executeFull')->will($this->returnCallback(function () {
         throw new \Exception('Test exception');
     }));
     $this->actionFactoryMock->expects($this->once())->method('get')->with('Some\\Class\\Name')->will($this->returnValue($actionMock));
     $this->model->reindexAll();
 }