Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data Structures | Public Member Functions | Data Fields | Protected Attributes
View Class Reference
Inheritance diagram for View:
DataObject ViewInterface

Data Structures

class  ChangelogTest
 

Public Member Functions

 __construct (ConfigInterface $config, ActionFactory $actionFactory, View\StateInterface $state, View\ChangelogInterface $changelog, SubscriptionFactory $subscriptionFactory, array $data=[], array $changelogBatchSize=[])
 
 getId ()
 
 setId ($id)
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getActionClass ()
 
 getGroup ()
 
 getSubscriptions ()
 
 load ($viewId)
 
 update ()
 
 suspend ()
 
 resume ()
 
 clearChangelog ()
 
 getState ()
 
 setState (View\StateInterface $state)
 
 isEnabled ()
 
 isIdle ()
 
 isWorking ()
 
 isSuspended ()
 
 getUpdated ()
 
 getChangelog ()
 
- 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)
 
- Public Member Functions inherited from ViewInterface
 subscribe ()
 
 unsubscribe ()
 

Data Fields

const DEFAULT_BATCH_SIZE = 1000
 

Protected Attributes

 $_idFieldName = 'view_id'
 
 $config
 
 $actionFactory
 
 $changelog
 
 $subscriptionFactory
 
 $state
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 15 of file View.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ConfigInterface  $config,
ActionFactory  $actionFactory,
View\StateInterface  $state,
View\ChangelogInterface  $changelog,
SubscriptionFactory  $subscriptionFactory,
array  $data = [],
array  $changelogBatchSize = [] 
)
Parameters
ConfigInterface$config
ActionFactory$actionFactory
View\StateInterface$state
View\ChangelogInterface$changelog
SubscriptionFactory$subscriptionFactory
array$data
array$changelogBatchSize

Definition at line 71 of file View.php.

79  {
80  $this->config = $config;
81  $this->actionFactory = $actionFactory;
82  $this->state = $state;
83  $this->changelog = $changelog;
84  $this->subscriptionFactory = $subscriptionFactory;
85  $this->changelogBatchSize = $changelogBatchSize;
86  parent::__construct($data);
87  }

Member Function Documentation

◆ clearChangelog()

clearChangelog ( )

Clear precessed changelog entries

Returns
void

Implements ViewInterface.

Definition at line 346 of file View.php.

347  {
348  if ($this->getState()->getMode() == View\StateInterface::MODE_ENABLED) {
349  $this->getChangelog()->clear($this->getState()->getVersionId());
350  }
351  }

◆ getActionClass()

getActionClass ( )

Return view action class

Returns
string

Implements ViewInterface.

Definition at line 138 of file View.php.

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

◆ getChangelog()

getChangelog ( )

Retrieve linked changelog

Returns
View\ChangelogInterface

Implements ViewInterface.

Definition at line 433 of file View.php.

434  {
435  if (!$this->changelog->getViewId()) {
436  $this->changelog->setViewId($this->getId());
437  }
438  return $this->changelog;
439  }

◆ getGroup()

getGroup ( )

Return view group

Returns
string

Implements ViewInterface.

Definition at line 148 of file View.php.

