/** * @param Action $subject * @param \Closure $proceed * @param array $productIds * @param array $attrData * @param int $storeId * @return Action * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundUpdateAttributes(Action $subject, \Closure $proceed, $productIds, $attrData, $storeId) { $returnValue = $proceed($productIds, $attrData, $storeId); $this->cacheContext->registerEntities(Product::CACHE_TAG, $productIds); $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]); return $returnValue; }
/** * test beforeExecute */ public function testBeforeExecute() { $expectedIds = [1, 2, 3]; $this->contextMock->expects($this->once())->method('registerEntities')->with($this->equalTo(\Magento\Catalog\Model\Product::ENTITY), $this->equalTo($expectedIds))->will($this->returnValue($this->contextMock)); $actualIds = $this->plugin->beforeExecute($this->subjectMock, $expectedIds); $this->assertEquals([$expectedIds], $actualIds); }
public function testDoExecuteList() { $ids = [1, 2, 5]; $this->indexBuilder->expects($this->once())->method('reindexFull'); $this->cacheContextMock->expects($this->once())->method('registerTags')->with([\Magento\Catalog\Model\Category::CACHE_TAG, \Magento\Catalog\Model\Product::CACHE_TAG, \Magento\Framework\App\Cache\Type\Block::CACHE_TAG]); $this->indexer->executeList($ids); }
/** * Clear cache after reindex all * * @param \Magento\Indexer\Model\Processor $subject * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterReindexAllInvalid(\Magento\Indexer\Model\Processor $subject) { $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->context]); if (!empty($this->context->getIdentities())) { $this->getCache()->clean($this->context->getIdentities()); } }
/** * Test afterUpdateMview * * @return void */ public function testAfterUpdateMview() { $tags = ['tag_name1', 'tag_name2']; $this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->equalTo('clean_cache_after_reindex'), $this->equalTo(['object' => $this->contextMock])); $this->contextMock->expects($this->atLeastOnce())->method('getIdentities')->willReturn($tags); $this->cacheMock->expects($this->once())->method('clean')->with($tags); $this->plugin->afterUpdateMview($this->subjectMock); }
public function testExecuteFull() { /** @var \Magento\Catalog\Model\Indexer\Category\Product\Action\Full $productIndexerFlatFull */ $productIndexerFlatFull = $this->getMock(\Magento\Catalog\Model\Indexer\Category\Product\Action\Full::class, [], [], '', false); $this->fullMock->expects($this->once())->method('create')->willReturn($productIndexerFlatFull); $productIndexerFlatFull->expects($this->once())->method('execute'); $this->cacheContextMock->expects($this->once())->method('registerTags')->with([\Magento\Catalog\Model\Category::CACHE_TAG]); $this->model->executeFull(); }
/** * test getIdentities */ public function testGetIdentities() { $expectedIdentities = ['product_1', 'product_2', 'product_3', 'category_5', 'category_6', 'category_7']; $productTag = 'product'; $categoryTag = 'category'; $productIds = [1, 2, 3]; $categoryIds = [5, 6, 7]; $this->context->registerEntities($productTag, $productIds); $this->context->registerEntities($categoryTag, $categoryIds); $actualIdentities = $this->context->getIdentities(); $this->assertEquals($expectedIdentities, $actualIdentities); }
/** * Refresh entities index * * @param array $productIds * @return array Affected ids */ protected function _reindexRows($productIds = []) { $connection = $this->_getConnection(); if (!is_array($productIds)) { $productIds = [$productIds]; } $parentIds = $this->getRelationsByChild($productIds); $processIds = $parentIds ? array_merge($parentIds, $productIds) : $productIds; // retrieve product types by processIds $select = $connection->select()->from($this->_getTable('catalog_product_entity'), ['entity_id', 'type_id'])->where('entity_id IN(?)', $processIds); $pairs = $connection->fetchPairs($select); $byType = []; foreach ($pairs as $productId => $typeId) { $byType[$typeId][$productId] = $productId; } $indexers = $this->_getTypeIndexers(); foreach ($indexers as $indexer) { if (isset($byType[$indexer->getTypeId()])) { $indexer->reindexEntity($byType[$indexer->getTypeId()]); } } $select = $connection->select()->distinct(true)->from($this->_getTable('catalog_category_product'), ['category_id'])->where('product_id IN(?)', $processIds); $affectedCategories = $connection->fetchCol($select); $this->cacheContext->registerEntities(Category::CACHE_TAG, $affectedCategories); $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]); return $this; }
public function testExecuteFull() { $this->productFlatIndexerFull->expects($this->any())->method('execute'); $this->cacheContextMock->expects($this->once())->method('registerTags')->with([\Magento\Catalog\Model\Category::CACHE_TAG, \Magento\Catalog\Model\Product::CACHE_TAG]); $this->model->executeFull(); }
/** * @param \Magento\Framework\Indexer\ActionInterface $subject * @param array $ids * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeExecute(\Magento\Framework\Indexer\ActionInterface $subject, $ids) { $this->context->registerEntities(\Magento\Catalog\Model\Category::CACHE_TAG, $ids); return [$ids]; }
/** * @param array $ids * @param array $idsForIndexer * @dataProvider dataProviderForExecuteList */ public function testDoExecuteList($ids, $idsForIndexer) { $this->indexBuilder->expects($this->once())->method('reindexByIds')->with($idsForIndexer); $this->cacheContextMock->expects($this->once())->method('registerEntities')->with(\Magento\Catalog\Model\Product::CACHE_TAG, $ids); $this->indexer->executeList($ids); }