Beispiel #1
0
 /**
  * @return array
  */
 protected function _getProcessesForReindex()
 {
     if ($this->_indexes === null) {
         $this->_indexes = array();
         $processes = $this->_indexer->getProcessesCollection()->addEventsStats();
         /** @var $process \Magento\Index\Model\Process */
         foreach ($processes as $process) {
             if (($process->getStatus() == \Magento\Index\Model\Process::STATUS_REQUIRE_REINDEX || $process->getEvents() > 0) && $process->getIndexer()->isVisible()) {
                 $this->_indexes[] = $process->getIndexer()->getName();
             }
         }
     }
     return $this->_indexes;
 }
Beispiel #2
0
 /**
  * Update websites for product action
  *
  * Allowed types:
  * - add
  * - remove
  *
  * @param array $productIds
  * @param array $websiteIds
  * @param string $type
  * @return void
  */
 public function updateWebsites($productIds, $websiteIds, $type)
 {
     if ($type == 'add') {
         $this->_productWebsiteFactory->create()->addProducts($websiteIds, $productIds);
     } else {
         if ($type == 'remove') {
             $this->_productWebsiteFactory->create()->removeProducts($websiteIds, $productIds);
         }
     }
     $this->setData(array('product_ids' => array_unique($productIds), 'website_ids' => $websiteIds, 'action_type' => $type));
     // register mass action indexer event
     $this->_indexIndexer->processEntityAction($this, \Magento\Catalog\Model\Product::ENTITY, \Magento\Index\Model\Event::TYPE_MASS_ACTION);
     if (!$this->getCategoryIndexer()->isScheduled()) {
         $this->getCategoryIndexer()->reindexList(array_unique($productIds));
     }
 }
Beispiel #3
0
 /**
  * Clean new data, unset data for done processes
  *
  * @return $this
  */
 public function cleanNewData()
 {
     $processIds = $this->getProcessIds();
     if (!is_array($processIds) || empty($processIds)) {
         return $this;
     }
     $newData = $this->getNewData(false);
     foreach ($processIds as $processId => $processStatus) {
         if ($processStatus == \Magento\Index\Model\Process::EVENT_STATUS_DONE) {
             $process = $this->_indexer->getProcessById($processId);
             if ($process) {
                 $namespace = get_class($process->getIndexer());
                 if (array_key_exists($namespace, $newData)) {
                     unset($newData[$namespace]);
                 }
             }
         }
     }
     $this->setNewData(serialize($newData));
     return $this;
 }
Beispiel #4
0
 /**
  * Parses string with indexers and return array of indexer instances
  *
  * @param string $string
  * @return array
  */
 protected function _parseIndexerString($string)
 {
     $processes = array();
     if ($string == 'all') {
         $collection = $this->_indexer->getProcessesCollection();
         foreach ($collection as $process) {
             $processes[] = $process;
         }
     } else {
         if (!empty($string)) {
             $codes = explode(',', $string);
             foreach ($codes as $code) {
                 $process = $this->_indexer->getProcessByCode(trim($code));
                 if (!$process) {
                     echo 'Warning: Unknown indexer with code ' . trim($code) . "\n";
                     $this->_hasErrors = true;
                 } else {
                     $processes[] = $process;
                 }
             }
         }
     }
     return $processes;
 }
Beispiel #5
0
 /**
  * Add reindexCallback
  *
  * @return \Magento\Catalog\Model\Category
  */
 protected function _afterSave()
 {
     $result = parent::_afterSave();
     $this->indexIndexer->processEntityAction($this, self::ENTITY, \Magento\Index\Model\Event::TYPE_SAVE);
     $this->_getResource()->addCommitCallback(array($this, 'reindex'));
     return $result;
 }
Beispiel #6
0
 /**
  * Run reindex process after data save
  *
  * @return $this
  */
 protected function _afterSave()
 {
     parent::_afterSave();
     $this->_indexer->processEntityAction($this, self::ENTITY, \Magento\Index\Model\Event::TYPE_SAVE);
     return $this;
 }
Beispiel #7
0
 /**
  * Init indexing process after product delete commit
  *
  * @return void
  */
 protected function _afterDeleteCommit()
 {
     $this->reindex();
     $this->_productPriceIndexerProcessor->reindexRow($this->getId());
     parent::_afterDeleteCommit();
     $this->_indexIndexer->indexEvents(self::ENTITY, \Magento\Index\Model\Event::TYPE_DELETE);
 }
Beispiel #8
0
 /**
  * Config data after commit observer.
  *
  * @param EventObserver $observer
  * @return void
  */
 public function processConfigDataSave(EventObserver $observer)
 {
     $configData = $observer->getEvent()->getConfigData();
     $this->_indexer->processEntityAction($configData, \Magento\Framework\App\Config\ValueInterface::ENTITY, \Magento\Index\Model\Event::TYPE_SAVE);
 }
Beispiel #9
0
 /**
  * Reindex all data what this process responsible is
  * Check and using depends processes
  *
  * @return $this|void
  */
 public function reindexEverything()
 {
     if ($this->getData('runed_reindexall')) {
         return $this;
     }
     $this->setForcePartialReindex($this->getStatus() == self::STATUS_PENDING && $this->_eventRepository->hasUnprocessed($this));
     if ($this->getDepends()) {
         foreach ($this->getDepends() as $code) {
             $process = $this->_indexer->getProcessByCode($code);
             if ($process) {
                 $process->reindexEverything();
             }
         }
     }
     $this->setData('runed_reindexall', true);
     return $this->reindexAll();
 }
Beispiel #10
0
 /**
  * Invalidate indexes by process codes.
  *
  * @return $this
  */
 public function invalidateIndex()
 {
     $relatedIndexers = $this->_importConfig->getRelatedIndexers($this->getEntity());
     if (empty($relatedIndexers)) {
         return $this;
     }
     foreach ($relatedIndexers as $indexer) {
         $indexProcess = $this->_indexer->getProcessByCode($indexer);
         if ($indexProcess) {
             $indexProcess->changeStatus(\Magento\Index\Model\Process::STATUS_REQUIRE_REINDEX);
         }
     }
     return $this;
 }