149  {
150  return $this->getData('group');
151  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getId()

getId ( )

Return ID

Returns
string

Implements ViewInterface.

Definition at line 94 of file View.php.

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

◆ getIdFieldName()

getIdFieldName ( )

Id field name getter

Returns
string

Definition at line 128 of file View.php.

129  {
130  return $this->_idFieldName;
131  }

◆ getState()

getState ( )

Return related state object

Returns
View\StateInterface

Implements ViewInterface.

Definition at line 358 of file View.php.

359  {
360  if (!$this->state->getViewId()) {
361  $this->state->loadByView($this->getId());
362  }
363  return $this->state;
364  }

◆ getSubscriptions()

getSubscriptions ( )

Return view subscriptions

Returns
array

Implements ViewInterface.

Definition at line 158 of file View.php.

159  {
160  return $this->getData('subscriptions');
161  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getUpdated()

getUpdated ( )

Return view updated datetime

Returns
string

Implements ViewInterface.

Definition at line 423 of file View.php.

424  {
425  return $this->getState()->getUpdated();
426  }

◆ isEnabled()

isEnabled ( )

Check whether view is enabled

Returns
bool

Implements ViewInterface.

Definition at line 383 of file View.php.

◆ isIdle()

isIdle ( )

Check whether view is idle

Returns
bool

Implements ViewInterface.

Definition at line 393 of file View.php.

394  {
395  return $this->getState()->getStatus() == \Magento\Framework\Mview\View\StateInterface::STATUS_IDLE;
396  }

◆ isSuspended()

isSuspended ( )

Check whether view is suspended

Returns
bool

Implements ViewInterface.

Definition at line 413 of file View.php.

414  {
415  return $this->getState()->getStatus() == \Magento\Framework\Mview\View\StateInterface::STATUS_SUSPENDED;
416  }

◆ isWorking()

isWorking ( )

Check whether view is working

Returns
bool

Implements ViewInterface.

Definition at line 403 of file View.php.

404  {
405  return $this->getState()->getStatus() == \Magento\Framework\Mview\View\StateInterface::STATUS_WORKING;
406  }

◆ load()

load (   $viewId)

Fill view data from config

Parameters
string$viewId
Returns
ViewInterface
Exceptions

Implements ViewInterface.

Definition at line 170 of file View.php.

171  {
172  $view = $this->config->getView($viewId);
173  if (empty($view) || empty($view['view_id']) || $view['view_id'] != $viewId) {
174  throw new \InvalidArgumentException("{$viewId} view does not exist.");
175  }
176 
177  $this->setId($viewId);
178  $this->setData($view);
179 
180  return $this;
181  }
setData($key, $value=null)
Definition: DataObject.php:72

◆ resume()

resume ( )

Resume view updates

Returns
void

Implements ViewInterface.

Definition at line 332 of file View.php.

◆ setId()

setId (   $id)

Set ID

Parameters
string$id
Returns
$this

Definition at line 105 of file View.php.

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

◆ setIdFieldName()

setIdFieldName (   $name)

Id field name setter

Parameters
string$name
Returns
$this

Definition at line 117 of file View.php.

118  {
119  $this->_idFieldName = $name;
120  return $this;
121  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setState()

setState ( View\StateInterface  $state)

Set view state object

Parameters
View\StateInterface$state
Returns
ViewInterface

Implements ViewInterface.

Definition at line 372 of file View.php.

373  {
374  $this->state = $state;
375  return $this;
376  }

◆ suspend()

suspend ( )

Suspend view updates and set version ID to changelog's end

Returns
void

Implements ViewInterface.

Definition at line 317 of file View.php.

318  {
319  if ($this->getState()->getMode() == View\StateInterface::MODE_ENABLED) {
320  $state = $this->getState();
321  $state->setVersionId($this->getChangelog()->getVersion());
322  $state->setStatus(View\StateInterface::STATUS_SUSPENDED);
323  $state->save();
324  }
325  }

◆ update()

update ( )

Materialize view by IDs in changelog

Returns
void
Exceptions

Implements ViewInterface.

Definition at line 264 of file View.php.

265  {
266  if ($this->getState()->getStatus() == View\StateInterface::STATUS_IDLE) {
267  try {
268  $currentVersionId = $this->getChangelog()->getVersion();
269  } catch (ChangelogTableNotExistsException $e) {
270  return;
271  }
272  $lastVersionId = (int) $this->getState()->getVersionId();
273  $action = $this->actionFactory->get($this->getActionClass());
274 
275  try {
276  $this->getState()->setStatus(View\StateInterface::STATUS_WORKING)->save();
277 
278  $versionBatchSize = self::$maxVersionQueryBatch;
279  $batchSize = isset($this->changelogBatchSize[$this->getChangelog()->getViewId()])
280  ? $this->changelogBatchSize[$this->getChangelog()->getViewId()]
282 
283  for ($vsFrom = $lastVersionId; $vsFrom < $currentVersionId; $vsFrom += $versionBatchSize) {
284  // Don't go past the current version for atomicy.
285  $versionTo = min($currentVersionId, $vsFrom + $versionBatchSize);
286  $ids = $this->getChangelog()->getList($vsFrom, $versionTo);
287 
288  // We run the actual indexer in batches.
289  // Chunked AFTER loading to avoid duplicates in separate chunks.
290  $chunks = array_chunk($ids, $batchSize);
291  foreach ($chunks as $ids) {
292  $action->execute($ids);
293  }
294  }
295 
296  $this->getState()->loadByView($this->getId());
297  $statusToRestore = $this->getState()->getStatus() == View\StateInterface::STATUS_SUSPENDED
300  $this->getState()->setVersionId($currentVersionId)->setStatus($statusToRestore)->save();
301  } catch (\Exception $exception) {
302  $this->getState()->loadByView($this->getId());
303  $statusToRestore = $this->getState()->getStatus() == View\StateInterface::STATUS_SUSPENDED
306  $this->getState()->setStatus($statusToRestore)->save();
307  throw $exception;
308  }
309  }
310  }

Field Documentation

◆ $_idFieldName

$_idFieldName = 'view_id'
protected

Definition at line 30 of file View.php.

◆ $actionFactory

$actionFactory
protected

Definition at line 40 of file View.php.

◆ $changelog

$changelog
protected

Definition at line 45 of file View.php.

◆ $config

$config
protected

Definition at line 35 of file View.php.

◆ $state

$state
protected

Definition at line 55 of file View.php.

◆ $subscriptionFactory

$subscriptionFactory
protected

Definition at line 50 of file View.php.

◆ DEFAULT_BATCH_SIZE

const DEFAULT_BATCH_SIZE = 1000

Default batch size for partial reindex

Definition at line 20 of file View.php.


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