Skip to content

Commit 42caef6

Browse files
ACPT-671
fixing static test failure
1 parent eed0a75 commit 42caef6

File tree

1 file changed

+64
-35
lines changed
  • app/code/Magento/CatalogImportExport/Model/Import

1 file changed

+64
-35
lines changed

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

Lines changed: 64 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,7 @@ private function saveProductTierPricesPhase(array $rowData, bool $priceIsGlobal,
17981798
* @param array $rowData
17991799
* @param int $storeId
18001800
* @param array $existingImages
1801+
* @param string $productMediaPath
18011802
* @param array $uploadedImages
18021803
* @param array $imagesForChangeVisibility
18031804
* @param array $labelsForUpdate
@@ -1965,7 +1966,7 @@ private function saveProductAttributesPhase(
19651966
$productType = $previousType;
19661967
}
19671968
if ($productType === null) {
1968-
throw new Skip('Unknown Product Type');
1969+
throw new Skip(__('Unknown Product Type'));
19691970
}
19701971
}
19711972
$productTypeModel = $this->_productTypeModels[$productType];
@@ -2041,13 +2042,12 @@ private function saveProductAttributesPhase(
20412042
*/
20422043
private function getFileContent(string $path): string
20432044
{
2044-
$content = '';
20452045
if ($this->_mediaDirectory->isFile($path)
20462046
&& $this->_mediaDirectory->isReadable($path)
20472047
) {
2048-
$content = $this->_mediaDirectory->readFile($path);
2048+
return $this->_mediaDirectory->readFile($path);
20492049
}
2050-
return $content;
2050+
return '';
20512051
}
20522052

20532053
/**
@@ -2058,7 +2058,9 @@ private function getFileContent(string $path): string
20582058
*/
20592059
private function getRemoteFileContent(string $filename): string
20602060
{
2061+
// phpcs:disable Magento2.Functions.DiscouragedFunction
20612062
$content = file_get_contents($filename);
2063+
// phpcs:enable Magento2.Functions.DiscouragedFunction
20622064
return $content !== false ? $content : '';
20632065
}
20642066

@@ -3319,40 +3321,67 @@ private function findImageByColumnImage(string $productMediaPath, array &$images
33193321
$content = filter_var($columnImage, FILTER_VALIDATE_URL)
33203322
? $this->getRemoteFileContent($columnImage)
33213323
: $this->getFileContent($this->joinFilePaths($this->getUploader()->getTmpDir(), $columnImage));
3322-
$value = '';
3323-
if ($content) {
3324-
$useHash = $this->shouldUseHash($images);
3325-
if ($useHash) {
3326-
$hash = hash(self::HASH_ALGORITHM, $content);
3327-
}
3328-
foreach ($images as &$image) {
3329-
if ($useHash) {
3330-
if (!isset($image['hash'])) {
3331-
$imageContent = $this->getFileContent($this->joinFilePaths($productMediaPath, $image['value']));
3332-
if (!$imageContent) {
3333-
$image['hash'] = '';
3334-
continue;
3335-
}
3336-
$image['hash'] = hash(self::HASH_ALGORITHM, $imageContent);
3337-
}
3338-
if (isset($image['hash']) && $image['hash'] === $hash) {
3339-
$value = $image['value'];
3340-
break;
3341-
}
3342-
} else {
3343-
if (!isset($image['content'])) {
3344-
$image['content'] = $this->getFileContent(
3345-
$this->joinFilePaths($productMediaPath, $image['value'])
3346-
);
3347-
}
3348-
if ($content === $image['content']) {
3349-
$value = $image['value'];
3350-
break;
3351-
}
3324+
if (!$content) {
3325+
return '';
3326+
}
3327+
if ($this->shouldUseHash($images)) {
3328+
return $this->findImageByColumnImageUsingHash($productMediaPath, $images, $content);
3329+
} else {
3330+
return $this->findImageByColumnImageUsingContent($productMediaPath, $images, $content);
3331+
}
3332+
}
3333+
3334+
/**
3335+
* Returns image that matches the provided image content using hash
3336+
*
3337+
* @param string $productMediaPath
3338+
* @param array $images
3339+
* @param string $content
3340+
* @return string
3341+
*/
3342+
private function findImageByColumnImageUsingHash(string $productMediaPath, array &$images, string $content): string
3343+
{
3344+
$hash = hash(self::HASH_ALGORITHM, $content);
3345+
foreach ($images as &$image) {
3346+
if (!isset($image['hash'])) {
3347+
$imageContent = $this->getFileContent($this->joinFilePaths($productMediaPath, $image['value']));
3348+
if (!$imageContent) {
3349+
$image['hash'] = '';
3350+
continue;
33523351
}
3352+
$image['hash'] = hash(self::HASH_ALGORITHM, $imageContent);
3353+
}
3354+
if (isset($image['hash']) && $image['hash'] === $hash) {
3355+
return $image['value'];
3356+
}
3357+
}
3358+
return '';
3359+
}
3360+
3361+
/**
3362+
* Returns image that matches the provided image content using content
3363+
*
3364+
* @param string $productMediaPath
3365+
* @param array $images
3366+
* @param string $content
3367+
* @return string
3368+
*/
3369+
private function findImageByColumnImageUsingContent(
3370+
string $productMediaPath,
3371+
array &$images,
3372+
string $content
3373+
): string {
3374+
foreach ($images as &$image) {
3375+
if (!isset($image['content'])) {
3376+
$image['content'] = $this->getFileContent(
3377+
$this->joinFilePaths($productMediaPath, $image['value'])
3378+
);
3379+
}
3380+
if ($content === $image['content']) {
3381+
return $image['value'];
33533382
}
33543383
}
3355-
return $value;
3384+
return '';
33563385
}
33573386

33583387
/**

0 commit comments

Comments
 (0)