|
| 1 | +diff -Naur a/vendor/magento/framework/File/Uploader.php b/vendor/magento/framework/File/Uploader.php |
| 2 | +--- a/vendor/magento/framework/File/Uploader.php |
| 3 | ++++ b/vendor/magento/framework/File/Uploader.php |
| 4 | +@@ -6,7 +6,10 @@ |
| 5 | + namespace Magento\Framework\File; |
| 6 | + |
| 7 | + use Magento\Framework\App\Filesystem\DirectoryList; |
| 8 | ++use Magento\Framework\App\ObjectManager; |
| 9 | + use Magento\Framework\Exception\FileSystemException; |
| 10 | ++use Magento\Framework\Filesystem\DriverInterface; |
| 11 | ++use Magento\Framework\Filesystem\DriverPool; |
| 12 | + use Magento\Framework\Validation\ValidationException; |
| 13 | + |
| 14 | + /** |
| 15 | +@@ -144,15 +147,13 @@ class Uploader |
| 16 | + |
| 17 | + /** |
| 18 | + * Maximum Image Width resolution in pixels. For image resizing on client side |
| 19 | +- * @deprecated |
| 20 | +- * @see \Magento\Framework\Image\Adapter\UploadConfigInterface::getMaxWidth() |
| 21 | ++ * @deprecated @see \Magento\Framework\Image\Adapter\UploadConfigInterface::getMaxWidth() |
| 22 | + */ |
| 23 | + const MAX_IMAGE_WIDTH = 1920; |
| 24 | + |
| 25 | + /** |
| 26 | + * Maximum Image Height resolution in pixels. For image resizing on client side |
| 27 | +- * @deprecated |
| 28 | +- * @see \Magento\Framework\Image\Adapter\UploadConfigInterface::getMaxHeight() |
| 29 | ++ * @deprecated @see \Magento\Framework\Image\Adapter\UploadConfigInterface::getMaxHeight() |
| 30 | + */ |
| 31 | + const MAX_IMAGE_HEIGHT = 1200; |
| 32 | + |
| 33 | +@@ -169,21 +170,32 @@ class Uploader |
| 34 | + */ |
| 35 | + private $directoryList; |
| 36 | + |
| 37 | ++ /** |
| 38 | ++ * @var DriverPool|null |
| 39 | ++ */ |
| 40 | ++ private $driverPool; |
| 41 | ++ |
| 42 | ++ /** |
| 43 | ++ * @var DriverInterface|null |
| 44 | ++ */ |
| 45 | ++ private $fileDriver; |
| 46 | ++ |
| 47 | + /** |
| 48 | + * Init upload |
| 49 | + * |
| 50 | + * @param string|array $fileId |
| 51 | + * @param \Magento\Framework\File\Mime|null $fileMime |
| 52 | + * @param DirectoryList|null $directoryList |
| 53 | ++ * @param DriverPool|null $driverPool |
| 54 | + * @throws \DomainException |
| 55 | + */ |
| 56 | + public function __construct( |
| 57 | + $fileId, |
| 58 | + Mime $fileMime = null, |
| 59 | +- DirectoryList $directoryList = null |
| 60 | ++ DirectoryList $directoryList = null, |
| 61 | ++ DriverPool $driverPool = null |
| 62 | + ) { |
| 63 | +- $this->directoryList= $directoryList ?: \Magento\Framework\App\ObjectManager::getInstance() |
| 64 | +- ->get(DirectoryList::class); |
| 65 | ++ $this->directoryList= $directoryList ?: ObjectManager::getInstance()->get(DirectoryList::class); |
| 66 | + |
| 67 | + $this->_setUploadFileId($fileId); |
| 68 | + if (!file_exists($this->_file['tmp_name'])) { |
| 69 | +@@ -192,7 +204,8 @@ class Uploader |
| 70 | + } else { |
| 71 | + $this->_fileExists = true; |
| 72 | + } |
| 73 | +- $this->fileMime = $fileMime ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Mime::class); |
| 74 | ++ $this->fileMime = $fileMime ?: ObjectManager::getInstance()->get(Mime::class); |
| 75 | ++ $this->driverPool = $driverPool; |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | +@@ -230,7 +243,7 @@ class Uploader |
| 80 | + $this->setAllowCreateFolders(true); |
| 81 | + $this->_dispretionPath = static::getDispersionPath($fileName); |
| 82 | + $destinationFile .= $this->_dispretionPath; |
| 83 | +- $this->_createDestinationFolder($destinationFile); |
| 84 | ++ $this->createDestinationFolder($destinationFile); |
| 85 | + } |
| 86 | + |
| 87 | + if ($this->_allowRenameFiles) { |
| 88 | +@@ -275,13 +288,11 @@ class Uploader |
| 89 | + * @return void |
| 90 | + * @throws FileSystemException |
| 91 | + */ |
| 92 | +- private function validateDestination($destinationFolder) |
| 93 | ++ private function validateDestination(string $destinationFolder): void |
| 94 | + { |
| 95 | + if ($this->_allowCreateFolders) { |
| 96 | +- $this->_createDestinationFolder($destinationFolder); |
| 97 | +- } |
| 98 | +- |
| 99 | +- if (!is_writable($destinationFolder)) { |
| 100 | ++ $this->createDestinationFolder($destinationFolder); |
| 101 | ++ } elseif (!$this->getFileDriver()->isWritable($destinationFolder)) { |
| 102 | + throw new FileSystemException(__('Destination folder is not writable or does not exists.')); |
| 103 | + } |
| 104 | + } |
| 105 | +@@ -655,7 +666,7 @@ class Uploader |
| 106 | + * @return \Magento\Framework\File\Uploader |
| 107 | + * @throws FileSystemException |
| 108 | + */ |
| 109 | +- private function _createDestinationFolder($destinationFolder) |
| 110 | ++ private function createDestinationFolder(string $destinationFolder) |
| 111 | + { |
| 112 | + if (!$destinationFolder) { |
| 113 | + return $this; |
| 114 | +@@ -665,11 +676,13 @@ class Uploader |
| 115 | + $destinationFolder = substr($destinationFolder, 0, -1); |
| 116 | + } |
| 117 | + |
| 118 | +- if (!(@is_dir($destinationFolder) |
| 119 | +- || @mkdir($destinationFolder, 0777, true) |
| 120 | +- )) { |
| 121 | +- throw new FileSystemException(__('Unable to create directory %1.', $destinationFolder)); |
| 122 | ++ if (!$this->getFileDriver()->isDirectory($destinationFolder)) { |
| 123 | ++ $result = $this->getFileDriver()->createDirectory($destinationFolder); |
| 124 | ++ if (!$result) { |
| 125 | ++ throw new FileSystemException(__('Unable to create directory %1.', $destinationFolder)); |
| 126 | ++ } |
| 127 | + } |
| 128 | ++ |
| 129 | + return $this; |
| 130 | + } |
| 131 | + |
| 132 | +@@ -732,4 +745,20 @@ class Uploader |
| 133 | + } |
| 134 | + return $dispersionPath; |
| 135 | + } |
| 136 | ++ |
| 137 | ++ /** |
| 138 | ++ * Get driver for file |
| 139 | ++ * |
| 140 | ++ * @deprecated |
| 141 | ++ * @return DriverInterface |
| 142 | ++ */ |
| 143 | ++ private function getFileDriver(): DriverInterface |
| 144 | ++ { |
| 145 | ++ if (!$this->fileDriver) { |
| 146 | ++ $this->driverPool = $this->driverPool ?: ObjectManager::getInstance()->get(DriverPool::class); |
| 147 | ++ $this->fileDriver = $this->driverPool->getDriver(DriverPool::FILE); |
| 148 | ++ } |
| 149 | ++ |
| 150 | ++ return $this->fileDriver; |
| 151 | ++ } |
| 152 | + } |
0 commit comments