Example #1
0
 /**
  * Reindex all data what this process responsible is
  *
  * @return void
  * @throws \Magento\Framework\Model\Exception
  * @throws \Exception
  */
 public function reindexAll()
 {
     if ($this->isLocked()) {
         throw new \Magento\Framework\Model\Exception(__('%1 Index process is not working now. Please try running this process later.', $this->getIndexer()->getName()));
     }
     $processStatus = $this->getStatus();
     $this->_getResource()->startProcess($this);
     $this->lock();
     try {
         $eventsCollection = $this->_eventRepository->getUnprocessed($this);
         if ($processStatus == self::STATUS_PENDING && $eventsCollection->getSize() > 0 || $this->getForcePartialReindex()) {
             $this->_getResource()->beginTransaction();
             try {
                 $this->_processEventsCollection($eventsCollection, false);
                 $this->_getResource()->commit();
             } catch (\Exception $e) {
                 $this->_getResource()->rollBack();
                 throw $e;
             }
         } else {
             //Update existing events since we'll do reindexAll
             $this->_resourceEvent->updateProcessEvents($this);
             $this->getIndexer()->reindexAll();
         }
         $this->unlock();
         if ($this->getMode() == self::MODE_MANUAL && $this->_eventRepository->hasUnprocessed($this)) {
             $this->_getResource()->updateStatus($this, self::STATUS_REQUIRE_REINDEX);
         } else {
             $this->_getResource()->endProcess($this);
         }
     } catch (\Exception $e) {
         $this->unlock();
         $this->_getResource()->failProcess($this);
         throw $e;
     }
     $this->_eventManager->dispatch('after_reindex_process_' . $this->getIndexerCode());
 }