Exemplo n.º 1
0
 /**
  * Materialize view by IDs in changelog
  *
  * @return void
  * @throws \Exception
  */
 public function update()
 {
     if ($this->getState()->getMode() == View\StateInterface::MODE_ENABLED && $this->getState()->getStatus() == View\StateInterface::STATUS_IDLE) {
         $currentVersionId = $this->getChangelog()->getVersion();
         $lastVersionId = $this->getState()->getVersionId();
         $ids = $this->getChangelog()->getList($lastVersionId, $currentVersionId);
         if ($ids) {
             $action = $this->actionFactory->get($this->getActionClass());
             $this->getState()->setStatus(View\StateInterface::STATUS_WORKING)->save();
             try {
                 $action->execute($ids);
                 $this->getState()->loadByView($this->getId());
                 $statusToRestore = $this->getState()->getStatus() == View\StateInterface::STATUS_SUSPENDED ? View\StateInterface::STATUS_SUSPENDED : View\StateInterface::STATUS_IDLE;
                 $this->getState()->setVersionId($currentVersionId)->setStatus($statusToRestore)->save();
             } catch (\Exception $exception) {
                 $this->getState()->loadByView($this->getId());
                 $statusToRestore = $this->getState()->getStatus() == View\StateInterface::STATUS_SUSPENDED ? View\StateInterface::STATUS_SUSPENDED : View\StateInterface::STATUS_IDLE;
                 $this->getState()->setStatus($statusToRestore)->save();
                 throw $exception;
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Return indexer action instance
  *
  * @return ActionInterface
  */
 protected function getActionInstance()
 {
     return $this->actionFactory->get($this->getActionClass());
 }