Skip to content

Commit 443453f

Browse files
committed
Merge branch '2.4-develop' into ACP2E-3501
2 parents 00956af + 30d0b82 commit 443453f

File tree

31 files changed

+657
-279
lines changed

31 files changed

+657
-279
lines changed

app/code/Magento/Catalog/Model/Product/Image/RemoveDeletedImagesFromCache.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
2+
/************************************************************************
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained
13+
* from Adobe.
14+
* ***********************************************************************
515
*/
16+
617
declare(strict_types=1);
718

819
namespace Magento\Catalog\Model\Product\Image;
920

1021
use Magento\Catalog\Helper\Image;
1122
use Magento\Catalog\Model\Product\Media\Config;
1223
use Magento\Framework\App\Filesystem\DirectoryList;
13-
use Magento\Framework\Encryption\Encryptor;
1424
use Magento\Framework\Encryption\EncryptorInterface;
1525
use Magento\Framework\Filesystem;
1626
use Magento\Framework\Filesystem\Directory\WriteInterface;
@@ -21,6 +31,11 @@
2131
*/
2232
class RemoveDeletedImagesFromCache
2333
{
34+
/**
35+
* Current hashing algorithm
36+
*/
37+
private const HASH_ALGORITHM = 'md5';
38+
2439
/**
2540
* @var ConfigInterface
2641
*/
@@ -103,10 +118,10 @@ public function removeDeletedImagesFromCache(array $files): void
103118
unset($imageMiscParams['image_type']);
104119
}
105120

106-
$cacheId = $this->encryptor->hash(
121+
$cacheId = hash(
122+
self::HASH_ALGORITHM,
107123
implode('_', $this->convertImageMiscParamsToReadableFormat
108-
->convertImageMiscParamsToReadableFormat($imageMiscParams)),
109-
Encryptor::HASH_VERSION_MD5
124+
->convertImageMiscParamsToReadableFormat($imageMiscParams))
110125
);
111126

112127
foreach ($files as $filePath) {

app/code/Magento/Catalog/Model/View/Asset/Image.php

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
2+
/************************************************************************
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained
13+
* from Adobe.
14+
* ***********************************************************************
515
*/
616

717
namespace Magento\Catalog\Model\View\Asset;
@@ -11,7 +21,6 @@
1121
use Magento\Catalog\Model\Product\Image\ConvertImageMiscParamsToReadableFormat;
1222
use Magento\Catalog\Model\Product\Media\ConfigInterface;
1323
use Magento\Framework\App\ObjectManager;
14-
use Magento\Framework\Encryption\Encryptor;
1524
use Magento\Framework\Encryption\EncryptorInterface;
1625
use Magento\Framework\Exception\LocalizedException;
1726
use Magento\Framework\View\Asset\ContextInterface;
@@ -25,6 +34,11 @@
2534
*/
2635
class Image implements LocalInterface
2736
{
37+
/**
38+
* Current hashing algorithm
39+
*/
40+
private const HASH_ALGORITHM = 'md5';
41+
2842
/**
2943
* Image type of image (thumbnail,small_image,image,swatch_image,swatch_thumb)
3044
*
@@ -96,6 +110,8 @@ class Image implements LocalInterface
96110
* @param CatalogMediaConfig $catalogMediaConfig
97111
* @param StoreManagerInterface $storeManager
98112
* @param ConvertImageMiscParamsToReadableFormat $convertImageMiscParamsToReadableFormat
113+
*
114+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
99115
*/
100116
public function __construct(
101117
ConfigInterface $mediaConfig,
@@ -260,29 +276,27 @@ public function getModule()
260276
}
261277

262278
/**
263-
* Retrieve part of path based on misc params
264-
*
265-
* @return string
266-
*/
267-
private function getMiscPath()
268-
{
269-
return $this->encryptor->hash(
270-
implode('_', $this->convertToReadableFormat($this->miscParams)),
271-
Encryptor::HASH_VERSION_MD5
272-
);
273-
}
274-
275-
/**
276-
* Generate path from image info
279+
* Generate path from image info.
277280
*
278281
* @return string
279282
*/
280283
private function getImageInfo()
281284
{
282-
$path = $this->getModule()
283-
. DIRECTORY_SEPARATOR . $this->getMiscPath()
284-
. DIRECTORY_SEPARATOR . $this->getFilePath();
285-
return preg_replace('|\Q'. DIRECTORY_SEPARATOR . '\E+|', DIRECTORY_SEPARATOR, $path);
285+
$data = implode('_', $this->convertToReadableFormat($this->miscParams));
286+
287+
$pathTemplate = $this->getModule()
288+
. DIRECTORY_SEPARATOR . "%s" . DIRECTORY_SEPARATOR
289+
. $this->getFilePath();
290+
291+
/**
292+
* New paths are generated without dependency on
293+
* an encryption key.
294+
*/
295+
return preg_replace(
296+
'|\Q' . DIRECTORY_SEPARATOR . '\E+|',
297+
DIRECTORY_SEPARATOR,
298+
sprintf($pathTemplate, hash(self::HASH_ALGORITHM, $data))
299+
);
286300
}
287301

288302
/**

app/code/Magento/Catalog/Test/Unit/Model/Product/Image/RemoveDeletedImagesFromCacheTest.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
2+
/************************************************************************
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained
13+
* from Adobe.
14+
* ***********************************************************************
515
*/
16+
617
declare(strict_types=1);
718

819
namespace Magento\Catalog\Test\Unit\Model\Product\Image;
@@ -171,10 +182,6 @@ public function getRespectiveMethodMockObjForRemoveDeletedImagesFromCache(array
171182
->method('convertImageMiscParamsToReadableFormat')
172183
->willReturn($data['convertImageParamsToReadableFormat']);
173184

174-
$this->encryptor->expects($this->once())
175-
->method('hash')
176-
->willReturn('85b0304775df23c13f08dd2c1f9c4c28');
177-
178185
$this->mediaConfig->expects($this->once())
179186
->method('getBaseMediaPath')
180187
->willReturn('catalog/product');

app/code/Magento/Cron/Console/Command/CronCommand.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
2+
23
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
4+
* Copyright 2017 Adobe
5+
* All Rights Reserved.
56
*/
67

78
namespace Magento\Cron\Console\Command;
@@ -135,10 +136,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
135136
$params[ProcessCronQueueObserver::STANDALONE_PROCESS_STARTED] = $bootstrapOptionValue;
136137
}
137138
}
139+
138140
/** @var Cron $cronObserver */
139141
$cronObserver = $objectManager->create(Cron::class, ['parameters' => $params]);
140142
$cronObserver->launch();
141-
$output->writeln('<info>' . 'Ran jobs by schedule.' . '</info>');
143+
144+
// phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged,Magento2.Exceptions.TryProcessSystemResources.MissingTryCatch
145+
if (stream_isatty(STDOUT)) {
146+
$output->writeln('<info>' . 'Ran jobs by schedule.' . '</info>');
147+
}
142148

143149
return Cli::RETURN_SUCCESS;
144150
}

