Skip to content

Commit cc93658

Browse files
ACPT-671
switching hashing algoritm to 'xxh128' (or 'crc32c' for PHP < 8.1)
1 parent 25c711a commit cc93658

File tree

1 file changed

+9
-5
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import

1 file changed

+9
-5
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class Product extends AbstractEntity
4949
{
5050
private const DEFAULT_GLOBAL_MULTIPLE_VALUE_SEPARATOR = ',';
5151
public const CONFIG_KEY_PRODUCT_TYPES = 'global/importexport/import_product_types';
52-
private const HASH_ALGORITHM = 'sha256';
5352

5453
/**
5554
* Size of bunch - part of products to save in one step.
@@ -264,6 +263,11 @@ class Product extends AbstractEntity
264263
*/
265264
protected $_mediaGalleryAttributeId = null;
266265

266+
/**
267+
* @var string
268+
*/
269+
private $hashAlgorithm = 'crc32c';
270+
267271
/**
268272
* @var array
269273
* @codingStandardsIgnoreStart
@@ -904,7 +908,7 @@ public function __construct(
904908
$this->linkProcessor = $linkProcessor ?? ObjectManager::getInstance()
905909
->get(LinkProcessor::class);
906910
$this->linkProcessor->addNameToIds($this->_linkNameToId);
907-
911+
$this->hashAlgorithm = (version_compare(PHP_VERSION, '8.1.0') >= 0) ? 'xxh128' : 'crc32c';
908912
parent::__construct(
909913
$jsonHelper,
910914
$importExportData,
@@ -3344,17 +3348,17 @@ private function findImageByColumnImage(string $productMediaPath, array &$images
33443348
*/
33453349
private function findImageByColumnImageUsingHash(string $productMediaPath, array &$images, string $content): string
33463350
{
3347-
$hash = hash(self::HASH_ALGORITHM, $content);
3351+
$hash = hash($this->hashAlgorithm, $content);
33483352
foreach ($images as &$image) {
33493353
if (!isset($image['hash'])) {
33503354
$imageContent = $this->getFileContent($this->joinFilePaths($productMediaPath, $image['value']));
33513355
if (!$imageContent) {
33523356
$image['hash'] = '';
33533357
continue;
33543358
}
3355-
$image['hash'] = hash(self::HASH_ALGORITHM, $imageContent);
3359+
$image['hash'] = hash($this->hashAlgorithm, $imageContent);
33563360
}
3357-
if (isset($image['hash']) && $image['hash'] === $hash) {
3361+
if (!empty($image['hash']) && $image['hash'] === $hash) {
33583362
return $image['value'];
33593363
}
33603364
}

0 commit comments

Comments
 (0)