forked from magento/graphql-ce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2660 from magento-honey-badgers/MAGETWO-91437-Cat…
…egory-Product-Indexer [honey] MAGETWO-91437: Catalog_category_product_index table doesn't update after deleting category
- Loading branch information
Showing
8 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Model/Plugin/Category.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogSearch\Model\Indexer\Fulltext\Model\Plugin; | ||
|
||
use Magento\Catalog\Model\ResourceModel\Category as Resource; | ||
use Magento\CatalogSearch\Model\Indexer\Fulltext\Processor; | ||
|
||
/** | ||
* Perform indexer invalidation after a category delete. | ||
*/ | ||
class Category | ||
{ | ||
/** | ||
* @var Processor | ||
*/ | ||
private $fulltextIndexerProcessor; | ||
|
||
/** | ||
* @param Processor $fulltextIndexerProcessor | ||
*/ | ||
public function __construct(Processor $fulltextIndexerProcessor) | ||
{ | ||
$this->fulltextIndexerProcessor = $fulltextIndexerProcessor; | ||
} | ||
|
||
/** | ||
* Mark fulltext indexer as invalid post-deletion of category. | ||
* | ||
* @param Resource $subjectCategory | ||
* @param Resource $resultCategory | ||
* @return Resource | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterDelete(Resource $subjectCategory, Resource $resultCategory) : Resource | ||
{ | ||
$this->fulltextIndexerProcessor->markIndexerAsInvalid(); | ||
|
||
return $resultCategory; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Catalog\Model\ResourceModel\Category"> | ||
<plugin name="fulltext_search_indexer" type="Magento\CatalogSearch\Model\Indexer\Fulltext\Model\Plugin\Category"/> | ||
</type> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Catalog\Model\ResourceModel\Category"> | ||
<plugin name="fulltext_search_indexer" type="Magento\CatalogSearch\Model\Indexer\Fulltext\Model\Plugin\Category"/> | ||
</type> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...tion/testsuite/Magento/CatalogSearch/Model/Indexer/Fulltext/Model/Plugin/CategoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogSearch\Model\Indexer\Fulltext\Model\Plugin; | ||
|
||
use Magento\Catalog\Api\CategoryRepositoryInterface; | ||
use Magento\Catalog\Model\Category; | ||
use Magento\CatalogSearch\Model\Indexer\Fulltext\Processor; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
class CategoryTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var Processor | ||
*/ | ||
private $indexerProcessor; | ||
|
||
/** | ||
* @var CategoryRepositoryInterface | ||
*/ | ||
private $categoryRepository; | ||
|
||
protected function setUp() | ||
{ | ||
$this->indexerProcessor = Bootstrap::getObjectManager()->create(Processor::class); | ||
$this->categoryRepository = Bootstrap::getObjectManager()->create(CategoryRepositoryInterface::class); | ||
} | ||
|
||
/** | ||
* @magentoDataFixture Magento/Catalog/_files/indexer_catalog_category.php | ||
* @magentoAppArea adminhtml | ||
*/ | ||
public function testIndexerInvalidatedAfterCategoryDelete() | ||
{ | ||
$this->indexerProcessor->reindexAll(); | ||
$isIndexerValid = (bool)$this->indexerProcessor->getIndexer()->isValid(); | ||
|
||
$category = $this->getCategories(1); | ||
$this->categoryRepository->delete(array_pop($category)); | ||
|
||
$state = $this->indexerProcessor->getIndexer()->getState(); | ||
$state->loadByIndexer($this->indexerProcessor->getIndexerId()); | ||
$status = $state->getStatus(); | ||
|
||
$this->assertTrue($isIndexerValid); | ||
$this->assertEquals(\Magento\Framework\Indexer\StateInterface::STATUS_INVALID, $status); | ||
} | ||
|
||
/** | ||
* @param int $count | ||
* @return Category[] | ||
*/ | ||
private function getCategories($count) | ||
{ | ||
/** @var Category $category */ | ||
$category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( | ||
\Magento\Catalog\Model\Category::class | ||
); | ||
|
||
$result = $category->getCollection()->addAttributeToSelect('name')->getItems(); | ||
$result = array_slice($result, 2); | ||
|
||
return array_slice($result, 0, $count); | ||
} | ||
} |