app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2016 Adobe
4+
* All Rights Reserved.
55
*/
66

77
/**
@@ -278,10 +278,12 @@ function ($a, $b) {
278278
&& $this->getCronGroupConfigurationValue($groupId, 'use_separate_process') == 1
279279
) {
280280
$this->_shell->execute(
281-
$phpPath . ' %s cron:run --group=' . $groupId . ' --' . Cli::INPUT_KEY_BOOTSTRAP . '='
281+
'%s %s cron:run --group=%s --' . Cli::INPUT_KEY_BOOTSTRAP . '='
282282
. self::STANDALONE_PROCESS_STARTED . '=1',
283283
[
284-
BP . '/bin/magento'
284+
$phpPath,
285+
BP . '/bin/magento',
286+
$groupId,
285287
]
286288
);
287289
continue;
@@ -848,7 +850,7 @@ private function processPendingJobs(string $groupId, array $jobsRoot, int $curre
848850
/** @var Schedule $schedule */
849851
foreach ($pendingJobs as $schedule) {
850852
if (isset($processedJobs[$schedule->getJobCode()])) {
851-
// process only on job per run
853+
// process only one of each job per run
852854
continue;
853855
}
854856
$jobConfig = isset($jobsRoot[$schedule->getJobCode()]) ? $jobsRoot[$schedule->getJobCode()] : null;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2017 Adobe
5+
* All Rights Reserved.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magento\Cron\Shell;
11+
12+
use Magento\Framework\App\Filesystem\DirectoryList;
13+
use Magento\Framework\Filesystem;
14+
use Magento\Framework\OsInfo;
15+
use Magento\Framework\Shell\CommandRenderer;
16+
17+
class CommandRendererBackground extends CommandRenderer
18+
{
19+
/**
20+
* @param Filesystem $filesystem
21+
* @param OsInfo $osInfo
22+
*/
23+
public function __construct(
24+
private readonly Filesystem $filesystem,
25+
private readonly OsInfo $osInfo,
26+
) {
27+
}
28+
29+
/**
30+
* @inheritDoc
31+
*/
32+
public function render($command, array $arguments = []): string
33+
{
34+
$command = parent::render($command, $arguments);
35+
36+
$logFile = '/dev/null';
37+
if ($groupId = $arguments[2] ?? null) {
38+
$logDir = $this->filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath();
39+
// @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged
40+
$logFile = escapeshellarg($logDir . 'magento.cron.' . $groupId . '.log');
41+
}
42+
43+
return $this->osInfo->isWindows() ?
44+
'start /B "magento background task" ' . $command
45+
: str_replace('2>&1', ">> $logFile 2>&1 &", $command);
46+
}
47+
}

app/code/Magento/Cron/Test/Unit/Console/Command/CronCommandTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
23
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
4+
* Copyright 2017 Adobe
5+
* All Rights Reserved.
56
*/
7+
68
declare(strict_types=1);
79

810
namespace Magento\Cron\Test\Unit\Console\Command;
@@ -80,7 +82,7 @@ public function testExecute()
8082
new CronCommand($this->objectManagerFactory, $this->deploymentConfigMock)
8183
);
8284
$commandTester->execute([]);
83-
$expectedMsg = 'Ran jobs by schedule.' . PHP_EOL;
85+
$expectedMsg = '';
8486
$this->assertEquals($expectedMsg, $commandTester->getDisplay());
8587
}
8688
}

0 commit comments

Comments
 (0)