@@ -1798,6 +1798,7 @@ private function saveProductTierPricesPhase(array $rowData, bool $priceIsGlobal,
1798
1798
* @param array $rowData
1799
1799
* @param int $storeId
1800
1800
* @param array $existingImages
1801
+ * @param string $productMediaPath
1801
1802
* @param array $uploadedImages
1802
1803
* @param array $imagesForChangeVisibility
1803
1804
* @param array $labelsForUpdate
@@ -1965,7 +1966,7 @@ private function saveProductAttributesPhase(
1965
1966
$ productType = $ previousType ;
1966
1967
}
1967
1968
if ($ productType === null ) {
1968
- throw new Skip ('Unknown Product Type ' );
1969
+ throw new Skip (__ ( 'Unknown Product Type ' ) );
1969
1970
}
1970
1971
}
1971
1972
$ productTypeModel = $ this ->_productTypeModels [$ productType ];
@@ -2041,13 +2042,12 @@ private function saveProductAttributesPhase(
2041
2042
*/
2042
2043
private function getFileContent (string $ path ): string
2043
2044
{
2044
- $ content = '' ;
2045
2045
if ($ this ->_mediaDirectory ->isFile ($ path )
2046
2046
&& $ this ->_mediaDirectory ->isReadable ($ path )
2047
2047
) {
2048
- $ content = $ this ->_mediaDirectory ->readFile ($ path );
2048
+ return $ this ->_mediaDirectory ->readFile ($ path );
2049
2049
}
2050
- return $ content ;
2050
+ return '' ;
2051
2051
}
2052
2052
2053
2053
/**
@@ -2058,7 +2058,9 @@ private function getFileContent(string $path): string
2058
2058
*/
2059
2059
private function getRemoteFileContent (string $ filename ): string
2060
2060
{
2061
+ // phpcs:disable Magento2.Functions.DiscouragedFunction
2061
2062
$ content = file_get_contents ($ filename );
2063
+ // phpcs:enable Magento2.Functions.DiscouragedFunction
2062
2064
return $ content !== false ? $ content : '' ;
2063
2065
}
2064
2066
@@ -3319,40 +3321,67 @@ private function findImageByColumnImage(string $productMediaPath, array &$images
3319
3321
$ content = filter_var ($ columnImage , FILTER_VALIDATE_URL )
3320
3322
? $ this ->getRemoteFileContent ($ columnImage )
3321
3323
: $ 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 ;
3352
3351
}
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 ' ];
3353
3382
}
3354
3383
}
3355
- return $ value ;
3384
+ return '' ;
3356
3385
}
3357
3386
3358
3387
/**
0 commit comments