Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Indexer Class Reference
Inheritance diagram for Indexer:
DataObject IndexerInterface

Public Member Functions

 __construct (ConfigInterface $config, ActionFactory $actionFactory, StructureFactory $structureFactory, \Magento\Framework\Mview\ViewInterface $view, Indexer\StateFactory $stateFactory, Indexer\CollectionFactory $indexersFactory, array $data=[])
 
 getId ()
 
 setId ($id)
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getViewId ()
 
 getActionClass ()
 
 getTitle ()
 
 getDescription ()
 
 getFields ()
 
 getSources ()
 
 getHandlers ()
 
 load ($indexerId)
 
 getView ()
 
 getState ()
 
 setState (StateInterface $state)
 
 isScheduled ()
 
 setScheduled ($scheduled)
 
 isValid ()
 
 isInvalid ()
 
 isWorking ()
 
 invalidate ()
 
 getStatus ()
 
 getLatestUpdated ()
 
 reindexAll ()
 
 reindexRow ($id)
 
 reindexList ($ids)
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Protected Member Functions

 getActionInstance ()
 
 getStructureInstance ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_idFieldName = 'indexer_id'
 
 $config
 
 $actionFactory
 
 $structureFactory
 
 $view
 
 $stateFactory
 
 $state
 
 $indexersFactory
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 19 of file Indexer.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ConfigInterface  $config,
ActionFactory  $actionFactory,
StructureFactory  $structureFactory,
\Magento\Framework\Mview\ViewInterface  $view,
Indexer\StateFactory  $stateFactory,
Indexer\CollectionFactory  $indexersFactory,
array  $data = [] 
)
Parameters
ConfigInterface$config
ActionFactory$actionFactory
StructureFactory$structureFactory
\Magento\Framework\Mview\ViewInterface$view
Indexer\StateFactory$stateFactory
Indexer\CollectionFactory$indexersFactory
array$data

Definition at line 70 of file Indexer.php.

78  {
79  $this->config = $config;
80  $this->actionFactory = $actionFactory;
81  $this->structureFactory = $structureFactory;
82  $this->view = $view;
83  $this->stateFactory = $stateFactory;
84  $this->indexersFactory = $indexersFactory;
85  parent::__construct($data);
86  }

Member Function Documentation

◆ getActionClass()

getActionClass ( )

Return indexer action class

Returns
string

Implements IndexerInterface.

Definition at line 155 of file Indexer.php.

