1111use Magento \Catalog \Model \Product \Image \ConvertImageMiscParamsToReadableFormat ;
1212use Magento \Catalog \Model \Product \Media \ConfigInterface ;
1313use Magento \Framework \App \ObjectManager ;
14- use Magento \Framework \Config \ConfigOptionsListConstants ;
1514use Magento \Framework \Encryption \EncryptorInterface ;
1615use Magento \Framework \Exception \LocalizedException ;
17- use Magento \Framework \Filesystem ;
1816use Magento \Framework \View \Asset \ContextInterface ;
1917use Magento \Framework \View \Asset \LocalInterface ;
2018use Magento \Store \Model \StoreManagerInterface ;
21- use Magento \Framework \App \Filesystem \DirectoryList ;
2219
2320/**
2421 * A locally available image file asset that can be referred with a file path
@@ -91,11 +88,6 @@ class Image implements LocalInterface
9188 */
9289 private $ convertImageMiscParamsToReadableFormat ;
9390
94- /**
95- * @var Filesystem|null
96- */
97- private ?Filesystem $ fileSystem ;
98-
9991 /**
10092 * Image constructor.
10193 *
@@ -108,7 +100,6 @@ class Image implements LocalInterface
108100 * @param CatalogMediaConfig $catalogMediaConfig
109101 * @param StoreManagerInterface $storeManager
110102 * @param ConvertImageMiscParamsToReadableFormat $convertImageMiscParamsToReadableFormat
111- * @param Filesystem|null $fileSystem
112103 *
113104 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
114105 */
@@ -121,8 +112,7 @@ public function __construct(
121112 ImageHelper $ imageHelper = null ,
122113 CatalogMediaConfig $ catalogMediaConfig = null ,
123114 StoreManagerInterface $ storeManager = null ,
124- ?ConvertImageMiscParamsToReadableFormat $ convertImageMiscParamsToReadableFormat = null ,
125- ?Filesystem $ fileSystem = null
115+ ?ConvertImageMiscParamsToReadableFormat $ convertImageMiscParamsToReadableFormat = null
126116 ) {
127117 if (isset ($ miscParams ['image_type ' ])) {
128118 $ this ->sourceContentType = $ miscParams ['image_type ' ];
@@ -142,7 +132,6 @@ public function __construct(
142132 $ this ->mediaFormatUrl = $ catalogMediaConfig ->getMediaUrlFormat ();
143133 $ this ->convertImageMiscParamsToReadableFormat = $ convertImageMiscParamsToReadableFormat ?:
144134 ObjectManager::getInstance ()->get (ConvertImageMiscParamsToReadableFormat::class);
145- $ this ->fileSystem = $ fileSystem ?: ObjectManager::getInstance ()->get (Filesystem::class);
146135 }
147136
148137 /**
@@ -283,49 +272,21 @@ public function getModule()
283272 */
284273 private function getImageInfo ()
285274 {
286- $ mediaDirectory = $ this ->fileSystem ->getDirectoryRead (DirectoryList::MEDIA );
287275 $ data = implode ('_ ' , $ this ->convertToReadableFormat ($ this ->miscParams ));
288276
289277 $ pathTemplate = $ this ->getModule ()
290278 . DIRECTORY_SEPARATOR . "%s " . DIRECTORY_SEPARATOR
291279 . $ this ->getFilePath ();
292280
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 (
296286 '|\Q ' . DIRECTORY_SEPARATOR . '\E+| ' ,
297287 DIRECTORY_SEPARATOR ,
298288 sprintf ($ pathTemplate , hash (self ::HASH_ALGORITHM , $ data ))
299289 );
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 ;
329290 }
330291
331292 /**
0 commit comments