Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Recurring.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Indexer\Setup;
8 
18 use Magento\Indexer\Model\Indexer\StateFactory;
19 use Magento\Indexer\Model\ResourceModel\Indexer\State\CollectionFactory;
20 
26 {
32  private $statesFactory;
33 
37  private $config;
38 
42  private $encryptor;
43 
47  private $encoder;
48 
52  private $stateFactory;
53 
63  public function __construct(
64  CollectionFactory $statesFactory,
65  StateFactory $stateFactory,
66  ConfigInterface $config,
67  EncryptorInterface $encryptor,
68  EncoderInterface $encoder
69  ) {
70  $this->statesFactory = $statesFactory;
71  $this->stateFactory = $stateFactory;
72  $this->config = $config;
73  $this->encryptor = $encryptor;
74  $this->encoder = $encoder;
75  }
76 
81  {
83  $stateIndexers = [];
84  $states = $this->statesFactory->create();
85  foreach ($states->getItems() as $state) {
87  $stateIndexers[$state->getIndexerId()] = $state;
88  }
89 
90  foreach ($this->config->getIndexers() as $indexerId => $indexerConfig) {
91  $expectedHashConfig = $this->encryptor->hash(
92  $this->encoder->encode($indexerConfig),
94  );
95 
96  if (isset($stateIndexers[$indexerId])) {
97  if ($stateIndexers[$indexerId]->getHashConfig() != $expectedHashConfig) {
98  $stateIndexers[$indexerId]->setStatus(StateInterface::STATUS_INVALID);
99  $stateIndexers[$indexerId]->setHashConfig($expectedHashConfig);
100  $stateIndexers[$indexerId]->save();
101  }
102  } else {
104  $state = $this->stateFactory->create();
105  $state->loadByIndexer($indexerId);
106  $state->setHashConfig($expectedHashConfig);
107  $state->setStatus(StateInterface::STATUS_INVALID);
108  $state->save();
109  }
110  }
111  }
112 }
$config
Definition: fraud_order.php:17
install(SchemaSetupInterface $setup, ModuleContextInterface $context)
$setup
Definition: trigger.php:12
__construct(CollectionFactory $statesFactory, StateFactory $stateFactory, ConfigInterface $config, EncryptorInterface $encryptor, EncoderInterface $encoder)
Definition: Recurring.php:63