Ejemplo 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();
         }
     }
 }
Ejemplo n.º 2
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\Indexer\Model\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;
 }