Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractIndexer.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Framework\Mview\ActionInterface as MviewActionInterface;
9 use Magento\Framework\Indexer\ActionInterface as IndexerActionInterface;
12 
13 abstract class AbstractIndexer implements IndexerActionInterface, MviewActionInterface, IdentityInterface
14 {
18  protected $indexBuilder;
19 
25  protected $_eventManager;
26 
30  private $cacheManager;
31 
35  protected $cacheContext;
36 
41  public function __construct(
43  \Magento\Framework\Event\ManagerInterface $eventManager
44  ) {
45  $this->indexBuilder = $indexBuilder;
46  $this->_eventManager = $eventManager;
47  }
48 
55  public function execute($ids)
56  {
57  $this->executeList($ids);
58  }
59 
65  public function executeFull()
66  {
67  $this->indexBuilder->reindexFull();
68  $this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $this]);
69  //TODO: remove after fix fpc. MAGETWO-50668
70  $this->getCacheManager()->clean($this->getIdentities());
71  }
72 
79  public function getIdentities()
80  {
81  return [
85  ];
86  }
87 
95  public function executeList(array $ids)
96  {
97  if (!$ids) {
98  throw new \Magento\Framework\Exception\LocalizedException(
99  __('Could not rebuild index for empty products array')
100  );
101  }
102  $this->doExecuteList($ids);
103  }
104 
111  abstract protected function doExecuteList($ids);
112 
120  public function executeRow($id)
121  {
122  if (!$id) {
123  throw new \Magento\Framework\Exception\LocalizedException(
124  __('We can\'t rebuild the index for an undefined product.')
125  );
126  }
127  $this->doExecuteRow($id);
128  }
129 
137  abstract protected function doExecuteRow($id);
138 
144  private function getCacheManager()
145  {
146  if ($this->cacheManager === null) {
147  $this->cacheManager = \Magento\Framework\App\ObjectManager::getInstance()->get(
148  \Magento\Framework\App\CacheInterface::class
149  );
150  }
151  return $this->cacheManager;
152  }
153 
160  protected function getCacheContext()
161  {
162  if (!($this->cacheContext instanceof CacheContext)) {
163  return \Magento\Framework\App\ObjectManager::getInstance()->get(CacheContext::class);
164  } else {
165  return $this->cacheContext;
166  }
167  }
168 }
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13
__construct(IndexBuilder $indexBuilder, \Magento\Framework\Event\ManagerInterface $eventManager)