From d39c0937c3c3ce065851fdb39a3b0175fd3bc024 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 6 Apr 2021 22:18:25 +0100 Subject: [PATCH 001/656] Produce success message only for humans --- app/code/Magento/Cron/Console/Command/CronCommand.php | 5 ++++- app/code/Magento/Cron/composer.json | 1 + app/code/Magento/Cron/etc/di.xml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Cron/Console/Command/CronCommand.php b/app/code/Magento/Cron/Console/Command/CronCommand.php index 142a9a397eb5f..85a3d8243935d 100644 --- a/app/code/Magento/Cron/Console/Command/CronCommand.php +++ b/app/code/Magento/Cron/Console/Command/CronCommand.php @@ -115,6 +115,9 @@ protected function execute(InputInterface $input, OutputInterface $output) /** @var \Magento\Framework\App\Cron $cronObserver */ $cronObserver = $objectManager->create(\Magento\Framework\App\Cron::class, ['parameters' => $params]); $cronObserver->launch(); - $output->writeln('' . 'Ran jobs by schedule.' . ''); + + if (posix_isatty(STDOUT)) { + $output->writeln('' . 'Ran jobs by schedule.' . ''); + } } } diff --git a/app/code/Magento/Cron/composer.json b/app/code/Magento/Cron/composer.json index 00da35140744b..082681a67b94b 100644 --- a/app/code/Magento/Cron/composer.json +++ b/app/code/Magento/Cron/composer.json @@ -5,6 +5,7 @@ "sort-packages": true }, "require": { + "ext-posix": "*", "php": "~7.3.0||~7.4.0", "magento/framework": "*", "magento/module-store": "*" diff --git a/app/code/Magento/Cron/etc/di.xml b/app/code/Magento/Cron/etc/di.xml index e7286169359bd..8beeea0af6f5e 100644 --- a/app/code/Magento/Cron/etc/di.xml +++ b/app/code/Magento/Cron/etc/di.xml @@ -65,7 +65,7 @@ - {magentoRoot}bin/magento cron:run | grep -v "Ran jobs by schedule" >> {magentoLog}magento.cron.log + {magentoRoot}bin/magento cron:run >> {magentoLog}magento.cron.log false From cd7c499f49de63a8a4d200150544766daf28ccc2 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 6 Apr 2021 22:44:43 +0100 Subject: [PATCH 002/656] Catch STDERR as well as STDOUT --- app/code/Magento/Cron/etc/di.xml | 2 +- .../Magento/Framework/Shell/CommandRendererBackground.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Cron/etc/di.xml b/app/code/Magento/Cron/etc/di.xml index 8beeea0af6f5e..903ea478c4b60 100644 --- a/app/code/Magento/Cron/etc/di.xml +++ b/app/code/Magento/Cron/etc/di.xml @@ -65,7 +65,7 @@ - {magentoRoot}bin/magento cron:run >> {magentoLog}magento.cron.log + {magentoRoot}bin/magento cron:run >> {magentoLog}magento.cron.log 2>&1 false diff --git a/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php b/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php index 5b61c62dae313..d77375debc502 100644 --- a/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php +++ b/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php @@ -35,6 +35,6 @@ public function render($command, array $arguments = []) return $this->osInfo->isWindows() ? 'start /B "magento background task" ' . $command - : str_replace('2>&1', '> /dev/null &', $command); + : str_replace('2>&1', '> /dev/null 2>&1 &', $command); } } From 0fe0e186adddb502d91982fe18cc9406a4a9bd0a Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 6 Apr 2021 23:05:04 +0100 Subject: [PATCH 003/656] Log output of background processes --- .../Observer/ProcessCronQueueObserver.php | 6 +++-- .../Shell/CommandRendererBackground.php | 23 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php b/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php index 0f266b5d62d83..3c88f1d68bb24 100644 --- a/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php +++ b/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php @@ -254,10 +254,12 @@ function ($a, $b) { && $this->getCronGroupConfigurationValue($groupId, 'use_separate_process') == 1 ) { $this->_shell->execute( - $phpPath . ' %s cron:run --group=' . $groupId . ' --' . Cli::INPUT_KEY_BOOTSTRAP . '=' + '%s %s cron:run --group=%s --' . Cli::INPUT_KEY_BOOTSTRAP . '=' . self::STANDALONE_PROCESS_STARTED . '=1', [ - BP . '/bin/magento' + $phpPath, + BP . '/bin/magento', + $groupId, ] ); continue; diff --git a/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php b/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php index d77375debc502..84f97320a0dab 100644 --- a/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php +++ b/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php @@ -5,20 +5,31 @@ */ namespace Magento\Framework\Shell; +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem; use Magento\Framework\OsInfo; class CommandRendererBackground extends CommandRenderer { + /** + * @var Filesystem + */ + protected $filesystem; + /** * @var \Magento\Framework\OsInfo */ protected $osInfo; /** + * @param Filesystem $filesystem * @param OsInfo $osInfo */ - public function __construct(OsInfo $osInfo) - { + public function __construct( + Filesystem $filesystem, + OsInfo $osInfo + ) { + $this->filesystem = $filesystem; $this->osInfo = $osInfo; } @@ -33,8 +44,14 @@ public function render($command, array $arguments = []) { $command = parent::render($command, $arguments); + $logFile = '/dev/null'; + if ($groupId = $arguments[2] ?? null) { + $logDir = $this->filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath(); + $logFile = escapeshellarg($logDir . 'magento.cron.' . $groupId . '.log'); + } + return $this->osInfo->isWindows() ? 'start /B "magento background task" ' . $command - : str_replace('2>&1', '> /dev/null 2>&1 &', $command); + : str_replace('2>&1', ">> $logFile 2>&1 &", $command); } } From 0e2c0b8356c0ac3b1062df78e9634525450ff730 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 7 Apr 2021 22:31:42 +0100 Subject: [PATCH 004/656] Update test for new functionality --- .../Unit/CommandRendererBackgroundTest.php | 51 +++++++++++++++++-- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php b/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php index c737bc9c4461e..c83a064afae7f 100644 --- a/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php +++ b/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php @@ -7,6 +7,8 @@ namespace Magento\Framework\Shell\Test\Unit; +use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\Directory\ReadInterface; use Magento\Framework\OsInfo; use Magento\Framework\Shell\CommandRendererBackground; use PHPUnit\Framework\MockObject\MockObject; @@ -14,6 +16,13 @@ class CommandRendererBackgroundTest extends TestCase { + /** + * Test path to Magento's var/log directory + * + * @var string + */ + protected $logPath = '/path/to/magento/var/log/'; + /** * Test data for command * @@ -21,6 +30,11 @@ class CommandRendererBackgroundTest extends TestCase */ protected $testCommand = 'php -r test.php'; + /** + * @var Filesystem|MockObject + */ + protected $filesystem; + /** * @var OsInfo|MockObject */ @@ -30,23 +44,37 @@ protected function setUp(): void { $this->osInfo = $this->getMockBuilder(OsInfo::class) ->getMock(); + + $directoryMock = $this->getMockBuilder(ReadInterface::class) + ->getMock(); + $directoryMock->expects($this->any()) + ->method('getAbsolutePath') + ->willReturn($this->logPath); + + $this->filesystem = $this->getMockBuilder(Filesystem::class) + ->disableOriginalConstructor() + ->getMock(); + $this->filesystem->expects($this->any()) + ->method('getDirectoryRead') + ->willReturn($directoryMock); } /** * @dataProvider commandPerOsTypeDataProvider * @param bool $isWindows * @param string $expectedResults + * @param string[] $arguments */ - public function testRender($isWindows, $expectedResults) + public function testRender($isWindows, $expectedResults, $arguments) { $this->osInfo->expects($this->once()) ->method('isWindows') ->willReturn($isWindows); - $commandRenderer = new CommandRendererBackground($this->osInfo); + $commandRenderer = new CommandRendererBackground($this->filesystem, $this->osInfo); $this->assertEquals( $expectedResults, - $commandRenderer->render($this->testCommand) + $commandRenderer->render($this->testCommand, $arguments) ); } @@ -58,8 +86,21 @@ public function testRender($isWindows, $expectedResults) public function commandPerOsTypeDataProvider() { return [ - 'windows' => [true, 'start /B "magento background task" ' . $this->testCommand . ' 2>&1'], - 'unix' => [false, $this->testCommand . ' > /dev/null &'], + 'windows' => [ + true, + 'start /B "magento background task" ' . $this->testCommand . ' 2>&1', + [], + ], + 'unix-without-group-name' => [ + false, + $this->testCommand . ' >> /dev/null 2>&1 &', + [], + ], + 'unix-with-group-name' => [ + false, + $this->testCommand . " >> '{$this->logPath}magento.cron.group-name.log' 2>&1 &", + ['php-executable', 'script-path', 'group-name'], + ], ]; } } From 6e85c80b21a2886066e86f7d76e030226908575f Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 7 Apr 2021 22:32:12 +0100 Subject: [PATCH 005/656] Correct comment --- app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php b/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php index 3c88f1d68bb24..c747a7703ddce 100644 --- a/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php +++ b/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php @@ -811,7 +811,7 @@ private function processPendingJobs(string $groupId, array $jobsRoot, int $curre /** @var Schedule $schedule */ foreach ($pendingJobs as $schedule) { if (isset($processedJobs[$schedule->getJobCode()])) { - // process only on job per run + // process only one of each job per run continue; } $jobConfig = isset($jobsRoot[$schedule->getJobCode()]) ? $jobsRoot[$schedule->getJobCode()] : null; From 42d783c7861099db7729a1aeaa401e54920bcba9 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Thu, 8 Apr 2021 18:50:34 +0100 Subject: [PATCH 006/656] Add ext-posix to root composer.json --- composer.json | 1 + composer.lock | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 276a9facfa1ad..46c15e11e7e8f 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ "ext-mbstring": "*", "ext-openssl": "*", "ext-pdo_mysql": "*", + "ext-posix": "*", "ext-simplexml": "*", "ext-soap": "*", "ext-xsl": "*", diff --git a/composer.lock b/composer.lock index 4295afd9ead7e..4a66e253901cf 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9bc433740520119db84253a54d67a303", + "content-hash": "962083e98929e70d1ab0e3692a2e3a57", "packages": [ { "name": "aws/aws-sdk-php", @@ -11135,6 +11135,7 @@ "ext-mbstring": "*", "ext-openssl": "*", "ext-pdo_mysql": "*", + "ext-posix": "*", "ext-simplexml": "*", "ext-soap": "*", "ext-xsl": "*", From a75223dcd655cde87f988675806ba9335fb60600 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Tue, 11 Apr 2023 13:54:20 +0300 Subject: [PATCH 007/656] Make ImageMagick Adapter compatible with php8 (Implicit conversion from float to int) --- .../Magento/Framework/Image/Adapter/ImageMagick.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php b/lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php index d0b88a34c09d8..d81ceea37ddc6 100644 --- a/lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php +++ b/lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php @@ -212,14 +212,14 @@ public function resize($frameWidth = null, $frameHeight = null) $newImage = new \Imagick(); $newImage->newImage( - $dims['frame']['width'], - $dims['frame']['height'], + floor($dims['frame']['width']), + floor($dims['frame']['height']), $this->_imageHandler->getImageBackgroundColor() ); $this->_imageHandler->resizeImage( - $dims['dst']['width'], - $dims['dst']['height'], + floor($dims['dst']['width']), + floor($dims['dst']['height']), \Imagick::FILTER_CUBIC, self::BLUR_FACTOR ); From 365236a125d7f9fc35aa6f683dca3b8954a0fe3a Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 26 Apr 2023 13:22:53 +0100 Subject: [PATCH 008/656] Fix unit test failure --- .../Cron/Test/Unit/Console/Command/CronCommandTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Cron/Test/Unit/Console/Command/CronCommandTest.php b/app/code/Magento/Cron/Test/Unit/Console/Command/CronCommandTest.php index 83ebcddaf60b3..8718771432d0b 100644 --- a/app/code/Magento/Cron/Test/Unit/Console/Command/CronCommandTest.php +++ b/app/code/Magento/Cron/Test/Unit/Console/Command/CronCommandTest.php @@ -1,8 +1,10 @@ objectManagerFactory, $this->deploymentConfigMock) ); $commandTester->execute([]); - $expectedMsg = 'Ran jobs by schedule.' . PHP_EOL; + $expectedMsg = ''; $this->assertEquals($expectedMsg, $commandTester->getDisplay()); } } From a1d3859b6c2146b6fd24a818ae3f8b8ac1756a44 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 2 May 2023 13:39:20 +0100 Subject: [PATCH 009/656] Ignore intentional use of discouraged function --- app/code/Magento/Cron/Console/Command/CronCommand.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/Magento/Cron/Console/Command/CronCommand.php b/app/code/Magento/Cron/Console/Command/CronCommand.php index 321a8d3cdeef2..69e1630b7ce86 100644 --- a/app/code/Magento/Cron/Console/Command/CronCommand.php +++ b/app/code/Magento/Cron/Console/Command/CronCommand.php @@ -1,4 +1,5 @@ create(Cron::class, ['parameters' => $params]); $cronObserver->launch(); + // phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged if (posix_isatty(STDOUT)) { $output->writeln('' . 'Ran jobs by schedule.' . ''); } From 13bbeb1311251401e9af8641975fb2e96dccfbbd Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 16 May 2023 10:51:34 +0100 Subject: [PATCH 010/656] Replace posix_isatty() with stream_isatty() --- app/code/Magento/Cron/Console/Command/CronCommand.php | 4 ++-- app/code/Magento/Cron/composer.json | 1 - composer.json | 1 - composer.lock | 3 +-- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Cron/Console/Command/CronCommand.php b/app/code/Magento/Cron/Console/Command/CronCommand.php index 69e1630b7ce86..ceb123724210f 100644 --- a/app/code/Magento/Cron/Console/Command/CronCommand.php +++ b/app/code/Magento/Cron/Console/Command/CronCommand.php @@ -141,8 +141,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $cronObserver = $objectManager->create(Cron::class, ['parameters' => $params]); $cronObserver->launch(); - // phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged - if (posix_isatty(STDOUT)) { + // phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged,Magento2.Exceptions.TryProcessSystemResources.MissingTryCatch + if (stream_isatty(STDOUT)) { $output->writeln('' . 'Ran jobs by schedule.' . ''); } diff --git a/app/code/Magento/Cron/composer.json b/app/code/Magento/Cron/composer.json index f83c8c533ab78..1696588920015 100644 --- a/app/code/Magento/Cron/composer.json +++ b/app/code/Magento/Cron/composer.json @@ -5,7 +5,6 @@ "sort-packages": true }, "require": { - "ext-posix": "*", "php": "~8.1.0||~8.2.0", "magento/framework": "*", "magento/module-store": "*" diff --git a/composer.json b/composer.json index c2d0c4cfc5912..de82ab814e132 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,6 @@ "ext-mbstring": "*", "ext-openssl": "*", "ext-pdo_mysql": "*", - "ext-posix": "*", "ext-simplexml": "*", "ext-soap": "*", "ext-sodium": "*", diff --git a/composer.lock b/composer.lock index ee76b5d9b8c01..7cd9eaf2766f1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "888e78f254ed1481460220ea3b4e86c2", + "content-hash": "0bc8161c0e1f3acf100e1fa3c445b1e2", "packages": [ { "name": "aws/aws-crt-php", @@ -14164,7 +14164,6 @@ "ext-mbstring": "*", "ext-openssl": "*", "ext-pdo_mysql": "*", - "ext-posix": "*", "ext-simplexml": "*", "ext-soap": "*", "ext-sodium": "*", From 17638f5b352cf6c7e8871d5aa7b0e9824911c7d1 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 16 May 2023 11:16:18 +0100 Subject: [PATCH 011/656] Move Framework modifications into module --- .../Cron/Shell/CommandRendererBackground.php | 46 +++++++ .../Shell/CommandRendererBackgroundTest.php | 113 ++++++++++++++++++ app/code/Magento/Cron/etc/di.xml | 7 +- app/code/Magento/MessageQueue/etc/di.xml | 6 + .../Shell/CommandRendererBackground.php | 23 +--- .../Unit/CommandRendererBackgroundTest.php | 51 +------- 6 files changed, 176 insertions(+), 70 deletions(-) create mode 100644 app/code/Magento/Cron/Shell/CommandRendererBackground.php create mode 100644 app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php diff --git a/app/code/Magento/Cron/Shell/CommandRendererBackground.php b/app/code/Magento/Cron/Shell/CommandRendererBackground.php new file mode 100644 index 0000000000000..32196128980df --- /dev/null +++ b/app/code/Magento/Cron/Shell/CommandRendererBackground.php @@ -0,0 +1,46 @@ +filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath(); + $logFile = escapeshellarg($logDir . 'magento.cron.' . $groupId . '.log'); + } + + return $this->osInfo->isWindows() ? + 'start /B "magento background task" ' . $command + : str_replace('2>&1', ">> $logFile 2>&1 &", $command); + } +} diff --git a/app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php b/app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php new file mode 100644 index 0000000000000..bf6a7abf65423 --- /dev/null +++ b/app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php @@ -0,0 +1,113 @@ +osInfo = $this->getMockBuilder(OsInfo::class) + ->getMock(); + + $directoryMock = $this->getMockBuilder(ReadInterface::class) + ->getMock(); + $directoryMock->expects($this->any()) + ->method('getAbsolutePath') + ->willReturn($this->logPath); + + $this->filesystem = $this->getMockBuilder(Filesystem::class) + ->disableOriginalConstructor() + ->getMock(); + $this->filesystem->expects($this->any()) + ->method('getDirectoryRead') + ->willReturn($directoryMock); + } + + /** + * @covers ::render + * @dataProvider commandPerOsTypeDataProvider + * + * @param bool $isWindows + * @param string $expectedResults + * @param string[] $arguments + */ + public function testRender($isWindows, $expectedResults, $arguments) + { + $this->osInfo->expects($this->once()) + ->method('isWindows') + ->willReturn($isWindows); + + $commandRenderer = new CommandRendererBackground($this->filesystem, $this->osInfo); + $this->assertEquals( + $expectedResults, + $commandRenderer->render($this->testCommand, $arguments) + ); + } + + /** + * Data provider for each os type + * + * @return array + */ + public function commandPerOsTypeDataProvider() + { + return [ + 'windows' => [ + true, + 'start /B "magento background task" ' . $this->testCommand . ' 2>&1', + [], + ], + 'unix-without-group-name' => [ + false, + $this->testCommand . ' >> /dev/null 2>&1 &', + [], + ], + 'unix-with-group-name' => [ + false, + $this->testCommand . " >> '{$this->logPath}magento.cron.group-name.log' 2>&1 &", + ['php-executable', 'script-path', 'group-name'], + ], + ]; + } +} diff --git a/app/code/Magento/Cron/etc/di.xml b/app/code/Magento/Cron/etc/di.xml index 903ea478c4b60..73795e43a2640 100644 --- a/app/code/Magento/Cron/etc/di.xml +++ b/app/code/Magento/Cron/etc/di.xml @@ -28,15 +28,14 @@ - - + - Magento\Framework\Shell\CommandRendererBackground + Magento\Cron\Shell\CommandRendererBackground - shellBackground + shellBackgroundCron Magento\Cron\Model\VirtualLogger diff --git a/app/code/Magento/MessageQueue/etc/di.xml b/app/code/Magento/MessageQueue/etc/di.xml index caee6f7820c3b..7d4e4ca08b938 100644 --- a/app/code/Magento/MessageQueue/etc/di.xml +++ b/app/code/Magento/MessageQueue/etc/di.xml @@ -43,6 +43,12 @@ RefreshLock + + + + Magento\Framework\Shell\CommandRendererBackground + + shellBackground diff --git a/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php b/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php index 84f97320a0dab..5b61c62dae313 100644 --- a/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php +++ b/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php @@ -5,31 +5,20 @@ */ namespace Magento\Framework\Shell; -use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\Filesystem; use Magento\Framework\OsInfo; class CommandRendererBackground extends CommandRenderer { - /** - * @var Filesystem - */ - protected $filesystem; - /** * @var \Magento\Framework\OsInfo */ protected $osInfo; /** - * @param Filesystem $filesystem * @param OsInfo $osInfo */ - public function __construct( - Filesystem $filesystem, - OsInfo $osInfo - ) { - $this->filesystem = $filesystem; + public function __construct(OsInfo $osInfo) + { $this->osInfo = $osInfo; } @@ -44,14 +33,8 @@ public function render($command, array $arguments = []) { $command = parent::render($command, $arguments); - $logFile = '/dev/null'; - if ($groupId = $arguments[2] ?? null) { - $logDir = $this->filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath(); - $logFile = escapeshellarg($logDir . 'magento.cron.' . $groupId . '.log'); - } - return $this->osInfo->isWindows() ? 'start /B "magento background task" ' . $command - : str_replace('2>&1', ">> $logFile 2>&1 &", $command); + : str_replace('2>&1', '> /dev/null &', $command); } } diff --git a/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php b/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php index c83a064afae7f..c737bc9c4461e 100644 --- a/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php +++ b/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php @@ -7,8 +7,6 @@ namespace Magento\Framework\Shell\Test\Unit; -use Magento\Framework\Filesystem; -use Magento\Framework\Filesystem\Directory\ReadInterface; use Magento\Framework\OsInfo; use Magento\Framework\Shell\CommandRendererBackground; use PHPUnit\Framework\MockObject\MockObject; @@ -16,13 +14,6 @@ class CommandRendererBackgroundTest extends TestCase { - /** - * Test path to Magento's var/log directory - * - * @var string - */ - protected $logPath = '/path/to/magento/var/log/'; - /** * Test data for command * @@ -30,11 +21,6 @@ class CommandRendererBackgroundTest extends TestCase */ protected $testCommand = 'php -r test.php'; - /** - * @var Filesystem|MockObject - */ - protected $filesystem; - /** * @var OsInfo|MockObject */ @@ -44,37 +30,23 @@ protected function setUp(): void { $this->osInfo = $this->getMockBuilder(OsInfo::class) ->getMock(); - - $directoryMock = $this->getMockBuilder(ReadInterface::class) - ->getMock(); - $directoryMock->expects($this->any()) - ->method('getAbsolutePath') - ->willReturn($this->logPath); - - $this->filesystem = $this->getMockBuilder(Filesystem::class) - ->disableOriginalConstructor() - ->getMock(); - $this->filesystem->expects($this->any()) - ->method('getDirectoryRead') - ->willReturn($directoryMock); } /** * @dataProvider commandPerOsTypeDataProvider * @param bool $isWindows * @param string $expectedResults - * @param string[] $arguments */ - public function testRender($isWindows, $expectedResults, $arguments) + public function testRender($isWindows, $expectedResults) { $this->osInfo->expects($this->once()) ->method('isWindows') ->willReturn($isWindows); - $commandRenderer = new CommandRendererBackground($this->filesystem, $this->osInfo); + $commandRenderer = new CommandRendererBackground($this->osInfo); $this->assertEquals( $expectedResults, - $commandRenderer->render($this->testCommand, $arguments) + $commandRenderer->render($this->testCommand) ); } @@ -86,21 +58,8 @@ public function testRender($isWindows, $expectedResults, $arguments) public function commandPerOsTypeDataProvider() { return [ - 'windows' => [ - true, - 'start /B "magento background task" ' . $this->testCommand . ' 2>&1', - [], - ], - 'unix-without-group-name' => [ - false, - $this->testCommand . ' >> /dev/null 2>&1 &', - [], - ], - 'unix-with-group-name' => [ - false, - $this->testCommand . " >> '{$this->logPath}magento.cron.group-name.log' 2>&1 &", - ['php-executable', 'script-path', 'group-name'], - ], + 'windows' => [true, 'start /B "magento background task" ' . $this->testCommand . ' 2>&1'], + 'unix' => [false, $this->testCommand . ' > /dev/null &'], ]; } } From 485869e8c3c61a24bc6efbe79b77a1d3ecf520f1 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 16 May 2023 11:22:44 +0100 Subject: [PATCH 012/656] Adhere to coding standard --- .../Magento/Cron/Shell/CommandRendererBackground.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Cron/Shell/CommandRendererBackground.php b/app/code/Magento/Cron/Shell/CommandRendererBackground.php index 32196128980df..c492531e1479f 100644 --- a/app/code/Magento/Cron/Shell/CommandRendererBackground.php +++ b/app/code/Magento/Cron/Shell/CommandRendererBackground.php @@ -1,8 +1,10 @@ filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath(); + // @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged $logFile = escapeshellarg($logDir . 'magento.cron.' . $groupId . '.log'); } From 64df5bb62e5684d890e3bac0365dd115380a2d66 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 16 May 2023 13:34:27 +0100 Subject: [PATCH 013/656] Correct namespace --- .../Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php b/app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php index bf6a7abf65423..02358ca464069 100644 --- a/app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php +++ b/app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Magento\Cron\Shell\Test\Unit; +namespace Magento\Cron\Test\Unit\Shell; use Magento\Cron\Shell\CommandRendererBackground; use Magento\Framework\Filesystem; @@ -17,7 +17,7 @@ use PHPUnit\Framework\TestCase; /** - * @covers CommandRendererBackground + * @covers \Magento\Cron\Shell\CommandRendererBackground */ class CommandRendererBackgroundTest extends TestCase { From 8029ce9fb0cb774f47c9024a56cff67d45203404 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 16 May 2023 15:16:49 +0100 Subject: [PATCH 014/656] Add 'declare(strict_types=1);' --- app/code/Magento/Cron/Shell/CommandRendererBackground.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Cron/Shell/CommandRendererBackground.php b/app/code/Magento/Cron/Shell/CommandRendererBackground.php index c492531e1479f..b8f792b9c0a25 100644 --- a/app/code/Magento/Cron/Shell/CommandRendererBackground.php +++ b/app/code/Magento/Cron/Shell/CommandRendererBackground.php @@ -5,6 +5,8 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Cron\Shell; use Magento\Framework\App\Filesystem\DirectoryList; From 752821b64b13ea4f28abdef2869be8d9704bde3f Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 17 May 2023 10:53:16 +0100 Subject: [PATCH 015/656] Move global/api virtualType to app/etc/di.xml --- app/code/Magento/MessageQueue/etc/di.xml | 6 ------ app/etc/di.xml | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/MessageQueue/etc/di.xml b/app/code/Magento/MessageQueue/etc/di.xml index 7d4e4ca08b938..caee6f7820c3b 100644 --- a/app/code/Magento/MessageQueue/etc/di.xml +++ b/app/code/Magento/MessageQueue/etc/di.xml @@ -43,12 +43,6 @@ RefreshLock - - - - Magento\Framework\Shell\CommandRendererBackground - - shellBackground diff --git a/app/etc/di.xml b/app/etc/di.xml index c74ce0d679439..19bcc8a875cb9 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -2008,4 +2008,10 @@ + + + + Magento\Framework\Shell\CommandRendererBackground + + From e44ac4885e52c2d51cf7d2c73499dcd4e51180fd Mon Sep 17 00:00:00 2001 From: engcom-Charlie Date: Wed, 24 May 2023 16:30:06 +0530 Subject: [PATCH 016/656] Draft:Increase the page load time --- ...ontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml index e5f464920c3ee..62d53b6adb706 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml @@ -83,7 +83,7 @@ - + From 3925deb7520d76dc815bfdef5d696deb32b88e87 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 24 May 2023 15:19:50 +0100 Subject: [PATCH 017/656] Revert "Draft:Increase the page load time" This reverts commit e44ac4885e52c2d51cf7d2c73499dcd4e51180fd. --- ...ontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml index 62d53b6adb706..e5f464920c3ee 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml @@ -83,7 +83,7 @@ - + From 4746e944be4edd5315d8e57b7885998ee1702a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szubert?= Date: Sun, 10 Dec 2023 19:10:50 +0100 Subject: [PATCH 018/656] #36947 Fixed timezone of order_date field returned from graphql customerOrders query --- .../Magento/SalesGraphQl/Model/Formatter/Order.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/SalesGraphQl/Model/Formatter/Order.php b/app/code/Magento/SalesGraphQl/Model/Formatter/Order.php index c5d0df668afac..04566c3d94485 100644 --- a/app/code/Magento/SalesGraphQl/Model/Formatter/Order.php +++ b/app/code/Magento/SalesGraphQl/Model/Formatter/Order.php @@ -7,6 +7,8 @@ namespace Magento\SalesGraphQl\Model\Formatter; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; use Magento\Sales\Api\Data\OrderInterface; use Magento\SalesGraphQl\Model\Order\OrderAddress; use Magento\SalesGraphQl\Model\Order\OrderPayments; @@ -26,16 +28,21 @@ class Order */ private $orderPayments; + private TimezoneInterface $timezone; + /** * @param OrderAddress $orderAddress * @param OrderPayments $orderPayments + * @param TimezoneInterface|null $timezone */ public function __construct( OrderAddress $orderAddress, - OrderPayments $orderPayments + OrderPayments $orderPayments, + TimezoneInterface $timezone = null ) { $this->orderAddress = $orderAddress; $this->orderPayments = $orderPayments; + $this->timezone = $timezone ?: ObjectManager::getInstance()->get(TimezoneInterface::class); } /** @@ -52,7 +59,7 @@ public function format(OrderInterface $orderModel): array 'id' => base64_encode($orderModel->getEntityId()), 'increment_id' => $orderModel->getIncrementId(), 'number' => $orderModel->getIncrementId(), - 'order_date' => $orderModel->getCreatedAt(), + 'order_date' => $this->timezone->date($orderModel->getCreatedAt()), 'order_number' => $orderModel->getIncrementId(), 'status' => $orderModel->getStatusLabel(), 'shipping_method' => $orderModel->getShippingDescription(), From 0b9fbb73dbd0de588548edd6377a05e0b6a0315a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Szubert?= Date: Sun, 10 Dec 2023 19:18:29 +0100 Subject: [PATCH 019/656] #36947 Added timezone parsing to creditmemo, invoice, shipment comments dates --- .../Model/Resolver/CreditMemo/CreditMemoComments.php | 12 +++++++++++- .../Magento/SalesGraphQl/Model/Resolver/Invoices.php | 12 +++++++++++- .../SalesGraphQl/Model/Resolver/Shipments.php | 12 +++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/SalesGraphQl/Model/Resolver/CreditMemo/CreditMemoComments.php b/app/code/Magento/SalesGraphQl/Model/Resolver/CreditMemo/CreditMemoComments.php index 2c9fedf61b502..ff8850a74ff47 100644 --- a/app/code/Magento/SalesGraphQl/Model/Resolver/CreditMemo/CreditMemoComments.php +++ b/app/code/Magento/SalesGraphQl/Model/Resolver/CreditMemo/CreditMemoComments.php @@ -7,10 +7,12 @@ namespace Magento\SalesGraphQl\Model\Resolver\CreditMemo; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; use Magento\Sales\Api\Data\CreditmemoInterface; /** @@ -18,6 +20,14 @@ */ class CreditMemoComments implements ResolverInterface { + private TimezoneInterface $timezone; + + public function __construct( + TimezoneInterface $timezone = null + ) { + $this->timezone = $timezone ?: ObjectManager::getInstance()->get(TimezoneInterface::class); + } + /** * @inheritDoc */ @@ -40,7 +50,7 @@ public function resolve( if ($comment->getIsVisibleOnFront()) { $comments[] = [ 'message' => $comment->getComment(), - 'timestamp' => $comment->getCreatedAt() + 'timestamp' => $this->timezone->date($comment->getCreatedAt()) ]; } } diff --git a/app/code/Magento/SalesGraphQl/Model/Resolver/Invoices.php b/app/code/Magento/SalesGraphQl/Model/Resolver/Invoices.php index 02d0f7687894a..5421678188272 100644 --- a/app/code/Magento/SalesGraphQl/Model/Resolver/Invoices.php +++ b/app/code/Magento/SalesGraphQl/Model/Resolver/Invoices.php @@ -7,10 +7,12 @@ namespace Magento\SalesGraphQl\Model\Resolver; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; use Magento\Sales\Api\Data\OrderInterface; use Magento\Sales\Api\Data\InvoiceInterface; @@ -19,6 +21,14 @@ */ class Invoices implements ResolverInterface { + private TimezoneInterface $timezone; + + public function __construct( + TimezoneInterface $timezone = null + ) { + $this->timezone = $timezone ?: ObjectManager::getInstance()->get(TimezoneInterface::class); + } + /** * @inheritDoc */ @@ -61,7 +71,7 @@ private function getInvoiceComments(InvoiceInterface $invoice): array foreach ($invoice->getComments() as $comment) { if ($comment->getIsVisibleOnFront()) { $comments[] = [ - 'timestamp' => $comment->getCreatedAt(), + 'timestamp' => $this->timezone->date($comment->getCreatedAt()), 'message' => $comment->getComment() ]; } diff --git a/app/code/Magento/SalesGraphQl/Model/Resolver/Shipments.php b/app/code/Magento/SalesGraphQl/Model/Resolver/Shipments.php index 8b6aaad09c304..e9cca8cd42ddb 100644 --- a/app/code/Magento/SalesGraphQl/Model/Resolver/Shipments.php +++ b/app/code/Magento/SalesGraphQl/Model/Resolver/Shipments.php @@ -7,10 +7,12 @@ namespace Magento\SalesGraphQl\Model\Resolver; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; use Magento\Sales\Api\Data\ShipmentInterface; use Magento\Sales\Model\Order; @@ -19,6 +21,14 @@ */ class Shipments implements ResolverInterface { + private TimezoneInterface $timezone; + + public function __construct( + TimezoneInterface $timezone = null + ) { + $this->timezone = $timezone ?: ObjectManager::getInstance()->get(TimezoneInterface::class); + } + /** * @inheritDoc */ @@ -62,7 +72,7 @@ private function getShipmentComments(ShipmentInterface $shipment): array foreach ($shipment->getComments() as $comment) { if ($comment->getIsVisibleOnFront()) { $comments[] = [ - 'timestamp' => $comment->getCreatedAt(), + 'timestamp' => $this->timezone->date($comment->getCreatedAt()), 'message' => $comment->getComment() ]; } From 0b3eb604a1f913b42b88292dcebcbb328e7f7271 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Sun, 7 Apr 2024 14:09:07 +0300 Subject: [PATCH 020/656] round image dimensions to make them compatible with php 8 (gd2/imagemagik) --- .../Magento/Framework/Image/Adapter/AbstractAdapter.php | 4 ++-- .../Magento/Framework/Image/Adapter/ImageMagick.php | 8 ++++---- .../Framework/Image/Test/Unit/Adapter/AbstractTest.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php b/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php index 3caab760f0108..c58ff8f4baa4c 100644 --- a/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php +++ b/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php @@ -577,9 +577,9 @@ protected function _adaptResizeValues($frameWidth, $frameHeight) return [ 'src' => ['x' => $srcX, 'y' => $srcY], - 'dst' => ['x' => $dstX, 'y' => $dstY, 'width' => $dstWidth, 'height' => $dstHeight], + 'dst' => ['x' => $dstX, 'y' => $dstY, 'width' => round($dstWidth), 'height' => round($dstHeight)], // size for new image - 'frame' => ['width' => $frameWidth, 'height' => $frameHeight] + 'frame' => ['width' => round($frameWidth), 'height' => round($frameHeight)] ]; } diff --git a/lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php b/lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php index d81ceea37ddc6..d0b88a34c09d8 100644 --- a/lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php +++ b/lib/internal/Magento/Framework/Image/Adapter/ImageMagick.php @@ -212,14 +212,14 @@ public function resize($frameWidth = null, $frameHeight = null) $newImage = new \Imagick(); $newImage->newImage( - floor($dims['frame']['width']), - floor($dims['frame']['height']), + $dims['frame']['width'], + $dims['frame']['height'], $this->_imageHandler->getImageBackgroundColor() ); $this->_imageHandler->resizeImage( - floor($dims['dst']['width']), - floor($dims['dst']['height']), + $dims['dst']['width'], + $dims['dst']['height'], \Imagick::FILTER_CUBIC, self::BLUR_FACTOR ); diff --git a/lib/internal/Magento/Framework/Image/Test/Unit/Adapter/AbstractTest.php b/lib/internal/Magento/Framework/Image/Test/Unit/Adapter/AbstractTest.php index bebc597138a05..fbfc8e9b7c101 100644 --- a/lib/internal/Magento/Framework/Image/Test/Unit/Adapter/AbstractTest.php +++ b/lib/internal/Magento/Framework/Image/Test/Unit/Adapter/AbstractTest.php @@ -98,7 +98,7 @@ public function adaptResizeValuesDataProvider() 'frame' => ['width' => 135, 'height' => 135], ]; - return [[135, null, $expected], [null, 135, $expected]]; + return [[134.5, null, $expected], [null, 134.5, $expected]]; } /** From 78ca8287c765b88529be54df4241adb1b304acb2 Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Sun, 7 Apr 2024 15:12:07 +0300 Subject: [PATCH 021/656] phpstan fixes. --- .../Image/Adapter/AbstractAdapter.php | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php b/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php index c58ff8f4baa4c..60587b86e1c84 100644 --- a/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php +++ b/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php @@ -27,25 +27,25 @@ abstract class AbstractAdapter implements AdapterInterface * Position constants. * Used mainly for watermarks */ - const POSITION_TOP_LEFT = 'top-left'; + public const POSITION_TOP_LEFT = 'top-left'; - const POSITION_TOP_RIGHT = 'top-right'; + public const POSITION_TOP_RIGHT = 'top-right'; - const POSITION_BOTTOM_LEFT = 'bottom-left'; + public const POSITION_BOTTOM_LEFT = 'bottom-left'; - const POSITION_BOTTOM_RIGHT = 'bottom-right'; + public const POSITION_BOTTOM_RIGHT = 'bottom-right'; - const POSITION_STRETCH = 'stretch'; + public const POSITION_STRETCH = 'stretch'; - const POSITION_TILE = 'tile'; + public const POSITION_TILE = 'tile'; - const POSITION_CENTER = 'center'; + public const POSITION_CENTER = 'center'; /**#@-*/ /** * The size of the font to use as default */ - const DEFAULT_FONT_SIZE = 15; + public const DEFAULT_FONT_SIZE = 15; /** * @var int @@ -274,8 +274,7 @@ abstract public function getColorAt($x, $y); */ public function __construct( \Magento\Framework\Filesystem $filesystem, - \Psr\Log\LoggerInterface $logger, - array $data = [] + \Psr\Log\LoggerInterface $logger ) { $this->_filesystem = $filesystem; $this->logger = $logger; @@ -622,10 +621,7 @@ protected function _checkAspectRatio($frameWidth, $frameHeight) */ protected function _checkDimensions($frameWidth, $frameHeight) { - if ($frameWidth !== null && $frameWidth <= 0 || - $frameHeight !== null && $frameHeight <= 0 || - empty($frameWidth) && empty($frameHeight) - ) { + if ($frameWidth !== null && $frameWidth <= 0 || $frameHeight !== null && $frameHeight <= 0) { //phpcs:ignore Magento2.Exceptions.DirectThrow throw new \InvalidArgumentException('Invalid image dimensions.'); } From fd4a69775e8ff7e58aa1de01872899d01461f16e Mon Sep 17 00:00:00 2001 From: Kostadin Bashev Date: Sun, 7 Apr 2024 15:56:48 +0300 Subject: [PATCH 022/656] phpcs fixes. --- .../Image/Adapter/AbstractAdapter.php | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php b/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php index 60587b86e1c84..9a7795349457a 100644 --- a/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php +++ b/lib/internal/Magento/Framework/Image/Adapter/AbstractAdapter.php @@ -8,11 +8,14 @@ namespace Magento\Framework\Image\Adapter; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\Directory\Write; +use Psr\Log\LoggerInterface; /** * Image abstract adapter * - * @api * @SuppressWarnings(PHPMD.TooManyFields) */ abstract class AbstractAdapter implements AdapterInterface @@ -150,17 +153,17 @@ abstract class AbstractAdapter implements AdapterInterface /** * Filesystem instance * - * @var \Magento\Framework\Filesystem + * @var Filesystem */ protected $_filesystem; /** - * @var \Magento\Framework\Filesystem\Directory\Write + * @var Write */ protected $directoryWrite; /** - * @var \Psr\Log\LoggerInterface + * @var LoggerInterface */ protected $logger; @@ -267,14 +270,14 @@ abstract public function getColorAt($x, $y); /** * Initialize default values * - * @param \Magento\Framework\Filesystem $filesystem - * @param \Psr\Log\LoggerInterface $logger - * @param array $data + * @param Filesystem $filesystem + * @param LoggerInterface $logger + * @throws FileSystemException * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( - \Magento\Framework\Filesystem $filesystem, - \Psr\Log\LoggerInterface $logger + Filesystem $filesystem, + LoggerInterface $logger ) { $this->_filesystem = $filesystem; $this->logger = $logger; @@ -686,7 +689,7 @@ protected function _prepareDestination($destination = null, $newName = null) if (!is_writable($destination)) { try { $this->directoryWrite->create($this->directoryWrite->getRelativePath($destination)); - } catch (\Magento\Framework\Exception\FileSystemException $e) { + } catch (FileSystemException $e) { $this->logger->critical($e); //phpcs:ignore Magento2.Exceptions.DirectThrow throw new \DomainException( From 19745e8ca4c9aa5bd4b00f7010c4041f859ee754 Mon Sep 17 00:00:00 2001 From: franciscof Date: Sat, 4 May 2024 02:45:36 -0300 Subject: [PATCH 023/656] feat: update success message with field changed ref --- .../Adminhtml/System/Account/Save.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php index d95b0541c2c76..9254990d99b18 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php @@ -81,7 +81,32 @@ public function execute() } else { $user->save(); $user->sendNotificationEmailsIfRequired(); - $this->messageManager->addSuccessMessage(__('You saved the account.')); + + // Check which fields were modified after saving + $modifiedFields = []; + $propertiesToCheck = ['password', 'username', 'firstname', 'lastname', 'email']; + + foreach ($propertiesToCheck as $property) { + if ($user->getOrigData($property) !== $user->{'get' . ucfirst($property)}()) { + $modifiedFields[] = $property; + } + } + + if (!empty($modifiedFields)) { + $countModifiedFields = count($modifiedFields); + $successMessage = ''; + // validate how many fields were modified to display them correctly + if ($countModifiedFields > 1) { + $lastModifiedField = array_pop($modifiedFields); + $modifiedFieldsText = implode(', ', $modifiedFields); + $successMessage = __('The %1, and %2 of this account have been modified successfully.', $modifiedFieldsText, $lastModifiedField); + } else { + $successMessage = __('The %1 of this account has been modified successfully.', reset($modifiedFields)); + } + $this->messageManager->addSuccessMessage($successMessage); + } else { + $this->messageManager->addSuccessMessage(__('You saved the account.')); + } } } catch (UserLockedException $e) { $this->_auth->logout(); From 265ed1acab79091d0813d3fd35888c2b8c1b7d38 Mon Sep 17 00:00:00 2001 From: franciscof Date: Sat, 4 May 2024 11:53:15 -0300 Subject: [PATCH 024/656] fix coding-standard --- .../Controller/Adminhtml/System/Account/Save.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php index 9254990d99b18..e4b8021aed14b 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php @@ -25,8 +25,9 @@ class Save extends \Magento\Backend\Controller\Adminhtml\System\Account /** * Get security cookie * + * @deprecated 100.1.0 The method getSecurityCookie() is deprecated and no longer needed. + * Use dependency injection to get an instance of SecurityCookie instead. * @return SecurityCookie - * @deprecated 100.1.0 */ private function getSecurityCookie() { @@ -85,13 +86,13 @@ public function execute() // Check which fields were modified after saving $modifiedFields = []; $propertiesToCheck = ['password', 'username', 'firstname', 'lastname', 'email']; - + foreach ($propertiesToCheck as $property) { if ($user->getOrigData($property) !== $user->{'get' . ucfirst($property)}()) { $modifiedFields[] = $property; } } - + if (!empty($modifiedFields)) { $countModifiedFields = count($modifiedFields); $successMessage = ''; @@ -99,9 +100,13 @@ public function execute() if ($countModifiedFields > 1) { $lastModifiedField = array_pop($modifiedFields); $modifiedFieldsText = implode(', ', $modifiedFields); - $successMessage = __('The %1, and %2 of this account have been modified successfully.', $modifiedFieldsText, $lastModifiedField); + $successMessage = + __('The %1 and %2 of this account have been modified successfully.', + $modifiedFieldsText,$lastModifiedField); } else { - $successMessage = __('The %1 of this account has been modified successfully.', reset($modifiedFields)); + $successMessage = + __('The %1 of this account has been modified successfully.', + reset($modifiedFields)); } $this->messageManager->addSuccessMessage($successMessage); } else { From ffbcc7e571da84e1bcf8f661cbfeab07a7f7ad4e Mon Sep 17 00:00:00 2001 From: Oleksandr Dubovyk Date: Thu, 16 May 2024 15:54:49 -0500 Subject: [PATCH 025/656] ACP2E-2974 --- .../Entity/Attribute/OptionValueProvider.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php index 554896a704094..ea3c7afae7156 100644 --- a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php +++ b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php @@ -21,12 +21,20 @@ class OptionValueProvider */ private $connection; + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + private $storeManager; /** * @param ResourceConnection $connection + * @param \Magento\Store\Model\StoreManagerInterface $storeManager */ - public function __construct(ResourceConnection $connection) - { + public function __construct( + ResourceConnection $connection, + \Magento\Store\Model\StoreManagerInterface $storeManager + ) { $this->connection = $connection->getConnection(); + $this->storeManager = $storeManager; } /** @@ -37,11 +45,13 @@ public function __construct(ResourceConnection $connection) */ public function get(int $optionId): ?string { + $storeId = $this->storeManager->getStore()->getId(); $select = $this->connection->select() - ->from($this->connection->getTableName('eav_attribute_option_value'), 'value') + ->from($this->connection->getTableName('eav_attribute_option_value'), ['store_id', 'value']) ->where('option_id = ?', $optionId); - $result = $this->connection->fetchOne($select); + $records = $this->connection->fetchAssoc($select); + $result = $records[$storeId]['value']; if ($result !== false) { return $result; From 54c54e7c2df62cb0a164ad8dfdfd727a89e058e9 Mon Sep 17 00:00:00 2001 From: Oleksandr Dubovyk Date: Mon, 20 May 2024 16:40:15 -0500 Subject: [PATCH 026/656] ACP2E-2974 --- .../Entity/Attribute/OptionValueProvider.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php index ea3c7afae7156..af4fe7ff3fa3c 100644 --- a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php +++ b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php @@ -51,11 +51,12 @@ public function get(int $optionId): ?string ->where('option_id = ?', $optionId); $records = $this->connection->fetchAssoc($select); - $result = $records[$storeId]['value']; - - if ($result !== false) { - return $result; + if (!empty($records)) { + return $records[$storeId]['value']; } +// if ($result !== false) { +// return $result; +// } return null; } From 2196f95f74590e3610cab453aa3f051217f66bc0 Mon Sep 17 00:00:00 2001 From: Oleksandr Dubovyk Date: Tue, 21 May 2024 16:10:09 -0500 Subject: [PATCH 027/656] ACP2E-2974 --- .../Entity/Attribute/OptionValueProvider.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php index af4fe7ff3fa3c..3a49e5290838c 100644 --- a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php +++ b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/OptionValueProvider.php @@ -51,13 +51,10 @@ public function get(int $optionId): ?string ->where('option_id = ?', $optionId); $records = $this->connection->fetchAssoc($select); - if (!empty($records)) { - return $records[$storeId]['value']; + if (empty($records)) { + return null; } -// if ($result !== false) { -// return $result; -// } - return null; + return $records[$storeId]['value'] ?? $records[0]['value']; } } From db1ea4ec5da3345803a65a4d8da7b128da0bd54a Mon Sep 17 00:00:00 2001 From: ergohack Date: Mon, 3 Jun 2024 11:42:37 -0600 Subject: [PATCH 028/656] avoid a misconfiguration infinite loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The virtual type configurations are not supposed to be self‑referential, … but if they ever are this function will spin in an infinite loop. --- lib/internal/Magento/Framework/ObjectManager/Config/Config.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/internal/Magento/Framework/ObjectManager/Config/Config.php b/lib/internal/Magento/Framework/ObjectManager/Config/Config.php index dd7df3a3af535..e924a313a627c 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Config/Config.php +++ b/lib/internal/Magento/Framework/ObjectManager/Config/Config.php @@ -156,6 +156,7 @@ public function isShared($type) public function getInstanceType($instanceName) { while (isset($this->_virtualTypes[$instanceName])) { + if ($instanceName == $this->_virtualTypes[$instanceName]) break; $instanceName = $this->_virtualTypes[$instanceName]; } return $instanceName; From 1f18dbf9b22e43f7664b08cac8ce20a07e41e36e Mon Sep 17 00:00:00 2001 From: John Robertson Date: Fri, 7 Jun 2024 11:15:59 -0600 Subject: [PATCH 029/656] replaced loop exit with a thrown exception --- .../Magento/Framework/ObjectManager/Config/Config.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/ObjectManager/Config/Config.php b/lib/internal/Magento/Framework/ObjectManager/Config/Config.php index e924a313a627c..bea9afb48b226 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Config/Config.php +++ b/lib/internal/Magento/Framework/ObjectManager/Config/Config.php @@ -152,11 +152,17 @@ public function isShared($type) * * @param string $instanceName * @return mixed + * @throws \LogicException */ public function getInstanceType($instanceName) { while (isset($this->_virtualTypes[$instanceName])) { - if ($instanceName == $this->_virtualTypes[$instanceName]) break; + if ($instanceName == $this->_virtualTypes[$instanceName]) { + throw new \LogicException( + 'unsupported self-referencing virutal type: ' + .$instanceName + ); + } $instanceName = $this->_virtualTypes[$instanceName]; } return $instanceName; From 28342644181e801a5533aeeb88dedacfce1c1992 Mon Sep 17 00:00:00 2001 From: John Robertson Date: Sat, 8 Jun 2024 13:38:02 -0600 Subject: [PATCH 030/656] corrected spelling of exception message and moved to a strict compare --- .../Magento/Framework/ObjectManager/Config/Config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/ObjectManager/Config/Config.php b/lib/internal/Magento/Framework/ObjectManager/Config/Config.php index bea9afb48b226..8fc33003806ab 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Config/Config.php +++ b/lib/internal/Magento/Framework/ObjectManager/Config/Config.php @@ -157,9 +157,9 @@ public function isShared($type) public function getInstanceType($instanceName) { while (isset($this->_virtualTypes[$instanceName])) { - if ($instanceName == $this->_virtualTypes[$instanceName]) { + if ($instanceName === $this->_virtualTypes[$instanceName]) { throw new \LogicException( - 'unsupported self-referencing virutal type: ' + 'unsupported self-referencing virtual type: ' .$instanceName ); } From 9b492e45419fb5e73bbf2084829bd4c18317342c Mon Sep 17 00:00:00 2001 From: franciscof Date: Wed, 19 Jun 2024 16:26:57 -0300 Subject: [PATCH 031/656] fix coding-standard --- .../Backend/Controller/Adminhtml/System/Account/Save.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php index e4b8021aed14b..fe877b4e39a64 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php @@ -11,11 +11,11 @@ use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Exception\State\UserLockedException; use Magento\Security\Model\SecurityCookie; - +use Magento\Framework\App\Action\HttpPostActionInterface; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends \Magento\Backend\Controller\Adminhtml\System\Account +class Save extends \Magento\Backend\Controller\Adminhtml\System\Account implements HttpPostActionInterface { /** * @var SecurityCookie From 27fc59f214d2bbad6ad8b9c18918f35c86d22a3e Mon Sep 17 00:00:00 2001 From: franciscof Date: Wed, 19 Jun 2024 17:43:35 -0300 Subject: [PATCH 032/656] fix coding-standard --- .../Adminhtml/System/Account/Save.php | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php index fe877b4e39a64..e4c7be18dd092 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php @@ -12,6 +12,7 @@ use Magento\Framework\Exception\State\UserLockedException; use Magento\Security\Model\SecurityCookie; use Magento\Framework\App\Action\HttpPostActionInterface; + /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ @@ -25,8 +26,10 @@ class Save extends \Magento\Backend\Controller\Adminhtml\System\Account implemen /** * Get security cookie * - * @deprecated 100.1.0 The method getSecurityCookie() is deprecated and no longer needed. - * Use dependency injection to get an instance of SecurityCookie instead. + * @deprecated 100.1.0 This method is deprecated because dependency injection should be used instead of + * directly accessing the SecurityCookie instance. + * Use dependency injection to get an instance of SecurityCookie. + * @see \Magento\Backend\Controller\Adminhtml\System\Account::__construct() * @return SecurityCookie */ private function getSecurityCookie() @@ -100,13 +103,16 @@ public function execute() if ($countModifiedFields > 1) { $lastModifiedField = array_pop($modifiedFields); $modifiedFieldsText = implode(', ', $modifiedFields); - $successMessage = - __('The %1 and %2 of this account have been modified successfully.', - $modifiedFieldsText,$lastModifiedField); + $successMessage = __( + 'The %1 and %2 of this account have been modified successfully.', + $modifiedFieldsText, + $lastModifiedField + ); } else { - $successMessage = - __('The %1 of this account has been modified successfully.', - reset($modifiedFields)); + $successMessage = __( + 'The %1 of this account has been modified successfully.', + reset($modifiedFields) + ); } $this->messageManager->addSuccessMessage($successMessage); } else { From 41fc2788b0cab9f19dc51beaa9811a6b3d26918c Mon Sep 17 00:00:00 2001 From: franciscof Date: Sat, 4 May 2024 02:45:36 -0300 Subject: [PATCH 033/656] feat: update success message with field changed ref --- .../Adminhtml/System/Account/Save.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php index d95b0541c2c76..9254990d99b18 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php @@ -81,7 +81,32 @@ public function execute() } else { $user->save(); $user->sendNotificationEmailsIfRequired(); - $this->messageManager->addSuccessMessage(__('You saved the account.')); + + // Check which fields were modified after saving + $modifiedFields = []; + $propertiesToCheck = ['password', 'username', 'firstname', 'lastname', 'email']; + + foreach ($propertiesToCheck as $property) { + if ($user->getOrigData($property) !== $user->{'get' . ucfirst($property)}()) { + $modifiedFields[] = $property; + } + } + + if (!empty($modifiedFields)) { + $countModifiedFields = count($modifiedFields); + $successMessage = ''; + // validate how many fields were modified to display them correctly + if ($countModifiedFields > 1) { + $lastModifiedField = array_pop($modifiedFields); + $modifiedFieldsText = implode(', ', $modifiedFields); + $successMessage = __('The %1, and %2 of this account have been modified successfully.', $modifiedFieldsText, $lastModifiedField); + } else { + $successMessage = __('The %1 of this account has been modified successfully.', reset($modifiedFields)); + } + $this->messageManager->addSuccessMessage($successMessage); + } else { + $this->messageManager->addSuccessMessage(__('You saved the account.')); + } } } catch (UserLockedException $e) { $this->_auth->logout(); From b5e8b655795201a18ebece8836fb6df71734597a Mon Sep 17 00:00:00 2001 From: franciscof Date: Sat, 4 May 2024 11:53:15 -0300 Subject: [PATCH 034/656] fix coding-standard --- .../Controller/Adminhtml/System/Account/Save.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php index 9254990d99b18..e4b8021aed14b 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php @@ -25,8 +25,9 @@ class Save extends \Magento\Backend\Controller\Adminhtml\System\Account /** * Get security cookie * + * @deprecated 100.1.0 The method getSecurityCookie() is deprecated and no longer needed. + * Use dependency injection to get an instance of SecurityCookie instead. * @return SecurityCookie - * @deprecated 100.1.0 */ private function getSecurityCookie() { @@ -85,13 +86,13 @@ public function execute() // Check which fields were modified after saving $modifiedFields = []; $propertiesToCheck = ['password', 'username', 'firstname', 'lastname', 'email']; - + foreach ($propertiesToCheck as $property) { if ($user->getOrigData($property) !== $user->{'get' . ucfirst($property)}()) { $modifiedFields[] = $property; } } - + if (!empty($modifiedFields)) { $countModifiedFields = count($modifiedFields); $successMessage = ''; @@ -99,9 +100,13 @@ public function execute() if ($countModifiedFields > 1) { $lastModifiedField = array_pop($modifiedFields); $modifiedFieldsText = implode(', ', $modifiedFields); - $successMessage = __('The %1, and %2 of this account have been modified successfully.', $modifiedFieldsText, $lastModifiedField); + $successMessage = + __('The %1 and %2 of this account have been modified successfully.', + $modifiedFieldsText,$lastModifiedField); } else { - $successMessage = __('The %1 of this account has been modified successfully.', reset($modifiedFields)); + $successMessage = + __('The %1 of this account has been modified successfully.', + reset($modifiedFields)); } $this->messageManager->addSuccessMessage($successMessage); } else { From ed8b2a13c1e0597996f8ed0bce1770f6fb1bef2d Mon Sep 17 00:00:00 2001 From: franciscof Date: Wed, 19 Jun 2024 16:26:57 -0300 Subject: [PATCH 035/656] fix coding-standard --- .../Backend/Controller/Adminhtml/System/Account/Save.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php index e4b8021aed14b..fe877b4e39a64 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php @@ -11,11 +11,11 @@ use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Exception\State\UserLockedException; use Magento\Security\Model\SecurityCookie; - +use Magento\Framework\App\Action\HttpPostActionInterface; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class Save extends \Magento\Backend\Controller\Adminhtml\System\Account +class Save extends \Magento\Backend\Controller\Adminhtml\System\Account implements HttpPostActionInterface { /** * @var SecurityCookie From 36269dcfba32615caef8adb930578ddb374ac969 Mon Sep 17 00:00:00 2001 From: franciscof Date: Wed, 19 Jun 2024 17:43:35 -0300 Subject: [PATCH 036/656] fix coding-standard --- .../Adminhtml/System/Account/Save.php | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php index fe877b4e39a64..e4c7be18dd092 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php @@ -12,6 +12,7 @@ use Magento\Framework\Exception\State\UserLockedException; use Magento\Security\Model\SecurityCookie; use Magento\Framework\App\Action\HttpPostActionInterface; + /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ @@ -25,8 +26,10 @@ class Save extends \Magento\Backend\Controller\Adminhtml\System\Account implemen /** * Get security cookie * - * @deprecated 100.1.0 The method getSecurityCookie() is deprecated and no longer needed. - * Use dependency injection to get an instance of SecurityCookie instead. + * @deprecated 100.1.0 This method is deprecated because dependency injection should be used instead of + * directly accessing the SecurityCookie instance. + * Use dependency injection to get an instance of SecurityCookie. + * @see \Magento\Backend\Controller\Adminhtml\System\Account::__construct() * @return SecurityCookie */ private function getSecurityCookie() @@ -100,13 +103,16 @@ public function execute() if ($countModifiedFields > 1) { $lastModifiedField = array_pop($modifiedFields); $modifiedFieldsText = implode(', ', $modifiedFields); - $successMessage = - __('The %1 and %2 of this account have been modified successfully.', - $modifiedFieldsText,$lastModifiedField); + $successMessage = __( + 'The %1 and %2 of this account have been modified successfully.', + $modifiedFieldsText, + $lastModifiedField + ); } else { - $successMessage = - __('The %1 of this account has been modified successfully.', - reset($modifiedFields)); + $successMessage = __( + 'The %1 of this account has been modified successfully.', + reset($modifiedFields) + ); } $this->messageManager->addSuccessMessage($successMessage); } else { From b717e0dd024aba12df7fa67400674da56edfc804 Mon Sep 17 00:00:00 2001 From: franciscof Date: Wed, 19 Jun 2024 18:57:40 -0300 Subject: [PATCH 037/656] fix coding-standard --- .../Backend/Controller/Adminhtml/System/Account/Save.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php index e4c7be18dd092..6ef8f127e02e9 100644 --- a/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php +++ b/app/code/Magento/Backend/Controller/Adminhtml/System/Account/Save.php @@ -27,7 +27,7 @@ class Save extends \Magento\Backend\Controller\Adminhtml\System\Account implemen * Get security cookie * * @deprecated 100.1.0 This method is deprecated because dependency injection should be used instead of - * directly accessing the SecurityCookie instance. + * directly accessing the SecurityCookie instance. * Use dependency injection to get an instance of SecurityCookie. * @see \Magento\Backend\Controller\Adminhtml\System\Account::__construct() * @return SecurityCookie From 8b2069b9ffcff8a2ce5c22a1f4ec6e7036849cb4 Mon Sep 17 00:00:00 2001 From: Pieter Zandbergen Date: Thu, 27 Jun 2024 14:19:11 +0200 Subject: [PATCH 038/656] fix: Use Object Manager for ModeConfigured Fixing #38875 (AC-12299) --- .../Magento/Csp/Model/Mode/ConfigManager.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Csp/Model/Mode/ConfigManager.php b/app/code/Magento/Csp/Model/Mode/ConfigManager.php index bc31a41982549..07cc44bbeff65 100644 --- a/app/code/Magento/Csp/Model/Mode/ConfigManager.php +++ b/app/code/Magento/Csp/Model/Mode/ConfigManager.php @@ -11,7 +11,7 @@ use Magento\Framework\App\ObjectManager; use Magento\Csp\Api\Data\ModeConfiguredInterface; use Magento\Csp\Api\ModeConfigManagerInterface; -use Magento\Csp\Model\Mode\Data\ModeConfigured; +use Magento\Csp\Model\Mode\Data\ModeConfiguredFactory; use Magento\Framework\App\Area; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\State; @@ -24,10 +24,15 @@ class ConfigManager implements ModeConfigManagerInterface { /** - * @var ScopeConfigInterface + * @var ScopeConfigInterfaceFactory */ private $config; + /** + * @var ModeConfiguredFactory + */ + private $modeConfiguredFactory; + /** * @var Store */ @@ -45,17 +50,20 @@ class ConfigManager implements ModeConfigManagerInterface /** * @param ScopeConfigInterface $config + * @param ModeConfiguredFactory $modeConfiguredFactory * @param Store $store * @param State $state * @param Http|null $request */ public function __construct( ScopeConfigInterface $config, + ModeConfiguredFactory $modeConfiguredFactory, Store $store, State $state, ?Http $request = null ) { $this->config = $config; + $this->modeConfiguredFactory = $modeConfiguredFactory; $this->storeModel = $store; $this->state = $state; @@ -118,9 +126,9 @@ public function getConfigured(): ModeConfiguredInterface ); } - return new ModeConfigured( - (bool) $reportOnly, - !empty($reportUri) ? $reportUri : null - ); + return $this->modeConfiguredFactory->create([ + 'reportOnly' => $reportOnly, + 'reportUri' => !empty($reportUri) ? $reportUri : null, + ]); } } From 44392fb701265019f8afc3bac0fcbdc5569384b2 Mon Sep 17 00:00:00 2001 From: Pieter Zandbergen Date: Thu, 27 Jun 2024 14:21:49 +0200 Subject: [PATCH 039/656] fix: Wrong type --- app/code/Magento/Csp/Model/Mode/ConfigManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Csp/Model/Mode/ConfigManager.php b/app/code/Magento/Csp/Model/Mode/ConfigManager.php index 07cc44bbeff65..2db46aee6f6c8 100644 --- a/app/code/Magento/Csp/Model/Mode/ConfigManager.php +++ b/app/code/Magento/Csp/Model/Mode/ConfigManager.php @@ -24,7 +24,7 @@ class ConfigManager implements ModeConfigManagerInterface { /** - * @var ScopeConfigInterfaceFactory + * @var ScopeConfigInterface */ private $config; From 96daecf76213f92b2f44567a62ab2db0933bf34b Mon Sep 17 00:00:00 2001 From: Pieter Zandbergen Date: Mon, 8 Jul 2024 14:06:12 +0200 Subject: [PATCH 040/656] fix: Type casting (reportOnly flag) Co-authored-by: Denis Kopylov --- app/code/Magento/Csp/Model/Mode/ConfigManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Csp/Model/Mode/ConfigManager.php b/app/code/Magento/Csp/Model/Mode/ConfigManager.php index 2db46aee6f6c8..19337c6841573 100644 --- a/app/code/Magento/Csp/Model/Mode/ConfigManager.php +++ b/app/code/Magento/Csp/Model/Mode/ConfigManager.php @@ -127,7 +127,7 @@ public function getConfigured(): ModeConfiguredInterface } return $this->modeConfiguredFactory->create([ - 'reportOnly' => $reportOnly, + 'reportOnly' => (bool)$reportOnly, 'reportUri' => !empty($reportUri) ? $reportUri : null, ]); } From 3d47ec006bd8c2e50e26b054feadce4aed5a64f6 Mon Sep 17 00:00:00 2001 From: Pieter Zandbergen Date: Mon, 8 Jul 2024 14:07:54 +0200 Subject: [PATCH 041/656] fix: type casting (reportUri) --- app/code/Magento/Csp/Model/Mode/ConfigManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Csp/Model/Mode/ConfigManager.php b/app/code/Magento/Csp/Model/Mode/ConfigManager.php index 19337c6841573..4b2a7c1b63c98 100644 --- a/app/code/Magento/Csp/Model/Mode/ConfigManager.php +++ b/app/code/Magento/Csp/Model/Mode/ConfigManager.php @@ -127,8 +127,8 @@ public function getConfigured(): ModeConfiguredInterface } return $this->modeConfiguredFactory->create([ - 'reportOnly' => (bool)$reportOnly, - 'reportUri' => !empty($reportUri) ? $reportUri : null, + 'reportOnly' => (bool) $reportOnly, + 'reportUri' => !empty($reportUri) ? (string) $reportUri : null, ]); } } From ded2587fb111570ef1226abaa501a105a52fd13f Mon Sep 17 00:00:00 2001 From: rostislav Date: Fri, 12 Jul 2024 15:34:57 +0300 Subject: [PATCH 042/656] issue-38703 added possibility to reset default options for attributes for visual, text swatches and dropdown attributes --- .../Adminhtml/Product/Attribute/Save.php | 5 +++++ .../catalog/product/attribute/options.phtml | 7 +++++++ .../Catalog/view/adminhtml/web/js/options.js | 19 +++++++++++++++++++ .../catalog/product/attribute/text.phtml | 7 +++++++ .../catalog/product/attribute/visual.phtml | 7 +++++++ .../Swatches/view/adminhtml/web/js/text.js | 17 +++++++++++++++++ .../Swatches/view/adminhtml/web/js/visual.js | 19 ++++++++++++++++++- 7 files changed, 80 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php index d443f399360a9..6f3ccc96fae1d 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php @@ -269,6 +269,11 @@ public function execute() unset($data['entity_type_id']); + if (array_key_exists('reset_is-default_option', $data) && $data['reset_is-default_option']) { + unset($data['reset_is-default_option']); + $data['default_value'] = null; + } + $model->addData($data); if (!$attributeId) { diff --git a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml index 7ae3a2ade6557..c382bbcad5ba9 100644 --- a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml +++ b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml @@ -38,6 +38,7 @@ $stores = $block->getStoresSortedBySortOrder(); + @@ -48,6 +49,12 @@ $stores = $block->getStoresSortedBySortOrder(); type="button" class="action- scalable add"> escapeHtml(__('Add Option')) ?> + + diff --git a/app/code/Magento/Catalog/view/adminhtml/web/js/options.js b/app/code/Magento/Catalog/view/adminhtml/web/js/options.js index 7adc0dcfdf408..efaf18e423302 100644 --- a/app/code/Magento/Catalog/view/adminhtml/web/js/options.js +++ b/app/code/Magento/Catalog/view/adminhtml/web/js/options.js @@ -94,6 +94,16 @@ define([ element.remove(); } }, + + /** + * Reset Is Default option + * + */ + reset: function () { + jQuery('input[name="defaulttext[]"]').prop('checked', false); + jQuery('input[name="reset_is_default_option"]').val(1); + }, + updateItemsCountField: function () { $('option-count-check').value = this.totalItems > 0 ? '1' : ''; }, @@ -151,6 +161,15 @@ define([ if ($('add_new_option_button')) { Event.observe('add_new_option_button', 'click', attributeOption.add.bind(attributeOption, {}, true)); } + + if ($('reset_is_default_option_button')) { + Event.observe( + 'reset_is-default_option_button', + 'click', + attributeOption.reset.bind(attributeOption, true) + ); + } + $('manage-options-panel').on('click', '.delete-option', function (event) { attributeOption.remove(event); }); diff --git a/app/code/Magento/Swatches/view/adminhtml/templates/catalog/product/attribute/text.phtml b/app/code/Magento/Swatches/view/adminhtml/templates/catalog/product/attribute/text.phtml index 2841b1861f849..d6376ebde51e2 100644 --- a/app/code/Magento/Swatches/view/adminhtml/templates/catalog/product/attribute/text.phtml +++ b/app/code/Magento/Swatches/view/adminhtml/templates/catalog/product/attribute/text.phtml @@ -35,6 +35,7 @@ $stores = $block->getStoresSortedBySortOrder(); + @@ -45,6 +46,12 @@ $stores = $block->getStoresSortedBySortOrder(); type="button" class="action- scalable add"> escapeHtml(__('Add Swatch')) ?> + + diff --git a/app/code/Magento/Swatches/view/adminhtml/templates/catalog/product/attribute/visual.phtml b/app/code/Magento/Swatches/view/adminhtml/templates/catalog/product/attribute/visual.phtml index 84ab09073f986..e7883d99d16fd 100644 --- a/app/code/Magento/Swatches/view/adminhtml/templates/catalog/product/attribute/visual.phtml +++ b/app/code/Magento/Swatches/view/adminhtml/templates/catalog/product/attribute/visual.phtml @@ -37,6 +37,7 @@ $stores = $block->getStoresSortedBySortOrder(); + @@ -47,6 +48,12 @@ $stores = $block->getStoresSortedBySortOrder(); type="button" class="action- scalable add"> escapeHtml(__('Add Swatch')) ?> + + diff --git a/app/code/Magento/Swatches/view/adminhtml/web/js/text.js b/app/code/Magento/Swatches/view/adminhtml/web/js/text.js index c2d923df1953f..15578db7a2f1b 100644 --- a/app/code/Magento/Swatches/view/adminhtml/web/js/text.js +++ b/app/code/Magento/Swatches/view/adminhtml/web/js/text.js @@ -98,6 +98,15 @@ define([ } }, + /** + * Reset Is Default option + * + */ + reset: function () { + jQuery('input[name="defaulttext[]"]').prop('checked',false); + jQuery('input[name="reset_is_default_option"]').val(1); + }, + /** * Update items count field */ @@ -179,6 +188,14 @@ define([ swatchTextOption.add.bind(swatchTextOption, true) ); } + + if ($('reset_is_default_option_button')) { + Event.observe( + 'reset_is-default_option_button', + 'click', + swatchTextOption.reset.bind(swatchTextOption, true) + ); + } jQuery('#swatch-text-options-panel').on('render', function () { swatchTextOption.ignoreValidate(); diff --git a/app/code/Magento/Swatches/view/adminhtml/web/js/visual.js b/app/code/Magento/Swatches/view/adminhtml/web/js/visual.js index a70d2782eda5f..223e139e08d6f 100644 --- a/app/code/Magento/Swatches/view/adminhtml/web/js/visual.js +++ b/app/code/Magento/Swatches/view/adminhtml/web/js/visual.js @@ -147,6 +147,15 @@ define([ } }, + /** + * Reset Is Default option + * + */ + reset: function () { + jQuery('input[name="defaulttext[]"]').prop('checked', false); + jQuery('input[name="reset_is_default_option"]').val(1); + }, + /** * Update items count field */ @@ -229,6 +238,14 @@ define([ ); } + if ($('reset_is_default_option_button')) { + Event.observe( + 'reset_is-default_option_button', + 'click', + swatchVisualOption.reset.bind(swatchVisualOption, true) + ); + } + jQuery('#swatch-visual-options-panel').on('render', function () { swatchVisualOption.ignoreValidate(); @@ -319,7 +336,7 @@ define([ }).appendTo($('body')); this.iframe = $('', { - id: 'upload_iframe', + id: 'upload_iframe', name: 'upload_iframe' }).appendTo(this.wrapper); From 2e414b7927ca7d9a04e67a8adf3e36af34c91490 Mon Sep 17 00:00:00 2001 From: rostislav Date: Fri, 12 Jul 2024 15:56:44 +0300 Subject: [PATCH 043/656] issue-38703 added possibility to reset default options for attributes for visual, text swatches and dropdown attributes ( fixes ) --- .../catalog/product/attribute/options.phtml | 2 +- .../Catalog/view/adminhtml/web/js/options.js | 17 ++++++++--------- .../catalog/product/attribute/text.phtml | 2 +- .../catalog/product/attribute/visual.phtml | 2 +- .../Swatches/view/adminhtml/web/js/text.js | 6 +++--- .../Swatches/view/adminhtml/web/js/visual.js | 8 ++++---- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml index c382bbcad5ba9..1c998dee69215 100644 --- a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml +++ b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/options.phtml @@ -50,7 +50,7 @@ $stores = $block->getStoresSortedBySortOrder(); escapeHtml(__('Add Option')) ?> - - -