-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 #2696 from magento-tsg/2.3-develop-pr23
[TSG] Upporting for 2.3 (pr23) (2.3.0)
- Loading branch information
Showing
62 changed files
with
1,891 additions
and
371 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
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
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
85 changes: 85 additions & 0 deletions
85
app/code/Magento/Elasticsearch/Model/Indexer/Plugin/DependencyUpdaterPlugin.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,85 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Elasticsearch\Model\Indexer\Plugin; | ||
|
||
use Magento\Elasticsearch\Model\Config; | ||
use Magento\Framework\Indexer\Config\DependencyInfoProvider as Provider; | ||
use Magento\CatalogSearch\Model\Indexer\Fulltext as CatalogSearchFulltextIndexer; | ||
use Magento\CatalogInventory\Model\Indexer\Stock\Processor as CatalogInventoryStockIndexer; | ||
|
||
/** | ||
* Plugin for maintenance catalog search index dependency on stock index. | ||
* If elasticsearch is used as search engine catalog search index becomes dependent on stock index. Elasticsearch | ||
* module declares this dependence. But in case when elasticsearch module is enabled and elasticsearch engine isn`t | ||
* used as search engine other search engines don`t need this dependency. | ||
* This plugin remove catalog search index dependency on stock index when elasticsearch isn`t used as search engine | ||
* except full reindexing. During full reindexing this dependency doesn`t make overhead. | ||
*/ | ||
class DependencyUpdaterPlugin | ||
{ | ||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @param Config $config | ||
*/ | ||
public function __construct(Config $config) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* Remove index dependency, if it needed, on run reindexing by specifics indexes. | ||
* | ||
* @param Provider $provider | ||
* @param array $dependencies | ||
* @param string $indexerId | ||
* @return array | ||
* @see \Magento\Indexer\Console\Command\IndexerReindexCommand::getIndexers() | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterGetIndexerIdsToRunBefore(Provider $provider, array $dependencies, string $indexerId): array | ||
{ | ||
if ($this->isFilteringNeeded($indexerId, CatalogSearchFulltextIndexer::INDEXER_ID)) { | ||
$dependencies = array_diff($dependencies, [CatalogInventoryStockIndexer::INDEXER_ID]); | ||
} | ||
|
||
return $dependencies; | ||
} | ||
|
||
/** | ||
* Remove index dependency, if it needed, on reindex triggers. | ||
* | ||
* @param Provider $provider | ||
* @param array $dependencies | ||
* @param string $indexerId | ||
* @return array | ||
* @see \Magento\Indexer\Model\Indexer\DependencyDecorator | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterGetIndexerIdsToRunAfter(Provider $provider, array $dependencies, string $indexerId): array | ||
{ | ||
if ($this->isFilteringNeeded($indexerId, CatalogInventoryStockIndexer::INDEXER_ID)) { | ||
$dependencies = array_diff($dependencies, [CatalogSearchFulltextIndexer::INDEXER_ID]); | ||
} | ||
|
||
return $dependencies; | ||
} | ||
|
||
/** | ||
* @param string $currentIndexerId | ||
* @param string $targetIndexerId | ||
* @return bool | ||
*/ | ||
private function isFilteringNeeded(string $currentIndexerId, string $targetIndexerId): bool | ||
{ | ||
return (!$this->config->isElasticsearchEnabled() && $targetIndexerId === $currentIndexerId); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
app/code/Magento/Elasticsearch/Model/Indexer/Plugin/StockedProductsFilterPlugin.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,94 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Elasticsearch\Model\Indexer\Plugin; | ||
|
||
use Magento\Elasticsearch\Model\Config; | ||
use Magento\CatalogInventory\Api\StockConfigurationInterface; | ||
use Magento\CatalogInventory\Api\StockStatusRepositoryInterface; | ||
use Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory; | ||
use Magento\CatalogInventory\Api\Data\StockStatusInterface; | ||
use Magento\CatalogSearch\Model\Indexer\Fulltext\Action\DataProvider; | ||
|
||
/** | ||
* Plugin for filtering child products that are out of stock for preventing their saving to catalog search index. | ||
*/ | ||
class StockedProductsFilterPlugin | ||
{ | ||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @var StockConfigurationInterface | ||
*/ | ||
private $stockConfiguration; | ||
|
||
/** | ||
* @var StockStatusRepositoryInterface | ||
*/ | ||
private $stockStatusRepository; | ||
|
||
/** | ||
* @var StockStatusCriteriaInterfaceFactory | ||
*/ | ||
private $stockStatusCriteriaFactory; | ||
|
||
/** | ||
* @param Config $config | ||
* @param StockConfigurationInterface $stockConfiguration | ||
* @param StockStatusRepositoryInterface $stockStatusRepository | ||
* @param StockStatusCriteriaInterfaceFactory $stockStatusCriteriaFactory | ||
*/ | ||
public function __construct( | ||
Config $config, | ||
StockConfigurationInterface $stockConfiguration, | ||
StockStatusRepositoryInterface $stockStatusRepository, | ||
StockStatusCriteriaInterfaceFactory $stockStatusCriteriaFactory | ||
) { | ||
$this->config = $config; | ||
$this->stockConfiguration = $stockConfiguration; | ||
$this->stockStatusRepository = $stockStatusRepository; | ||
$this->stockStatusCriteriaFactory = $stockStatusCriteriaFactory; | ||
} | ||
|
||
/** | ||
* Filter out of stock options for configurable product. | ||
* | ||
* @param DataProvider $dataProvider | ||
* @param array $indexData | ||
* @param array $productData | ||
* @param int $storeId | ||
* @return array | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function beforePrepareProductIndex( | ||
DataProvider $dataProvider, | ||
array $indexData, | ||
array $productData, | ||
int $storeId | ||
): array { | ||
if ($this->config->isElasticsearchEnabled() && !$this->stockConfiguration->isShowOutOfStock($storeId)) { | ||
$productIds = array_keys($indexData); | ||
$stockStatusCriteria = $this->stockStatusCriteriaFactory->create(); | ||
$stockStatusCriteria->setProductsFilter($productIds); | ||
$stockStatusCollection = $this->stockStatusRepository->getList($stockStatusCriteria); | ||
$stockStatuses = $stockStatusCollection->getItems(); | ||
$stockStatuses = array_filter($stockStatuses, function (StockStatusInterface $stockStatus) { | ||
return StockStatusInterface::STATUS_IN_STOCK == $stockStatus->getStockStatus(); | ||
}); | ||
$indexData = array_intersect_key($indexData, $stockStatuses); | ||
} | ||
|
||
return [ | ||
$indexData, | ||
$productData, | ||
$storeId, | ||
]; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...code/Magento/Elasticsearch/Test/Unit/Model/Indexer/Plugin/DependencyUpdaterPluginTest.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,87 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Elasticsearch\Test\Unit\Model\Indexer\Plugin; | ||
|
||
use Magento\Elasticsearch\Model\Config; | ||
use Magento\Elasticsearch\Model\Indexer\Plugin\DependencyUpdaterPlugin; | ||
use Magento\Framework\Indexer\Config\DependencyInfoProvider; | ||
use Magento\CatalogSearch\Model\Indexer\Fulltext as CatalogSearchFulltextIndexer; | ||
use Magento\CatalogInventory\Model\Indexer\Stock\Processor as CatalogInventoryStockIndexer; | ||
|
||
/** | ||
* Test for Magento\Elasticsearch\Model\Indexer\Plugin\DependencyUpdaterPlugin class. | ||
*/ | ||
class DependencyUpdaterPluginTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var Config|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $configMock; | ||
|
||
/** | ||
* @var DependencyUpdaterPlugin | ||
*/ | ||
private $plugin; | ||
|
||
/** | ||
* @var DependencyInfoProvider|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $providerMock; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->configMock = $this->getMockBuilder(Config::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->configMock->expects($this->exactly(2)) | ||
->method('isElasticsearchEnabled') | ||
->willReturnOnConsecutiveCalls(true, false); | ||
$this->providerMock = $this->getMockBuilder(DependencyInfoProvider::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->plugin = new DependencyUpdaterPlugin($this->configMock); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testAfterGetIndexerIdsToRunBefore(): void | ||
{ | ||
$dependencies = [ | ||
CatalogInventoryStockIndexer::INDEXER_ID, | ||
]; | ||
$indexerId = CatalogSearchFulltextIndexer::INDEXER_ID; | ||
|
||
$indexerIds = $this->plugin->afterGetIndexerIdsToRunBefore($this->providerMock, $dependencies, $indexerId); | ||
$this->assertContains(CatalogInventoryStockIndexer::INDEXER_ID, $indexerIds); | ||
|
||
$indexerIds = $this->plugin->afterGetIndexerIdsToRunBefore($this->providerMock, $dependencies, $indexerId); | ||
$this->assertNotContains(CatalogInventoryStockIndexer::INDEXER_ID, $indexerIds); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testAfterGetIndexerIdsToRunAfter(): void | ||
{ | ||
$dependencies = [ | ||
CatalogSearchFulltextIndexer::INDEXER_ID, | ||
]; | ||
$indexerId = CatalogInventoryStockIndexer::INDEXER_ID; | ||
|
||
$indexerIds = $this->plugin->afterGetIndexerIdsToRunAfter($this->providerMock, $dependencies, $indexerId); | ||
$this->assertContains(CatalogSearchFulltextIndexer::INDEXER_ID, $indexerIds); | ||
|
||
$indexerIds = $this->plugin->afterGetIndexerIdsToRunAfter($this->providerMock, $dependencies, $indexerId); | ||
$this->assertNotContains(CatalogSearchFulltextIndexer::INDEXER_ID, $indexerIds); | ||
} | ||
} |
Oops, something went wrong.