public function testRemoveDeletedProducts() { $productsToDeleteIds = array(1, 2); $select = $this->getMock('\\Magento\\Framework\\Db\\Select', array(), array(), '', false); $select->expects($this->once())->method('from')->with('catalog_product_entity')->will($this->returnSelf()); $select->expects($this->once())->method('where')->with('entity_id IN(?)', $productsToDeleteIds)->will($this->returnSelf()); $products = array(array('entity_id' => 2)); $statement = $this->getMock('\\Zend_Db_Statement_Interface'); $statement->expects($this->once())->method('fetchAll')->will($this->returnValue($products)); $this->connection->expects($this->once())->method('query')->with($select)->will($this->returnValue($statement)); $this->connection->expects($this->once())->method('select')->will($this->returnValue($select)); $this->connection->expects($this->once())->method('delete')->with('store_1_flat', array('entity_id IN(?)' => array(1))); $this->model->removeDeletedProducts($productsToDeleteIds, 1); }
/** * Execute multiple rows reindex action * * @param array $ids * * @return \Magento\Catalog\Model\Indexer\Product\Flat\Action\Rows * @throws \Magento\Framework\Model\Exception */ public function execute($ids) { if (empty($ids)) { throw new \Magento\Framework\Model\Exception(__('Bad value was supplied.')); } foreach ($this->_storeManager->getStores() as $store) { $idsBatches = array_chunk($ids, \Magento\Catalog\Helper\Product\Flat\Indexer::BATCH_SIZE); foreach ($idsBatches as $changedIds) { $this->flatItemEraser->removeDeletedProducts($changedIds, $store->getId()); if (!empty($changedIds)) { $this->_reindex($store->getId(), $changedIds); } } } return $this; }
/** * Execute row reindex action * * @param int|null $id * @return \Magento\Catalog\Model\Indexer\Product\Flat\Action\Row * @throws \Magento\Framework\Model\Exception */ public function execute($id = null) { if (!isset($id) || empty($id)) { throw new \Magento\Framework\Model\Exception(__('Could not rebuild index for undefined product')); } $ids = array($id); foreach ($this->_storeManager->getStores() as $store) { $tableExists = $this->_isFlatTableExists($store->getId()); if ($tableExists) { $this->flatItemEraser->removeDeletedProducts($ids, $store->getId()); } if (isset($ids[0])) { if (!$tableExists) { $this->_flatTableBuilder->build($store->getId(), array($ids[0]), $this->_valueFieldSuffix, $this->_tableDropSuffix, false); } $this->flatItemWriter->write($store->getId(), $ids[0], $this->_valueFieldSuffix); } } return $this; }