示例#1
0
文件: Grid.php 项目: aiesh/magento2
 /**
  * Add name and description to collection elements
  *
  * @return $this
  */
 protected function _afterLoadCollection()
 {
     /** @var $item \Magento\Index\Model\Process */
     foreach ($this->_collection as $key => $item) {
         if (!$item->getIndexer()->isVisible()) {
             $this->_collection->removeItemByKey($key);
             continue;
         }
         $item->setName($item->getIndexer()->getName());
         $item->setDescription($item->getIndexer()->getDescription());
         $item->setUpdateRequired($this->_eventRepository->hasUnprocessed($item) ? 1 : 0);
         if ($item->isLocked()) {
             $item->setStatus(\Magento\Index\Model\Process::STATUS_RUNNING);
         }
     }
     return $this;
 }
示例#2
0
 public function testGetUnprocessedReturnsConfiguredCollectionOfEvents()
 {
     $process = $this->getMock('Magento\\Index\\Model\\Process', array(), array(), '', false);
     $this->_eventCollection->expects($this->once())->method('addProcessFilter')->with($process, \Magento\Index\Model\Process::EVENT_STATUS_NEW);
     $this->assertEquals($this->_eventCollection, $this->_model->getUnprocessed($process));
 }
示例#3
0
 /**
  * Index pending events addressed to the process
  *
  * @param   null|string $entity
  * @param   null|string $type
  * @return  $this
  * @throws \Exception
  */
 public function indexEvents($entity = null, $type = null)
 {
     /**
      * Check if process indexer can match entity code and action type
      */
     if ($entity !== null && $type !== null) {
         if (!$this->getIndexer()->matchEntityAndType($entity, $type)) {
             return $this;
         }
     }
     if ($this->getMode() == self::MODE_MANUAL) {
         return $this;
     }
     if ($this->isLocked()) {
         return $this;
     }
     $this->lock();
     try {
         /**
          * Prepare events collection
          */
         $eventsCollection = $this->_eventRepository->getUnprocessed($this);
         if ($entity !== null) {
             $eventsCollection->addEntityFilter($entity);
         }
         if ($type !== null) {
             $eventsCollection->addTypeFilter($type);
         }
         $this->_processEventsCollection($eventsCollection);
         $this->unlock();
     } catch (\Exception $e) {
         $this->unlock();
         throw $e;
     }
     return $this;
 }