diff --git a/app/code/Magento/Deploy/Console/DeployStaticOptions.php b/app/code/Magento/Deploy/Console/DeployStaticOptions.php index 7bf522f7ca355..9a73dd5d65fc7 100644 --- a/app/code/Magento/Deploy/Console/DeployStaticOptions.php +++ b/app/code/Magento/Deploy/Console/DeployStaticOptions.php @@ -131,6 +131,11 @@ class DeployStaticOptions */ const CONTENT_VERSION = 'content-version'; + /** + * Key for refresh content version only mode + */ + const REFRESH_CONTENT_VERSION_ONLY = 'refresh-content-version-only'; + /** * Deploy static command options list * @@ -225,6 +230,13 @@ private function getBasicOptions() 'Custom version of static content can be used if running deployment on multiple nodes ' . 'to ensure that static content version is identical and caching works properly.' ), + new InputOption( + self::REFRESH_CONTENT_VERSION_ONLY, + null, + InputOption::VALUE_NONE, + 'Refreshing the version of static content only can be used to refresh static content ' + . 'in browser cache and CDN cache.' + ), new InputArgument( self::LANGUAGES_ARGUMENT, InputArgument::IS_ARRAY, diff --git a/app/code/Magento/Deploy/Service/DeployStaticContent.php b/app/code/Magento/Deploy/Service/DeployStaticContent.php index 5f087ca6bb7ff..092e4b0fc238d 100644 --- a/app/code/Magento/Deploy/Service/DeployStaticContent.php +++ b/app/code/Magento/Deploy/Service/DeployStaticContent.php @@ -75,6 +75,16 @@ public function __construct( */ public function deploy(array $options) { + $version = !empty($options[Options::CONTENT_VERSION]) && is_string($options[Options::CONTENT_VERSION]) + ? $options[Options::CONTENT_VERSION] + : (new \DateTime())->getTimestamp(); + $this->versionStorage->save($version); + + if ($this->isRefreshContentVersionOnly($options)) { + $this->logger->warning("New content version: " . $version); + return; + } + $queue = $this->queueFactory->create( [ 'logger' => $this->logger, @@ -96,11 +106,6 @@ public function deploy(array $options) ] ); - $version = !empty($options[Options::CONTENT_VERSION]) && is_string($options[Options::CONTENT_VERSION]) - ? $options[Options::CONTENT_VERSION] - : (new \DateTime())->getTimestamp(); - $this->versionStorage->save($version); - $packages = $deployStrategy->deploy($options); if ($options[Options::NO_JAVASCRIPT] !== true) { @@ -135,4 +140,14 @@ private function getProcessesAmount(array $options) { return isset($options[Options::JOBS_AMOUNT]) ? (int)$options[Options::JOBS_AMOUNT] : 0; } + + /** + * @param array $options + * @return bool + */ + private function isRefreshContentVersionOnly(array $options) + { + return isset($options[Options::REFRESH_CONTENT_VERSION_ONLY]) + && $options[Options::REFRESH_CONTENT_VERSION_ONLY]; + } } diff --git a/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php b/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php index 04bfea068cabb..3d263c7a0a69f 100644 --- a/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php +++ b/app/code/Magento/Deploy/Test/Unit/Service/DeployStaticContentTest.php @@ -114,14 +114,18 @@ protected function setUp() public function testDeploy($options, $expectedContentVersion) { $package = $this->getMock(Package::class, [], [], '', false); - $package->expects($this->exactly(1))->method('isVirtual')->willReturn(false); - $package->expects($this->exactly(3))->method('getArea')->willReturn('area'); - $package->expects($this->exactly(3))->method('getTheme')->willReturn('theme'); - $package->expects($this->exactly(2))->method('getLocale')->willReturn('locale'); - - $packages = [ - 'package' => $package - ]; + if ($options['refresh-content-version-only']) { + $package->expects($this->never())->method('isVirtual'); + $package->expects($this->never())->method('getArea'); + $package->expects($this->never())->method('getTheme'); + $package->expects($this->never())->method('getLocale'); + } else { + $package->expects($this->exactly(1))->method('isVirtual')->willReturn(false); + $package->expects($this->exactly(3))->method('getArea')->willReturn('area'); + $package->expects($this->exactly(3))->method('getTheme')->willReturn('theme'); + $package->expects($this->exactly(2))->method('getLocale')->willReturn('locale'); + } + $packages = ['package' => $package]; if ($expectedContentVersion) { $this->versionStorage->expects($this->once())->method('save')->with($expectedContentVersion); @@ -132,20 +136,27 @@ public function testDeploy($options, $expectedContentVersion) $queue = $this->getMockBuilder(Queue::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); - $this->queueFactory->expects($this->once())->method('create')->willReturn($queue); + if ($options['refresh-content-version-only']) { + $this->queueFactory->expects($this->never())->method('create'); + } else { + $this->queueFactory->expects($this->once())->method('create')->willReturn($queue); + } $strategy = $this->getMockBuilder(CompactDeploy::class) ->setMethods(['deploy']) ->disableOriginalConstructor() ->getMockForAbstractClass(); - $strategy->expects($this->once())->method('deploy') - ->with($options) - ->willReturn($packages); - $this->deployStrategyFactory->expects($this->once()) - ->method('create') - ->with('compact', ['queue' => $queue]) - ->willReturn($strategy); - + if ($options['refresh-content-version-only']) { + $strategy->expects($this->never())->method('deploy'); + } else { + $strategy->expects($this->once())->method('deploy') + ->with($options) + ->willReturn($packages); + $this->deployStrategyFactory->expects($this->once()) + ->method('create') + ->with('compact', ['queue' => $queue]) + ->willReturn($strategy); + } $deployPackageService = $this->getMockBuilder(DeployPackage::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -166,34 +177,32 @@ public function testDeploy($options, $expectedContentVersion) ->disableOriginalConstructor() ->getMockForAbstractClass(); - $this->objectManager->expects($this->exactly(4)) - ->method('create') - ->withConsecutive( - [DeployPackage::class, ['logger' => $this->logger]], - [DeployRequireJsConfig::class, ['logger' => $this->logger]], - [DeployTranslationsDictionary::class, ['logger' => $this->logger]], - [Bundle::class, ['logger' => $this->logger]] - ) - ->willReturnOnConsecutiveCalls( - $deployPackageService, - $deployRjsConfig, - $deployI18n, - $deployBundle - ); - - $this->objectManager->expects($this->exactly(1)) - ->method('get') - ->withConsecutive( - [MinifyTemplates::class] - ) - ->willReturnOnConsecutiveCalls( - $minifyTemplates - ); - - $this->assertEquals( - null, - $this->service->deploy($options) - ); + if ($options['refresh-content-version-only']) { + $this->objectManager->expects($this->never())->method('create'); + $this->objectManager->expects($this->never())->method('get'); + } else { + $this->objectManager->expects($this->exactly(4)) + ->method('create') + ->withConsecutive( + [DeployPackage::class, ['logger' => $this->logger]], + [DeployRequireJsConfig::class, ['logger' => $this->logger]], + [DeployTranslationsDictionary::class, ['logger' => $this->logger]], + [Bundle::class, ['logger' => $this->logger]] + ) + ->willReturnOnConsecutiveCalls( + $deployPackageService, + $deployRjsConfig, + $deployI18n, + $deployBundle + ); + + $this->objectManager->expects($this->exactly(1)) + ->method('get') + ->withConsecutive([MinifyTemplates::class]) + ->willReturnOnConsecutiveCalls($minifyTemplates); + } + + $this->assertEquals(null, $this->service->deploy($options)); } public function deployDataProvider() @@ -203,7 +212,8 @@ public function deployDataProvider() [ 'strategy' => 'compact', 'no-javascript' => false, - 'no-html-minify' => false + 'no-html-minify' => false, + 'refresh-content-version-only' => false, ], null // content version value should not be asserted in this case ], @@ -212,9 +222,17 @@ public function deployDataProvider() 'strategy' => 'compact', 'no-javascript' => false, 'no-html-minify' => false, + 'refresh-content-version-only' => false, 'content-version' => '123456', ], '123456' + ], + [ + [ + 'refresh-content-version-only' => true, + 'content-version' => '654321', + ], + '654321' ] ]; } diff --git a/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php b/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php index d2a0ddce1b422..4217c9ea5c650 100644 --- a/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DeployStaticContentCommand.php @@ -120,11 +120,15 @@ protected function execute(InputInterface $input, OutputInterface $output) $options = $input->getOptions(); $options[Options::LANGUAGE] = $input->getArgument(Options::LANGUAGES_ARGUMENT) ?: ['all']; + $refreshOnly = isset($options[Options::REFRESH_CONTENT_VERSION_ONLY]) + && $options[Options::REFRESH_CONTENT_VERSION_ONLY]; $verbose = $output->getVerbosity() > 1 ? $output->getVerbosity() : OutputInterface::VERBOSITY_VERBOSE; $logger = $this->consoleLoggerFactory->getLogger($output, $verbose); - $logger->alert(PHP_EOL . "Deploy using {$options[Options::STRATEGY]} strategy"); + if (!$refreshOnly) { + $logger->alert(PHP_EOL . "Deploy using {$options[Options::STRATEGY]} strategy"); + } $this->mockCache(); @@ -135,7 +139,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $deployService->deploy($options); - $logger->alert(PHP_EOL . "Execution time: " . (microtime(true) - $time)); + if (!$refreshOnly) { + $logger->alert(PHP_EOL . "Execution time: " . (microtime(true) - $time)); + } return \Magento\Framework\Console\Cli::RETURN_SUCCESS; }