11
11
use Magento \Catalog \Model \Product \Image \ConvertImageMiscParamsToReadableFormat ;
12
12
use Magento \Catalog \Model \Product \Media \ConfigInterface ;
13
13
use Magento \Framework \App \ObjectManager ;
14
- use Magento \Framework \Config \ConfigOptionsListConstants ;
15
14
use Magento \Framework \Encryption \EncryptorInterface ;
16
15
use Magento \Framework \Exception \LocalizedException ;
17
- use Magento \Framework \Filesystem ;
18
16
use Magento \Framework \View \Asset \ContextInterface ;
19
17
use Magento \Framework \View \Asset \LocalInterface ;
20
18
use Magento \Store \Model \StoreManagerInterface ;
21
- use Magento \Framework \App \Filesystem \DirectoryList ;
22
19
23
20
/**
24
21
* A locally available image file asset that can be referred with a file path
@@ -91,11 +88,6 @@ class Image implements LocalInterface
91
88
*/
92
89
private $ convertImageMiscParamsToReadableFormat ;
93
90
94
- /**
95
- * @var Filesystem|null
96
- */
97
- private ?Filesystem $ fileSystem ;
98
-
99
91
/**
100
92
* Image constructor.
101
93
*
@@ -108,7 +100,6 @@ class Image implements LocalInterface
108
100
* @param CatalogMediaConfig $catalogMediaConfig
109
101
* @param StoreManagerInterface $storeManager
110
102
* @param ConvertImageMiscParamsToReadableFormat $convertImageMiscParamsToReadableFormat
111
- * @param Filesystem|null $fileSystem
112
103
*
113
104
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
114
105
*/
@@ -121,8 +112,7 @@ public function __construct(
121
112
ImageHelper $ imageHelper = null ,
122
113
CatalogMediaConfig $ catalogMediaConfig = null ,
123
114
StoreManagerInterface $ storeManager = null ,
124
- ?ConvertImageMiscParamsToReadableFormat $ convertImageMiscParamsToReadableFormat = null ,
125
- ?Filesystem $ fileSystem = null
115
+ ?ConvertImageMiscParamsToReadableFormat $ convertImageMiscParamsToReadableFormat = null
126
116
) {
127
117
if (isset ($ miscParams ['image_type ' ])) {
128
118
$ this ->sourceContentType = $ miscParams ['image_type ' ];
@@ -142,7 +132,6 @@ public function __construct(
142
132
$ this ->mediaFormatUrl = $ catalogMediaConfig ->getMediaUrlFormat ();
143
133
$ this ->convertImageMiscParamsToReadableFormat = $ convertImageMiscParamsToReadableFormat ?:
144
134
ObjectManager::getInstance ()->get (ConvertImageMiscParamsToReadableFormat::class);
145
- $ this ->fileSystem = $ fileSystem ?: ObjectManager::getInstance ()->get (Filesystem::class);
146
135
}
147
136
148
137
/**
@@ -283,49 +272,21 @@ public function getModule()
283
272
*/
284
273
private function getImageInfo ()
285
274
{
286
- $ mediaDirectory = $ this ->fileSystem ->getDirectoryRead (DirectoryList::MEDIA );
287
275
$ data = implode ('_ ' , $ this ->convertToReadableFormat ($ this ->miscParams ));
288
276
289
277
$ pathTemplate = $ this ->getModule ()
290
278
. DIRECTORY_SEPARATOR . "%s " . DIRECTORY_SEPARATOR
291
279
. $ this ->getFilePath ();
292
280
293
- // New paths are generated without dependency on
294
- // an encryption key.
295
- $ hashBasedPath = preg_replace (
281
+ /**
282
+ * New paths are generated without dependency on
283
+ * an encryption key.
284
+ */
285
+ return preg_replace (
296
286
'|\Q ' . DIRECTORY_SEPARATOR . '\E+| ' ,
297
287
DIRECTORY_SEPARATOR ,
298
288
sprintf ($ pathTemplate , hash (self ::HASH_ALGORITHM , $ data ))
299
289
);
300
-
301
- if ($ mediaDirectory ->isExist ($ this ->context ->getPath () . DIRECTORY_SEPARATOR . $ hashBasedPath )) {
302
- return $ hashBasedPath ;
303
- }
304
-
305
- // This loop is intended to preserve backward compatibility and keep
306
- // existing encryption key based media gallery cache valid
307
- // even if an encryption key was changed.
308
- $ keys = explode ("\n" , $ this ->encryptor ->exportKeys ());
309
- foreach ($ keys as $ key ) {
310
- if (str_starts_with ($ key , ConfigOptionsListConstants::STORE_KEY_ENCODED_RANDOM_STRING_PREFIX )) {
311
- // phpcs:disable Magento2.Functions.DiscouragedFunction
312
- $ key = base64_decode (
313
- substr ($ key , strlen (ConfigOptionsListConstants::STORE_KEY_ENCODED_RANDOM_STRING_PREFIX ))
314
- );
315
- }
316
-
317
- $ keyBasedPath = preg_replace (
318
- '|\Q ' . DIRECTORY_SEPARATOR . '\E+| ' ,
319
- DIRECTORY_SEPARATOR ,
320
- sprintf ($ pathTemplate , hash_hmac (self ::HASH_ALGORITHM , $ data , $ key ))
321
- );
322
-
323
- if ($ mediaDirectory ->isExist ($ this ->context ->getPath () . DIRECTORY_SEPARATOR . $ keyBasedPath )) {
324
- return $ keyBasedPath ;
325
- }
326
- }
327
-
328
- return $ hashBasedPath ;
329
290
}
330
291
331
292
/**
0 commit comments