Skip to content

Commit aa0fabc

Browse files
authored
Merge branch '2.4-develop' into phpdoc/scopeConfig
2 parents 8c8dd99 + b2b7b32 commit aa0fabc

File tree

7 files changed

+155
-183
lines changed

7 files changed

+155
-183
lines changed

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

+22-7
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/Product/Price/Validation/TierPriceValidator.php

+27-60
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 2024 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Catalog\Model\Product\Price\Validation;
@@ -10,10 +10,8 @@
1010
use Magento\Catalog\Api\ProductRepositoryInterface;
1111
use Magento\Catalog\Model\Product\Type;
1212
use Magento\Catalog\Model\ProductIdLocatorInterface;
13-
use Magento\Customer\Api\GroupRepositoryInterface;
1413
use Magento\Directory\Model\Currency;
15-
use Magento\Framework\Api\FilterBuilder;
16-
use Magento\Framework\Api\SearchCriteriaBuilder;
14+
use Magento\Framework\App\ResourceConnection;
1715
use Magento\Framework\Exception\LocalizedException;
1816
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1917
use Magento\Store\Api\WebsiteRepositoryInterface;
@@ -35,21 +33,6 @@ class TierPriceValidator implements ResetAfterRequestInterface
3533
*/
3634
private $productIdLocator;
3735

38-
/**
39-
* @var SearchCriteriaBuilder
40-
*/
41-
private $searchCriteriaBuilder;
42-
43-
/**
44-
* @var FilterBuilder
45-
*/
46-
private $filterBuilder;
47-
48-
/**
49-
* @var GroupRepositoryInterface
50-
*/
51-
private $customerGroupRepository;
52-
5336
/**
5437
* @var WebsiteRepositoryInterface
5538
*/
@@ -60,13 +43,6 @@ class TierPriceValidator implements ResetAfterRequestInterface
6043
*/
6144
private $validationResult;
6245

63-
/**
64-
* Groups by code cache.
65-
*
66-
* @var array
67-
*/
68-
private $customerGroupsByCode = [];
69-
7046
/**
7147
* @var InvalidSkuProcessor
7248
*/
@@ -97,6 +73,16 @@ class TierPriceValidator implements ResetAfterRequestInterface
9773
*/
9874
private $productsCacheBySku = [];
9975

76+
/**
77+
* @var ResourceConnection
78+
*/
79+
private $resourceConnection;
80+
81+
/**
82+
* @var array Customer group check cache
83+
*/
84+
private $customerGroupCheck = [];
85+
10086
/**
10187
* @var ScopeConfigInterface
10288
*/
@@ -106,38 +92,32 @@ class TierPriceValidator implements ResetAfterRequestInterface
10692
* TierPriceValidator constructor.
10793
*
10894
* @param ProductIdLocatorInterface $productIdLocator
109-
* @param SearchCriteriaBuilder $searchCriteriaBuilder
110-
* @param FilterBuilder $filterBuilder
111-
* @param GroupRepositoryInterface $customerGroupRepository
11295
* @param WebsiteRepositoryInterface $websiteRepository
11396
* @param Result $validationResult
11497
* @param InvalidSkuProcessor $invalidSkuProcessor
11598
* @param ProductRepositoryInterface $productRepository
11699
* @param array $allowedProductTypes [optional]
100+
* @param ResourceConnection|null $resourceConnection
117101
* @param ScopeConfigInterface|null $scopeConfig
118102
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
119103
*/
120104
public function __construct(
121105
ProductIdLocatorInterface $productIdLocator,
122-
SearchCriteriaBuilder $searchCriteriaBuilder,
123-
FilterBuilder $filterBuilder,
124-
GroupRepositoryInterface $customerGroupRepository,
125106
WebsiteRepositoryInterface $websiteRepository,
126107
Result $validationResult,
127108
InvalidSkuProcessor $invalidSkuProcessor,
128109
ProductRepositoryInterface $productRepository,
129110
array $allowedProductTypes = [],
111+
?ResourceConnection $resourceConnection = null,
130112
?ScopeConfigInterface $scopeConfig = null
131113
) {
132114
$this->productIdLocator = $productIdLocator;
133-
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
134-
$this->filterBuilder = $filterBuilder;
135-
$this->customerGroupRepository = $customerGroupRepository;
136115
$this->websiteRepository = $websiteRepository;
137116
$this->validationResult = $validationResult;
138117
$this->invalidSkuProcessor = $invalidSkuProcessor;
139118
$this->productRepository = $productRepository;
140119
$this->allowedProductTypes = $allowedProductTypes;
120+
$this->resourceConnection = $resourceConnection ?: ObjectManager::getInstance()->get(ResourceConnection::class);
141121
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
142122
}
143123

@@ -504,32 +484,19 @@ private function checkGroup(TierPriceInterface $price, $key, Result $validationR
504484
*/
505485
private function retrieveGroupValue(string $code)
506486
{
507-
if (!isset($this->customerGroupsByCode[$code])) {
508-
$searchCriteria = $this->searchCriteriaBuilder->addFilters(
509-
[
510-
$this->filterBuilder->setField('customer_group_code')->setValue($code)->create()
511-
]
487+
if (!isset($this->customerGroupCheck[$code])) {
488+
$connection = $this->resourceConnection->getConnection();
489+
$select = $connection->select()->from(
490+
$this->resourceConnection->getTableName('customer_group'),
491+
'customer_group_id'
492+
)->where(
493+
'customer_group_code = ?',
494+
$code
512495
);
513-
$items = $this->customerGroupRepository->getList($searchCriteria->create())->getItems();
514-
$item = array_shift($items);
515-
516-
if (!$item) {
517-
$this->customerGroupsByCode[$code] = false;
518-
return false;
519-
}
520-
521-
$itemCode = $item->getCode();
522-
$itemId = $item->getId();
523-
524-
if (strtolower($itemCode) !== $code) {
525-
$this->customerGroupsByCode[$code] = false;
526-
return false;
527-
}
528-
529-
$this->customerGroupsByCode[strtolower($itemCode)] = $itemId;
496+
$this->customerGroupCheck[$code] = $connection->fetchOne($select);
530497
}
531498

532-
return $this->customerGroupsByCode[$code];
499+
return $this->customerGroupCheck[$code];
533500
}
534501

535502
/**
@@ -576,6 +543,6 @@ private function compareWebsiteValueNewPrice(TierPriceInterface $price, TierPric
576543
*/
577544
public function _resetState(): void
578545
{
579-
$this->customerGroupsByCode = [];
546+
$this->customerGroupCheck = [];
580547
}
581548
}

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

+36-22
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

+14-7
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');

0 commit comments

Comments
 (0)