156  {
157  return $this->getData('action_class');
158  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getActionInstance()

getActionInstance ( )
protected

Return indexer action instance

Returns
ActionInterface
Exceptions

Definition at line 373 of file Indexer.php.

374  {
375  return $this->actionFactory->create(
376  $this->getActionClass(),
377  [
378  'indexStructure' => $this->getStructureInstance(),
379  'data' => $this->getData(),
380  ]
381  );
382  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getDescription()

getDescription ( )

Return indexer description

Returns
string

Implements IndexerInterface.

Definition at line 175 of file Indexer.php.

176  {
177  return $this->getData('description');
178  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getFields()

getFields ( )

Return indexer fields

Returns
array

Implements IndexerInterface.

Definition at line 185 of file Indexer.php.

186  {
187  return $this->getData('fields');
188  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getHandlers()

getHandlers ( )

Return indexer handlers

Returns
array

Implements IndexerInterface.

Definition at line 205 of file Indexer.php.

206  {
207  return $this->getData('handlers');
208  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getId()

getId ( )

Return ID

@codeCoverageIgnore

Returns
string

Implements IndexerInterface.

Definition at line 95 of file Indexer.php.

96  {
97  return $this->getData($this->_idFieldName);
98  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getIdFieldName()

getIdFieldName ( )

Id field name getter

@codeCoverageIgnore

Returns
string

Definition at line 135 of file Indexer.php.

136  {
137  return $this->_idFieldName;
138  }

◆ getLatestUpdated()

getLatestUpdated ( )

Return indexer or mview latest updated time

Returns
string

Implements IndexerInterface.

Definition at line 352 of file Indexer.php.

353  {
354  if ($this->getView()->isEnabled() && $this->getView()->getUpdated()) {
355  if (!$this->getState()->getUpdated()) {
356  return $this->getView()->getUpdated();
357  }
358  $indexerUpdatedDate = new \DateTime($this->getState()->getUpdated());
359  $viewUpdatedDate = new \DateTime($this->getView()->getUpdated());
360  if ($viewUpdatedDate > $indexerUpdatedDate) {
361  return $this->getView()->getUpdated();
362  }
363  }
364  return $this->getState()->getUpdated();
365  }

◆ getSources()

getSources ( )

Return indexer sources

Returns
array

Implements IndexerInterface.

Definition at line 195 of file Indexer.php.

196  {
197  return $this->getData('sources');
198  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getState()

getState ( )

Return related state object

Returns
StateInterface

Implements IndexerInterface.

Definition at line 248 of file Indexer.php.

249  {
250  if (!$this->state) {
251  $this->state = $this->stateFactory->create();
252  $this->state->loadByIndexer($this->getId());
253  }
254  return $this->state;
255  }

◆ getStatus()

getStatus ( )

Return indexer status

Returns
string

Implements IndexerInterface.

Definition at line 342 of file Indexer.php.

343  {
344  return $this->getState()->getStatus();
345  }

◆ getStructureInstance()

getStructureInstance ( )
protected

Return indexer structure instance

Returns
IndexStructureInterface

Definition at line 389 of file Indexer.php.

390  {
391  if (!$this->getData('structure')) {
392  return null;
393  }
394  return $this->structureFactory->create($this->getData('structure'));
395  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getTitle()

getTitle ( )

Return indexer title

Returns
string

Implements IndexerInterface.

Definition at line 165 of file Indexer.php.

166  {
167  return $this->getData('title');
168  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getView()

getView ( )

Return related view object

Returns
\Magento\Framework\Mview\ViewInterface

Implements IndexerInterface.

Definition at line 235 of file Indexer.php.

236  {
237  if (!$this->view->getId()) {
238  $this->view->load($this->getViewId());
239  }
240  return $this->view;
241  }

◆ getViewId()

getViewId ( )

Return indexer's view ID

Returns
string

Implements IndexerInterface.

Definition at line 145 of file Indexer.php.

146  {
147  return $this->getData('view_id');
148  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ invalidate()

invalidate ( )

Set indexer invalid

Returns
void

Implements IndexerInterface.

Definition at line 330 of file Indexer.php.

◆ isInvalid()

isInvalid ( )

Check whether indexer is invalid

Returns
bool

Implements IndexerInterface.

Definition at line 310 of file Indexer.php.

311  {
312  return $this->getState()->getStatus() == StateInterface::STATUS_INVALID;
313  }

◆ isScheduled()

isScheduled ( )

Check whether indexer is run by schedule

Returns
bool

Implements IndexerInterface.

Definition at line 274 of file Indexer.php.

275  {
276  return $this->getView()->isEnabled();
277  }

◆ isValid()

isValid ( )

Check whether indexer is valid

Returns
bool

Implements IndexerInterface.

Definition at line 300 of file Indexer.php.

301  {
302  return $this->getState()->getStatus() == StateInterface::STATUS_VALID;
303  }

◆ isWorking()

isWorking ( )

Check whether indexer is working

Returns
bool

Implements IndexerInterface.

Definition at line 320 of file Indexer.php.

321  {
322  return $this->getState()->getStatus() == StateInterface::STATUS_WORKING;
323  }

◆ load()

load (   $indexerId)

Fill indexer data from config

Parameters
string$indexerId
Returns
IndexerInterface
Exceptions

Implements IndexerInterface.

Definition at line 217 of file Indexer.php.

218  {
219  $indexer = $this->config->getIndexer($indexerId);
220  if (empty($indexer) || empty($indexer['indexer_id']) || $indexer['indexer_id'] != $indexerId) {
221  throw new \InvalidArgumentException("{$indexerId} indexer does not exist.");
222  }
223 
224  $this->setId($indexerId);
225  $this->setData($indexer);
226 
227  return $this;
228  }
setData($key, $value=null)
Definition: DataObject.php:72

◆ reindexAll()

reindexAll ( )

Regenerate full index

Returns
void
Exceptions

Implements IndexerInterface.

Definition at line 403 of file Indexer.php.

404  {
406  $state = $this->getState();
408  $state->save();
409  if ($this->getView()->isEnabled()) {
410  $this->getView()->suspend();
411  }
412  try {
413  $this->getActionInstance()->executeFull();
415  $state->save();
416  $this->getView()->resume();
417  } catch (\Throwable $exception) {
419  $state->save();
420  $this->getView()->resume();
421  throw $exception;
422  }
423  }
424  }

◆ reindexList()

reindexList (   $ids)

Regenerate rows in index by ID list

Parameters
int[]$ids
Returns
void

Implements IndexerInterface.

Definition at line 444 of file Indexer.php.

445  {
446  $this->getActionInstance()->executeList($ids);
447  $this->getState()->save();
448  }

◆ reindexRow()

reindexRow (   $id)

Regenerate one row in index by ID

Parameters
int$id
Returns
void

Implements IndexerInterface.

Definition at line 432 of file Indexer.php.

433  {
434  $this->getActionInstance()->executeRow($id);
435  $this->getState()->save();
436  }
$id
Definition: fieldset.phtml:14

◆ setId()

setId (   $id)

Set ID

@codeCoverageIgnore

Parameters
string$id
Returns
$this

Definition at line 108 of file Indexer.php.

109  {
110  $this->setData($this->_idFieldName, $id);
111  return $this;
112  }
$id
Definition: fieldset.phtml:14
setData($key, $value=null)
Definition: DataObject.php:72

◆ setIdFieldName()

setIdFieldName (   $name)

Id field name setter

@codeCoverageIgnore

Parameters
string$name
Returns
$this

Definition at line 122 of file Indexer.php.

123  {
124  $this->_idFieldName = $name;
125  return $this;
126  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setScheduled()

setScheduled (   $scheduled)

Turn scheduled mode on/off

Parameters
bool$scheduled
Returns
void

Implements IndexerInterface.

Definition at line 285 of file Indexer.php.

286  {
287  if ($scheduled) {
288  $this->getView()->subscribe();
289  } else {
290  $this->getView()->unsubscribe();
291  }
292  $this->getState()->save();
293  }

◆ setState()

setState ( StateInterface  $state)

Set indexer state object

Parameters
StateInterface$state
Returns
IndexerInterface

Implements IndexerInterface.

Definition at line 263 of file Indexer.php.

264  {
265  $this->state = $state;
266  return $this;
267  }

Field Documentation

◆ $_idFieldName

$_idFieldName = 'indexer_id'
protected

Definition at line 24 of file Indexer.php.

◆ $actionFactory

$actionFactory
protected

Definition at line 34 of file Indexer.php.

◆ $config

$config
protected

Definition at line 29 of file Indexer.php.

◆ $indexersFactory

$indexersFactory
protected

Definition at line 59 of file Indexer.php.

◆ $state

$state
protected

Definition at line 54 of file Indexer.php.

◆ $stateFactory

$stateFactory
protected

Definition at line 49 of file Indexer.php.

◆ $structureFactory

$structureFactory
protected

Definition at line 39 of file Indexer.php.

◆ $view

$view
protected

Definition at line 44 of file Indexer.php.


The documentation for this class was generated from the following file: