Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data.php
Go to the documentation of this file.
1 <?php
7 
10 
15 {
19  protected $stateCollection;
20 
30  public function __construct(
31  \Magento\Framework\Indexer\Config\Reader $reader,
32  \Magento\Framework\Config\CacheInterface $cache,
33  \Magento\Indexer\Model\ResourceModel\Indexer\State\Collection $stateCollection,
34  $cacheId = 'indexer_config',
35  SerializerInterface $serializer = null
36  ) {
37  $this->stateCollection = $stateCollection;
38 
39  $isCacheExists = $cache->test($cacheId);
40 
41  parent::__construct($reader, $cache, $cacheId, $serializer);
42 
43  if (!$isCacheExists) {
44  $this->deleteNonexistentStates();
45  }
46  }
47 
53  protected function deleteNonexistentStates()
54  {
55  foreach ($this->stateCollection->getItems() as $state) {
57  if (!isset($this->_data[$state->getIndexerId()])) {
58  $state->delete();
59  }
60  }
61  }
62 }
__construct(\Magento\Framework\Indexer\Config\Reader $reader, \Magento\Framework\Config\CacheInterface $cache, \Magento\Indexer\Model\ResourceModel\Indexer\State\Collection $stateCollection, $cacheId='indexer_config', SerializerInterface $serializer=null)
Definition: Data.php:30