Skip to content

Commit 9b32a17

Browse files
committed
MC-18100: Changes in Downloadable product upload controller
1 parent 4661f62 commit 9b32a17

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

lib/internal/Magento/Framework/File/Uploader.php

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,13 @@ class Uploader
173173
*
174174
* @param string|array $fileId
175175
* @param \Magento\Framework\File\Mime|null $fileMime
176+
* @param DirectoryList|null $directoryList
176177
* @throws \DomainException
177178
*/
178179
public function __construct(
179180
$fileId,
180-
Mime $fileMime = null
181+
Mime $fileMime = null,
182+
DirectoryList $directoryList = null
181183
) {
182184
$this->_setUploadFileId($fileId);
183185
if (!file_exists($this->_file['tmp_name'])) {
@@ -187,6 +189,8 @@ public function __construct(
187189
$this->_fileExists = true;
188190
}
189191
$this->fileMime = $fileMime ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Mime::class);
192+
$this->directoryList= $directoryList ?: \Magento\Framework\App\ObjectManager::getInstance()
193+
->get(DirectoryList::class);
190194
}
191195

192196
/**
@@ -610,14 +614,14 @@ private function validateFileId(array $fileId)
610614
if (preg_match('/\.\.(\\\|\/)/', $tmpName) !== 1) {
611615
$allowedFolders = [
612616
sys_get_temp_dir(),
613-
$this->getDirectoryList()->getPath(DirectoryList::MEDIA),
614-
$this->getDirectoryList()->getPath(DirectoryList::VAR_DIR),
615-
$this->getDirectoryList()->getPath(DirectoryList::TMP),
616-
$this->getDirectoryList()->getPath(DirectoryList::UPLOAD),
617+
$this->directoryList->getPath(DirectoryList::MEDIA),
618+
$this->directoryList->getPath(DirectoryList::VAR_DIR),
619+
$this->directoryList->getPath(DirectoryList::TMP),
620+
$this->directoryList->getPath(DirectoryList::UPLOAD),
617621
];
618622

619623
$disallowedFolders = [
620-
$this->getDirectoryList()->getPath(DirectoryList::LOG),
624+
$this->directoryList->getPath(DirectoryList::LOG),
621625
];
622626

623627
foreach ($allowedFolders as $allowedFolder) {
@@ -643,19 +647,6 @@ private function validateFileId(array $fileId)
643647
}
644648
}
645649

646-
/**
647-
* @return DirectoryList
648-
*/
649-
private function getDirectoryList(): DirectoryList
650-
{
651-
if ($this->directoryList === null) {
652-
$this->directoryList = \Magento\Framework\App\ObjectManager::getInstance()
653-
->get(DirectoryList::class);
654-
}
655-
656-
return $this->directoryList;
657-
}
658-
659650
/**
660651
* Create destination folder
661652
*

0 commit comments

Comments
 (0)