Skip to content

Commit 251704c

Browse files
karyna-tandrewbess
authored andcommitted
rollback to check failure
1 parent df203c7 commit 251704c

File tree

2 files changed

+58
-20
lines changed

2 files changed

+58
-20
lines changed

app/code/Magento/Downloadable/Helper/File.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ protected function _moveFileFromTmp($baseTmpPath, $basePath, $file)
140140
$file = substr($file, 0, strlen($file) - 4);
141141
}
142142
// phpcs:ignore Magento2.Functions.DiscouragedFunction
143-
144143
$destFile = dirname($file) . '/'
145144
. Uploader::getNewFileName($this->getFilePath($basePath, $file));
146145

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

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -145,29 +145,31 @@ class Uploader
145145
*/
146146
private $filesystem;
147147

148-
/**
148+
/**#@+
149149
* File upload type (multiple or single)
150150
*/
151-
public const SINGLE_STYLE = 0;
151+
const SINGLE_STYLE = 0;
152+
153+
const MULTIPLE_STYLE = 1;
152154

153-
public const MULTIPLE_STYLE = 1;
155+
/**#@-*/
154156

155157
/**
156158
* Temp file name empty code
157159
*/
158-
public const TMP_NAME_EMPTY = 666;
160+
const TMP_NAME_EMPTY = 666;
159161

160162
/**
161163
* Maximum Image Width resolution in pixels. For image resizing on client side
162164
* @deprecated @see \Magento\Framework\Image\Adapter\UploadConfigInterface::getMaxWidth()
163165
*/
164-
public const MAX_IMAGE_WIDTH = 1920;
166+
const MAX_IMAGE_WIDTH = 1920;
165167

166168
/**
167169
* Maximum Image Height resolution in pixels. For image resizing on client side
168170
* @deprecated @see \Magento\Framework\Image\Adapter\UploadConfigInterface::getMaxHeight()
169171
*/
170-
public const MAX_IMAGE_HEIGHT = 1200;
172+
const MAX_IMAGE_HEIGHT = 1200;
171173

172174
/**
173175
* Resulting of uploaded file
@@ -206,7 +208,6 @@ class Uploader
206208
* @param DriverPool|null $driverPool
207209
* @param TargetDirectory|null $targetDirectory
208210
* @param Filesystem|null $filesystem
209-
* @param LoggerInterface|null $logger
210211
* @throws \DomainException
211212
*/
212213
public function __construct(
@@ -215,14 +216,12 @@ public function __construct(
215216
DirectoryList $directoryList = null,
216217
DriverPool $driverPool = null,
217218
TargetDirectory $targetDirectory = null,
218-
Filesystem $filesystem = null,
219-
LoggerInterface $logger = null
219+
Filesystem $filesystem = null
220220
) {
221221
$this->directoryList = $directoryList ?: ObjectManager::getInstance()->get(DirectoryList::class);
222222
$this->targetDirectory = $targetDirectory ?: ObjectManager::getInstance()->get(TargetDirectory::class);
223223

224224
$this->filesystem = $filesystem ?: ObjectManager::getInstance()->get(FileSystem::class);
225-
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
226225
$this->_setUploadFileId($fileId);
227226
if (!file_exists($this->_file['tmp_name'])) {
228227
$code = empty($this->_file['tmp_name']) ? self::TMP_NAME_EMPTY : 0;
@@ -251,7 +250,7 @@ protected function _afterSave($result)
251250
*
252251
* @param string $destinationFolder
253252
* @param string $newFileName
254-
* @return array|false
253+
* @return array
255254
* @throws \Exception
256255
* @SuppressWarnings(PHPMD.NPathComplexity)
257256
*/
@@ -323,7 +322,7 @@ private function validateDestination(string $destinationFolder): void
323322
}
324323
if ($this->_allowCreateFolders) {
325324
$this->createDestinationFolder($destinationFolder);
326-
} elseif (!$this->targetDirectory
325+
} elseif (!$this->getTargetDirectory()
327326
->getDirectoryWrite(DirectoryList::ROOT)
328327
->isWritable($destinationFolder)
329328
) {
@@ -356,24 +355,66 @@ protected function _moveFile($tmpPath, $destPath)
356355
$rootCode = DirectoryList::PUB;
357356

358357
try {
359-
if (strpos($destPath, $this->directoryList->getPath($rootCode)) !== 0) {
358+
if (strpos($destPath, $this->getDirectoryList()->getPath($rootCode)) !== 0) {
360359
$rootCode = DirectoryList::ROOT;
361360
}
362361

363-
$destPath = str_replace($this->directoryList->getPath($rootCode), '', $destPath);
364-
$directory = $this->targetDirectory->getDirectoryWrite($rootCode);
362+
$destPath = str_replace($this->getDirectoryList()->getPath($rootCode), '', $destPath);
363+
$directory = $this->getTargetDirectory()->getDirectoryWrite($rootCode);
365364

366365
return $this->getFileDriver()->rename(
367366
$tmpPath,
368367
$directory->getAbsolutePath($destPath),
369368
$directory->getDriver()
370369
);
371370
} catch (FileSystemException $exception) {
372-
$this->logger->critical($exception->getMessage());
371+
$this->getLogger()->critical($exception->getMessage());
373372
return false;
374373
}
375374
}
376375

376+
/**
377+
* Get logger instance.
378+
*
379+
* @deprecated
380+
* @return LoggerInterface
381+
*/
382+
private function getLogger(): LoggerInterface
383+
{
384+
if (!$this->logger) {
385+
$this->logger = ObjectManager::getInstance()->get(LoggerInterface::class);
386+
}
387+
return $this->logger;
388+
}
389+
390+
/**
391+
* Retrieves target directory.
392+
*
393+
* @return TargetDirectory
394+
*/
395+
private function getTargetDirectory(): TargetDirectory
396+
{
397+
if (!isset($this->targetDirectory)) {
398+
$this->targetDirectory = ObjectManager::getInstance()->get(TargetDirectory::class);
399+
}
400+
401+
return $this->targetDirectory;
402+
}
403+
404+
/**
405+
* Retrieves directory list.
406+
*
407+
* @return DirectoryList
408+
*/
409+
private function getDirectoryList(): DirectoryList
410+
{
411+
if (!isset($this->directoryList)) {
412+
$this->directoryList = ObjectManager::getInstance()->get(DirectoryList::class);
413+
}
414+
415+
return $this->directoryList;
416+
}
417+
377418
/**
378419
* Validate file before save
379420
*
@@ -732,7 +773,7 @@ private function createDestinationFolder(string $destinationFolder)
732773
$destinationFolder = substr($destinationFolder, 0, -1);
733774
}
734775

735-
$rootDirectory = $this->targetDirectory->getDirectoryWrite(DirectoryList::ROOT);
776+
$rootDirectory = $this->getTargetDirectory()->getDirectoryWrite(DirectoryList::ROOT);
736777

737778
if (!$rootDirectory->isDirectory($destinationFolder)) {
738779
$result = $rootDirectory->getDriver()->createDirectory($destinationFolder);
@@ -753,11 +794,9 @@ private function createDestinationFolder(string $destinationFolder)
753794
public static function getNewFileName($destinationFile)
754795
{
755796
/** @var Filesystem $fileSystem */
756-
// phpcs:ignore Magento2.PHP.AutogeneratedClassNotInConstructor
757797
$fileSystem = ObjectManager::getInstance()->get(Filesystem::class);
758798
$local = $fileSystem->getDirectoryRead(DirectoryList::ROOT);
759799
/** @var TargetDirectory $targetDirectory */
760-
// phpcs:ignore Magento2.PHP.AutogeneratedClassNotInConstructor
761800
$targetDirectory = ObjectManager::getInstance()->get(TargetDirectory::class);
762801
$remote = $targetDirectory->getDirectoryRead(DirectoryList::ROOT);
763802

0 commit comments

Comments
 (0)