6
6
namespace Magento \Catalog \Model ;
7
7
8
8
use Magento \Framework \File \Uploader ;
9
+ use Magento \Framework \App \ObjectManager ;
10
+ use Magento \Framework \File \Name ;
9
11
10
12
/**
11
13
* Catalog image uploader
@@ -74,17 +76,23 @@ class ImageUploader
74
76
private $ allowedMimeTypes ;
75
77
76
78
/**
77
- * ImageUploader constructor
79
+ * @var \Magento\Framework\File\Name
80
+ */
81
+ private $ fileNameLookup ;
82
+
83
+ /**
84
+ * ImageUploader constructor.
78
85
*
79
86
* @param \Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase
80
87
* @param \Magento\Framework\Filesystem $filesystem
81
88
* @param \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory
82
89
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
83
90
* @param \Psr\Log\LoggerInterface $logger
84
- * @param string $baseTmpPath
85
- * @param string $basePath
86
- * @param string[] $allowedExtensions
87
- * @param string[] $allowedMimeTypes
91
+ * @param $baseTmpPath
92
+ * @param $basePath
93
+ * @param $allowedExtensions
94
+ * @param array $allowedMimeTypes
95
+ * @param Name|null $fileNameLookup
88
96
*/
89
97
public function __construct (
90
98
\Magento \MediaStorage \Helper \File \Storage \Database $ coreFileStorageDatabase ,
@@ -95,7 +103,8 @@ public function __construct(
95
103
$ baseTmpPath ,
96
104
$ basePath ,
97
105
$ allowedExtensions ,
98
- $ allowedMimeTypes = []
106
+ $ allowedMimeTypes = [],
107
+ Name $ fileNameLookup = null
99
108
) {
100
109
$ this ->coreFileStorageDatabase = $ coreFileStorageDatabase ;
101
110
$ this ->mediaDirectory = $ filesystem ->getDirectoryWrite (\Magento \Framework \App \Filesystem \DirectoryList::MEDIA );
@@ -106,6 +115,7 @@ public function __construct(
106
115
$ this ->basePath = $ basePath ;
107
116
$ this ->allowedExtensions = $ allowedExtensions ;
108
117
$ this ->allowedMimeTypes = $ allowedMimeTypes ;
118
+ $ this ->fileNameLookup = $ fileNameLookup ?? ObjectManager::getInstance ()->get (Name::class);
109
119
}
110
120
111
121
/**
@@ -203,7 +213,7 @@ public function moveFileFromTmp($imageName, $returnRelativePath = false)
203
213
204
214
$ baseImagePath = $ this ->getFilePath (
205
215
$ basePath ,
206
- Uploader:: getNewFileName (
216
+ $ this -> fileNameLookup -> getNewFileName (
207
217
$ this ->mediaDirectory ->getAbsolutePath (
208
218
$ this ->getFilePath ($ basePath , $ imageName )
209
219
)
0 commit comments