diff --git a/composer.json b/composer.json index ffc78b4..ba9b846 100644 --- a/composer.json +++ b/composer.json @@ -2,13 +2,13 @@ "name": "magento/magento-cloud-patches", "description": "Provides critical fixes for Magento 2 Enterprise Edition", "type": "magento2-component", - "version": "1.0.9", + "version": "1.0.10", "license": "OSL-3.0", "require": { "php": "^7.0", "ext-json": "*", "composer/composer": "@stable", - "composer/semver": "^1.5", + "composer/semver": "^1.5||^2.0||^3.0", "symfony/config": "^3.3||^4.4||^5.1", "symfony/console": "^2.6||^4.0||^5.1", "symfony/dependency-injection": "^3.3||^4.3||^5.1", diff --git a/patches/MCLOUD-6923__layered_navigation_filter_is_present_only_when_product_is_present_on_the_listing_page_with_enabled_shared_catalog__2.3.5.patch b/patches/MCLOUD-6923__layered_navigation_filter_is_present_only_when_product_is_present_on_the_listing_page_with_enabled_shared_catalog__2.3.5.patch index 584d1a4..7b55923 100644 --- a/patches/MCLOUD-6923__layered_navigation_filter_is_present_only_when_product_is_present_on_the_listing_page_with_enabled_shared_catalog__2.3.5.patch +++ b/patches/MCLOUD-6923__layered_navigation_filter_is_present_only_when_product_is_present_on_the_listing_page_with_enabled_shared_catalog__2.3.5.patch @@ -1,7 +1,64 @@ diff -Nuar a/vendor/magento/module-shared-catalog/Model/SearchAdapter/Aggregation/Builder/DataProvider.php b/vendor/magento/module-shared-catalog/Model/SearchAdapter/Aggregation/Builder/DataProvider.php +index 86f4fd48e9..a6061fca6f 100644 --- a/vendor/magento/module-shared-catalog/Model/SearchAdapter/Aggregation/Builder/DataProvider.php +++ b/vendor/magento/module-shared-catalog/Model/SearchAdapter/Aggregation/Builder/DataProvider.php -@@ -103,18 +103,16 @@ public function __construct( +@@ -7,6 +7,8 @@ declare(strict_types=1); + + namespace Magento\SharedCatalog\Model\SearchAdapter\Aggregation\Builder; + ++use Magento\Catalog\Model\Layer; ++use Magento\Catalog\Model\Layer\Resolver; + use Magento\Catalog\Model\Product; + use Magento\Catalog\Model\ResourceModel\Product as ProductResource; + use Magento\CatalogInventory\Model\Configuration; +@@ -14,6 +16,7 @@ use Magento\CatalogInventory\Model\Stock; + use Magento\Customer\Model\Session; + use Magento\Eav\Model\Config as EavConfig; + use Magento\Framework\App\Config\ScopeConfigInterface; ++use Magento\Framework\App\ObjectManager; + use Magento\Framework\App\ResourceConnection; + use Magento\Framework\App\ScopeResolverInterface; + use Magento\Framework\DB\Adapter\AdapterInterface; +@@ -70,6 +73,11 @@ class DataProvider + */ + private $productItem; + ++ /** ++ * @var Layer ++ */ ++ private $searchLayer; ++ + /** + * @param ResourceConnection $resource + * @param Session $session +@@ -78,6 +86,7 @@ class DataProvider + * @param EavConfig $eavConfig + * @param ProductResource $product + * @param ProductItemResource $productItem ++ * @param Resolver|null $layerResolver + */ + public function __construct( + ResourceConnection $resource, +@@ -86,7 +95,8 @@ class DataProvider + ScopeConfigInterface $scopeConfig, + EavConfig $eavConfig, + ProductResource $product, +- ProductItemResource $productItem ++ ProductItemResource $productItem, ++ ?Resolver $layerResolver = null + ) { + $this->resource = $resource; + $this->connection = $resource->getConnection(); +@@ -96,6 +106,8 @@ class DataProvider + $this->eavConfig = $eavConfig; + $this->product = $product; + $this->productItem = $productItem; ++ $layerResolver = $layerResolver ?? ObjectManager::getInstance()->get(Resolver::class); ++ $this->searchLayer = $layerResolver->get(); + } + + /** +@@ -103,18 +115,16 @@ class DataProvider * * @param BucketInterface $bucket * @param array $dimensions @@ -20,9 +77,9 @@ diff -Nuar a/vendor/magento/module-shared-catalog/Model/SearchAdapter/Aggregatio - $select = $this->getSelect($bucket, $dimensions, $documentIds); + $select = $this->getSelect($bucket, $dimensions); $query = $this->connection->query($select); - + while ($row = $query->fetch()) { -@@ -134,11 +132,10 @@ public function getAggregation( +@@ -134,15 +144,15 @@ class DataProvider * * @param BucketInterface $bucket * @param array $dimensions @@ -35,24 +92,39 @@ diff -Nuar a/vendor/magento/module-shared-catalog/Model/SearchAdapter/Aggregatio { $attribute = $this->eavConfig->getAttribute(Product::ENTITY, $bucket->getField()); $currentScope = $this->scopeResolver->getScope($dimensions['scope']->getValue()); -@@ -161,7 +158,6 @@ private function getSelect(BucketInterface $bucket, array $dimensions, array $do + $customerGroupId = $this->session->getCustomerGroupId(); ++ $categoryId = $this->searchLayer->getCurrentCategory()->getId(); + + $eavIndexTable = $this->resource->getTableName( + 'catalog_product_index_eav' . ($attribute->getBackendType() === 'decimal' ? '_decimal' : '') +@@ -160,11 +170,14 @@ class DataProvider + ['shared_catalog_item' => $this->productItem->getMainTable()], 'source_entity.sku = shared_catalog_item.sku', [] ++ )->joinInner( ++ ['catalog_category_product' => $this->resource->getTableName('catalog_category_product')], ++ 'eav.entity_id = catalog_category_product.product_id', ++ [] ) - ->where('eav.entity_id IN (?)', $documentIds) ->where('eav.attribute_id = ?', $attribute->getId()) ->where('eav.store_id = ? ', $currentScope->getId()) - ->where('source_entity.type_id <> ?', 'configurable') -diff -Nuar a/vendor/magento/module-shared-catalog/Plugin/Elasticsearch/SearchAdapter/Aggregation/Builder/UpdateTermBucketBuilderPlugin.php b/vendor/magento/module-shared-catalog/Plugin/Elasticsearch/SearchAdapter/Aggregation/Builder/UpdateTermBucketBuilderPlugin.php +- ->where('source_entity.type_id <> ?', 'configurable') ++ ->where('catalog_category_product.category_id = ?', $categoryId) + ->where('shared_catalog_item.customer_group_id = ?', $customerGroupId); + + $this->addStockFilterToSelect($subSelect); +diff --git a/vendor/magento/module-shared-catalog/Plugin/Elasticsearch/SearchAdapter/Aggregation/Builder/UpdateTermBucketBuilderPlugin.php b/vendor/magento/module-shared-catalog/Plugin/Elasticsearch/SearchAdapter/Aggregation/Builder/UpdateTermBucketBuilderPlugin.php +index fdc811dbeb..28b1cd4ee4 100644 --- a/vendor/magento/module-shared-catalog/Plugin/Elasticsearch/SearchAdapter/Aggregation/Builder/UpdateTermBucketBuilderPlugin.php +++ b/vendor/magento/module-shared-catalog/Plugin/Elasticsearch/SearchAdapter/Aggregation/Builder/UpdateTermBucketBuilderPlugin.php -@@ -65,8 +65,7 @@ public function afterBuild( +@@ -65,8 +65,7 @@ class UpdateTermBucketBuilderPlugin $shouldAggregate = ($bucket->getField() !== 'category_ids'); - + if ($sharedCatalogIsEnabled && $shouldAggregate) { - $documentIds = array_column($queryResult['hits']['hits'], '_id'); - $values = $this->dataProvider->getAggregation($bucket, $dimensions, $documentIds); + $values = $this->dataProvider->getAggregation($bucket, $dimensions); } - + return $values; diff --git a/src/Command/Apply.php b/src/Command/Apply.php index 612f90a..47b1692 100644 --- a/src/Command/Apply.php +++ b/src/Command/Apply.php @@ -88,7 +88,9 @@ public function execute(InputInterface $input, OutputInterface $output) try { $this->applyOptional->run($input, $output); } catch (RuntimeException $e) { + $output->writeln($this->magentoVersion->get()); $output->writeln('' . $e->getMessage() . ''); + $this->logger->info($this->magentoVersion->get()); $this->logger->error($e->getMessage()); diff --git a/src/Command/Ece/Apply.php b/src/Command/Ece/Apply.php index c19f5da..7a1b513 100644 --- a/src/Command/Ece/Apply.php +++ b/src/Command/Ece/Apply.php @@ -98,6 +98,7 @@ public function execute(InputInterface $input, OutputInterface $output) $this->applyOptional->run($input, $output); $this->applyLocal->run($input, $output); } catch (RuntimeException $e) { + $output->writeln($this->magentoVersion->get()); $output->writeln('' . $e->getMessage() . ''); $this->logger->info($this->magentoVersion->get()); $this->logger->error($e->getMessage()); diff --git a/src/Command/Ece/Revert.php b/src/Command/Ece/Revert.php index a06e391..8244635 100644 --- a/src/Command/Ece/Revert.php +++ b/src/Command/Ece/Revert.php @@ -78,6 +78,7 @@ public function execute(InputInterface $input, OutputInterface $output) try { $this->revert->run($input, $output); } catch (RuntimeException $e) { + $output->writeln($this->magentoVersion->get()); $output->writeln('' . $e->getMessage() . ''); $this->logger->info($this->magentoVersion->get()); $this->logger->error($e->getMessage()); diff --git a/src/Command/Process/Action/ProcessDeprecatedAction.php b/src/Command/Process/Action/ProcessDeprecatedAction.php index 9341bda..b04ab3d 100644 --- a/src/Command/Process/Action/ProcessDeprecatedAction.php +++ b/src/Command/Process/Action/ProcessDeprecatedAction.php @@ -9,7 +9,6 @@ use Magento\CloudPatches\App\RuntimeException; use Magento\CloudPatches\Command\Process\Renderer; -use Magento\CloudPatches\Patch\Data\AggregatedPatch; use Magento\CloudPatches\Patch\Data\AggregatedPatchInterface; use Magento\CloudPatches\Patch\Pool\OptionalPool; use Magento\CloudPatches\Patch\Aggregator; @@ -93,6 +92,13 @@ public function execute(InputInterface $input, OutputInterface $output, array $p throw new RuntimeException($e->getMessage(), $e->getCode(), $e); } + $patches = array_filter( + $patches, + function ($patch) { + return !$this->statusPool->isApplied($patch->getId()); + } + ); + foreach ($patches as $patch) { $this->processDeprecation($patch, $output, $input); $this->processReplacement($patch, $output, $input); @@ -144,21 +150,23 @@ function ($patchId) { } ); - if ($requireRevertAndReplace) { - $ids = implode(' ', $requireRevertAndReplace); - $warning = sprintf('%s should be reverted and replaced with %s', $ids, $patch->getId()); - $output->writeln('' . $warning . ''); - $this->logger->warning($warning); + if (empty($requireRevertAndReplace)) { + return; + } - $question = 'Do you want to proceed with reverting?'; - if (!$this->renderer->printQuestion($input, $output, $question)) { - $errorMessage = sprintf('%s can\'t be applied without reverting %s', $patch->getId(), $ids); + $ids = implode(' ', $requireRevertAndReplace); + $warning = sprintf('%s should be reverted and replaced with %s', $ids, $patch->getId()); + $output->writeln('' . $warning . ''); + $this->logger->warning($warning); - throw new RuntimeException($errorMessage); - } + $question = 'Do you want to proceed with reverting?'; + if (!$this->renderer->printQuestion($input, $output, $question)) { + $errorMessage = sprintf('%s can\'t be applied without reverting %s', $patch->getId(), $ids); - $this->revert->execute($input, $output, $requireRevertAndReplace); + throw new RuntimeException($errorMessage); } + + $this->revert->execute($input, $output, $requireRevertAndReplace); } /** diff --git a/src/Command/Process/ApplyLocal.php b/src/Command/Process/ApplyLocal.php index 6316fab..654f03c 100644 --- a/src/Command/Process/ApplyLocal.php +++ b/src/Command/Process/ApplyLocal.php @@ -89,7 +89,7 @@ public function run(InputInterface $input, OutputInterface $output) $this->printInfo($output, $message); array_push($appliedPatches, $patch); } catch (ApplierException $exception) { - $this->printError($output, 'Error: patch can\'t be applied'); + $this->printError($output, 'Error: patch ' . $patch->getPath() . ' can\'t be applied'); $messages = $this->rollbackProcessor->process($appliedPatches); $output->writeln($messages); $errorMessage = sprintf( diff --git a/src/Command/Revert.php b/src/Command/Revert.php index 7a29a3d..d0bc7e4 100644 --- a/src/Command/Revert.php +++ b/src/Command/Revert.php @@ -101,6 +101,7 @@ public function execute(InputInterface $input, OutputInterface $output) try { $this->revert->run($input, $output); } catch (RuntimeException $e) { + $output->writeln($this->magentoVersion->get()); $output->writeln('' . $e->getMessage() . ''); $this->logger->info($this->magentoVersion->get()); $this->logger->error($e->getMessage()); diff --git a/src/Patch/Conflict/Processor.php b/src/Patch/Conflict/Processor.php index 68b99de..0346c15 100644 --- a/src/Patch/Conflict/Processor.php +++ b/src/Patch/Conflict/Processor.php @@ -73,7 +73,7 @@ public function process( array $appliedPatches, string $exceptionMessage ) { - $errorMessage = 'Error: patch can\'t be applied'; + $errorMessage = 'Error: patch ' . $patch->getId() . ' can\'t be applied'; $this->logger->error($errorMessage); $output->writeln('' . $errorMessage . ''); diff --git a/src/Test/Functional/Acceptance/Acceptance73Cest.php b/src/Test/Functional/Acceptance/Acceptance73Cest.php index a6e872b..0985aab 100644 --- a/src/Test/Functional/Acceptance/Acceptance73Cest.php +++ b/src/Test/Functional/Acceptance/Acceptance73Cest.php @@ -24,7 +24,10 @@ protected function patchesDataProvider(): array ['templateVersion' => '2.3.4', 'magentoVersion' => '2.3.4-p2'], ['templateVersion' => '2.3.5', 'magentoVersion' => '2.3.5'], ['templateVersion' => '2.3.5', 'magentoVersion' => '2.3.5-p1'], + ['templateVersion' => '2.3.5', 'magentoVersion' => '2.3.5-p2'], ['templateVersion' => '2.3.6', 'magentoVersion' => '2.3.6'], + ['templateVersion' => '2.3.6', 'magentoVersion' => '2.3.6-p1'], + ['templateVersion' => '2.3.6', 'magentoVersion' => '2.3.7'], ['templateVersion' => '2.4.0', 'magentoVersion' => '2.4.0'], ]; } diff --git a/src/Test/Functional/Acceptance/AcceptanceCest.php b/src/Test/Functional/Acceptance/AcceptanceCest.php index c532f87..9b44cf7 100644 --- a/src/Test/Functional/Acceptance/AcceptanceCest.php +++ b/src/Test/Functional/Acceptance/AcceptanceCest.php @@ -51,7 +51,10 @@ protected function patchesDataProvider(): array return [ ['templateVersion' => '2.4.0', 'magentoVersion' => '2.4.0'], ['templateVersion' => '2.4.0', 'magentoVersion' => '2.4.0-p1'], - ['templateVersion' => '2.4.1'], + ['templateVersion' => '2.4.1', 'magentoVersion' => '2.4.1'], + ['templateVersion' => '2.4.1', 'magentoVersion' => '2.4.1-p1'], + ['templateVersion' => '2.4.2', 'magentoVersion' => '2.4.2'], + ['templateVersion' => '2.4.2', 'magentoVersion' => '2.4.2-p1'], ['templateVersion' => 'master'], ]; } diff --git a/src/Test/Unit/Command/Process/Action/ProcessDeprecatedActionTest.php b/src/Test/Unit/Command/Process/Action/ProcessDeprecatedActionTest.php index 68cef97..50dd537 100644 --- a/src/Test/Unit/Command/Process/Action/ProcessDeprecatedActionTest.php +++ b/src/Test/Unit/Command/Process/Action/ProcessDeprecatedActionTest.php @@ -208,6 +208,40 @@ public function testProcessReplacementSuccessful() $this->action->execute($inputMock, $outputMock, $patchFilter); } + /** + * Tests successful skipping of replacement check when patch is already applied. + */ + public function testSkippingReplacementProcessForAppliedPatch() + { + $patch1 = $this->createPatch('MC-11111', false); + $this->statusPool->method('isApplied') + ->willReturnMap([ + ['MC-11111', true] + ]); + $patchFilter = [$patch1->getId()]; + + /** @var InputInterface|MockObject $inputMock */ + $inputMock = $this->getMockForAbstractClass(InputInterface::class); + /** @var OutputInterface|MockObject $outputMock */ + $outputMock = $this->getMockForAbstractClass(OutputInterface::class); + + $patchMock = $this->getMockForAbstractClass(PatchInterface::class); + + $this->optionalPool->expects($this->once()) + ->method('getList') + ->withConsecutive([$patchFilter]) + ->willReturn([$patchMock]); + + $this->aggregator->expects($this->once()) + ->method('aggregate') + ->willReturn([$patch1]); + + $this->renderer->expects($this->never()) + ->method('printQuestion'); + + $this->action->execute($inputMock, $outputMock, $patchFilter); + } + /** * Tests a case when user rejected to revert deprecated patches before applying a new one. */ diff --git a/src/Test/Unit/Patch/Conflict/ProcessorTest.php b/src/Test/Unit/Patch/Conflict/ProcessorTest.php index 8f09459..c37631f 100644 --- a/src/Test/Unit/Patch/Conflict/ProcessorTest.php +++ b/src/Test/Unit/Patch/Conflict/ProcessorTest.php @@ -92,7 +92,7 @@ public function testProcess() $outputMock->expects($this->exactly(2)) ->method('writeln') ->withConsecutive( - [$this->stringContains('Error: patch can\'t be applied')], + [$this->stringContains('Error: patch ' . $failedPatch->getId() . ' can\'t be applied')], [$rollbackMessages] );