Skip to content

Commit 58844c0

Browse files
Merge pull request #5438 from magento-borg/2.4.0-bugfixes-030929
Fixed Issues: - MC-31362: Media folder update - MC-30944: Incorrect flow of saving Newsletter templates - MC-31357: Customer file uploader update
2 parents dbc71bc + 09bc685 commit 58844c0

File tree

14 files changed

+845
-162
lines changed

14 files changed

+845
-162
lines changed

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/DeleteFolder.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
8+
declare(strict_types=1);
9+
710
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
811

912
use Magento\Framework\App\Action\HttpPostActionInterface;
@@ -60,13 +63,8 @@ public function execute()
6063
{
6164
try {
6265
$path = $this->getStorage()->getCmsWysiwygImages()->getCurrentPath();
63-
if (!$this->directoryResolver->validatePath($path, DirectoryList::MEDIA)) {
64-
throw new \Magento\Framework\Exception\LocalizedException(
65-
__('Directory %1 is not under storage root path.', $path)
66-
);
67-
}
6866
$this->getStorage()->deleteDirectory($path);
69-
67+
7068
return $this->resultRawFactory->create();
7169
} catch (\Exception $e) {
7270
$result = ['error' => true, 'message' => $e->getMessage()];

app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ public function __construct(
225225
*
226226
* @param string $path
227227
* @return void
228+
* @throws \Magento\Framework\Exception\FileSystemException
229+
* @throws \Magento\Framework\Exception\ValidatorException
228230
*/
229231
protected function createSubDirectories($path)
230232
{
@@ -295,6 +297,7 @@ protected function removeItemFromCollection($collection, $conditions)
295297
*
296298
* @param string $path Parent directory path
297299
* @return \Magento\Framework\Data\Collection\Filesystem
300+
* @throws \Exception
298301
*/
299302
public function getDirsCollection($path)
300303
{
@@ -393,6 +396,7 @@ public function getFilesCollection($path, $type = null)
393396
*
394397
* @param string $path Path to the directory
395398
* @return \Magento\Cms\Model\Wysiwyg\Images\Storage\Collection
399+
* @throws \Exception
396400
*/
397401
public function getCollection($path = null)
398402
{
@@ -485,6 +489,9 @@ public function deleteDirectory($path)
485489
*
486490
* @param string $path
487491
* @return void
492+
* @throws \Magento\Framework\Exception\FileSystemException
493+
* @throws \Magento\Framework\Exception\LocalizedException
494+
* @throws \Magento\Framework\Exception\ValidatorException
488495
*/
489496
protected function _deleteByPath($path)
490497
{
@@ -500,6 +507,8 @@ protected function _deleteByPath($path)
500507
*
501508
* @param string $target File path to be deleted
502509
* @return $this
510+
* @throws \Magento\Framework\Exception\FileSystemException
511+
* @throws \Magento\Framework\Exception\ValidatorException
503512
*/
504513
public function deleteFile($target)
505514
{
@@ -561,9 +570,11 @@ public function uploadFile($targetPath, $type = null)
561570
/**
562571
* Thumbnail path getter
563572
*
564-
* @param string $filePath original file path
565-
* @param bool $checkFile OPTIONAL is it necessary to check file availability
573+
* @param string $filePath original file path
574+
* @param bool $checkFile OPTIONAL is it necessary to check file availability
566575
* @return string|false
576+
* @throws \Magento\Framework\Exception\FileSystemException
577+
* @throws \Magento\Framework\Exception\ValidatorException
567578
*/
568579
public function getThumbnailPath($filePath, $checkFile = false)
569580
{
@@ -587,9 +598,11 @@ public function getThumbnailPath($filePath, $checkFile = false)
587598
/**
588599
* Thumbnail URL getter
589600
*
590-
* @param string $filePath original file path
591-
* @param bool $checkFile OPTIONAL is it necessary to check file availability
601+
* @param string $filePath original file path
602+
* @param bool $checkFile OPTIONAL is it necessary to check file availability
592603
* @return string|false
604+
* @throws \Magento\Framework\Exception\FileSystemException
605+
* @throws \Magento\Framework\Exception\ValidatorException
593606
*/
594607
public function getThumbnailUrl($filePath, $checkFile = false)
595608
{
@@ -610,6 +623,8 @@ public function getThumbnailUrl($filePath, $checkFile = false)
610623
* @param string $source Image path to be resized
611624
* @param bool $keepRatio Keep aspect ratio or not
612625
* @return bool|string Resized filepath or false if errors were occurred
626+
* @throws \Magento\Framework\Exception\FileSystemException
627+
* @throws \Magento\Framework\Exception\ValidatorException
613628
*/
614629
public function resizeFile($source, $keepRatio = true)
615630
{
@@ -643,6 +658,9 @@ public function resizeFile($source, $keepRatio = true)
643658
*
644659
* @param string $filename File basename
645660
* @return bool|string Thumbnail path or false for errors
661+
* @throws \Magento\Framework\Exception\FileSystemException
662+
* @throws \Magento\Framework\Exception\LocalizedException
663+
* @throws \Magento\Framework\Exception\ValidatorException
646664
*/
647665
public function resizeOnTheFly($filename)
648666
{
@@ -658,6 +676,8 @@ public function resizeOnTheFly($filename)
658676
*
659677
* @param bool|string $filePath Path to the file
660678
* @return string
679+
* @throws \Magento\Framework\Exception\FileSystemException
680+
* @throws \Magento\Framework\Exception\ValidatorException
661681
*/
662682
public function getThumbsPath($filePath = false)
663683
{
@@ -782,17 +802,28 @@ protected function _validatePath($path)
782802
*
783803
* @param string $path
784804
* @return string
805+
* @throws \Magento\Framework\Exception\ValidatorException
785806
*/
786807
protected function _sanitizePath($path)
787808
{
788-
return rtrim(preg_replace('~[/\\\]+~', '/', $this->_directory->getDriver()->getRealPathSafety($path)), '/');
809+
return rtrim(
810+
preg_replace(
811+
'~[/\\\]+~',
812+
'/',
813+
$this->_directory->getDriver()->getRealPathSafety(
814+
$this->_directory->getAbsolutePath($path)
815+
)
816+
),
817+
'/'
818+
);
789819
}
790820

791821
/**
792822
* Get path in root storage dir
793823
*
794824
* @param string $path
795825
* @return string|bool
826+
* @throws \Magento\Framework\Exception\ValidatorException
796827
*/
797828
protected function _getRelativePathToRoot($path)
798829
{

app/code/Magento/Cms/Test/Unit/Model/Wysiwyg/Images/StorageTest.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ class StorageTest extends \PHPUnit\Framework\TestCase
2929
protected $imagesStorage;
3030

3131
/**
32-
* @var \PHPUnit_Framework_MockObject_MockObject
32+
* @var \PHPUnit\Framework\MockObject\MockObject
3333
*/
3434
protected $filesystemMock;
3535

3636
/**
37-
* @var \PHPUnit_Framework_MockObject_MockObject
37+
* @var \PHPUnit\Framework\MockObject\MockObject
3838
*/
3939
protected $adapterFactoryMock;
4040

4141
/**
42-
* @var \PHPUnit_Framework_MockObject_MockObject
42+
* @var \PHPUnit\Framework\MockObject\MockObject
4343
*/
4444
protected $imageHelperMock;
4545

@@ -49,67 +49,67 @@ class StorageTest extends \PHPUnit\Framework\TestCase
4949
protected $resizeParameters;
5050

5151
/**
52-
* @var \Magento\Cms\Model\Wysiwyg\Images\Storage\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
52+
* @var \Magento\Cms\Model\Wysiwyg\Images\Storage\CollectionFactory|\PHPUnit\Framework\MockObject\MockObject
5353
*/
5454
protected $storageCollectionFactoryMock;
5555

5656
/**
57-
* @var \Magento\MediaStorage\Model\File\Storage\FileFactory|\PHPUnit_Framework_MockObject_MockObject
57+
* @var \Magento\MediaStorage\Model\File\Storage\FileFactory|\PHPUnit\Framework\MockObject\MockObject
5858
*/
5959
protected $storageFileFactoryMock;
6060

6161
/**
62-
* @var \Magento\MediaStorage\Model\File\Storage\DatabaseFactory|\PHPUnit_Framework_MockObject_MockObject
62+
* @var \Magento\MediaStorage\Model\File\Storage\DatabaseFactory|\PHPUnit\Framework\MockObject\MockObject
6363
*/
6464
protected $storageDatabaseFactoryMock;
6565

6666
/**
67-
* @var \Magento\MediaStorage\Model\File\Storage\Directory\DatabaseFactory|\PHPUnit_Framework_MockObject_MockObject
67+
* @var \Magento\MediaStorage\Model\File\Storage\Directory\DatabaseFactory|\PHPUnit\Framework\MockObject\MockObject
6868
*/
6969
protected $directoryDatabaseFactoryMock;
7070

7171
/**
72-
* @var \Magento\MediaStorage\Model\File\Storage\Directory\Database|\PHPUnit_Framework_MockObject_MockObject
72+
* @var \Magento\MediaStorage\Model\File\Storage\Directory\Database|\PHPUnit\Framework\MockObject\MockObject
7373
*/
7474
protected $directoryCollectionMock;
7575

7676
/**
77-
* @var \Magento\MediaStorage\Model\File\UploaderFactory|\PHPUnit_Framework_MockObject_MockObject
77+
* @var \Magento\MediaStorage\Model\File\UploaderFactory|\PHPUnit\Framework\MockObject\MockObject
7878
*/
7979
protected $uploaderFactoryMock;
8080

8181
/**
82-
* @var \Magento\Backend\Model\Session|\PHPUnit_Framework_MockObject_MockObject
82+
* @var \Magento\Backend\Model\Session|\PHPUnit\Framework\MockObject\MockObject
8383
*/
8484
protected $sessionMock;
8585

8686
/**
87-
* @var \Magento\Backend\Model\Url|\PHPUnit_Framework_MockObject_MockObject
87+
* @var \Magento\Backend\Model\Url|\PHPUnit\Framework\MockObject\MockObject
8888
*/
8989
protected $backendUrlMock;
9090

9191
/**
92-
* @var \Magento\Framework\Filesystem\Directory\Write|\PHPUnit_Framework_MockObject_MockObject
92+
* @var \Magento\Framework\Filesystem\Directory\Write|\PHPUnit\Framework\MockObject\MockObject
9393
*/
9494
protected $directoryMock;
9595

9696
/**
97-
* @var \Magento\Framework\Filesystem\DriverInterface|\PHPUnit_Framework_MockObject_MockObject
97+
* @var \Magento\Framework\Filesystem\DriverInterface|\PHPUnit\Framework\MockObject\MockObject
9898
*/
9999
protected $driverMock;
100100

101101
/**
102-
* @var \Magento\MediaStorage\Helper\File\Storage\Database|\PHPUnit_Framework_MockObject_MockObject
102+
* @var \Magento\MediaStorage\Helper\File\Storage\Database|\PHPUnit\Framework\MockObject\MockObject
103103
*/
104104
protected $coreFileStorageMock;
105105

106106
/**
107-
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager|\PHPUnit_Framework_MockObject_MockObject
107+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager|\PHPUnit\Framework\MockObject\MockObject
108108
*/
109109
protected $objectManagerHelper;
110110

111111
/**
112-
* @var \Magento\Framework\Filesystem\Io\File|\PHPUnit_Framework_MockObject_MockObject
112+
* @var \Magento\Framework\Filesystem\Io\File|\PHPUnit\Framework\MockObject\MockObject
113113
*/
114114
protected $ioFileMock;
115115

@@ -139,7 +139,7 @@ protected function setUp()
139139

140140
$this->directoryMock = $this->createPartialMock(
141141
\Magento\Framework\Filesystem\Directory\Write::class,
142-
['delete', 'getDriver', 'create', 'getRelativePath', 'isExist', 'isFile']
142+
['delete', 'getDriver', 'create', 'getRelativePath', 'getAbsolutePath', 'isExist', 'isFile']
143143
);
144144
$this->directoryMock->expects(
145145
$this->any()
@@ -283,6 +283,7 @@ public function testGetResizeHeight()
283283
public function testDeleteDirectoryOverRoot()
284284
{
285285
$this->driverMock->expects($this->atLeastOnce())->method('getRealPathSafety')->will($this->returnArgument(0));
286+
$this->directoryMock->expects($this->atLeastOnce())->method('getAbsolutePath')->will($this->returnArgument(0));
286287
$this->imagesStorage->deleteDirectory(self::INVALID_DIRECTORY_OVER_ROOT);
287288
}
288289

@@ -294,6 +295,7 @@ public function testDeleteDirectoryOverRoot()
294295
public function testDeleteRootDirectory()
295296
{
296297
$this->driverMock->expects($this->atLeastOnce())->method('getRealPathSafety')->will($this->returnArgument(0));
298+
$this->directoryMock->expects($this->atLeastOnce())->method('getAbsolutePath')->will($this->returnArgument(0));
297299
$this->imagesStorage->deleteDirectory(self::STORAGE_ROOT_DIR);
298300
}
299301

@@ -355,7 +357,7 @@ public function testGetDirsCollection($exclude, $include, $fileNames, $expectedR
355357

356358
$collection = [];
357359
foreach ($fileNames as $filename) {
358-
/** @var \Magento\Framework\DataObject|\PHPUnit_Framework_MockObject_MockObject $objectMock */
360+
/** @var \Magento\Framework\DataObject|\PHPUnit\Framework\MockObject\MockObject $objectMock */
359361
$objectMock = $this->createPartialMock(\Magento\Framework\DataObject::class, ['getFilename']);
360362
$objectMock->expects($this->any())
361363
->method('getFilename')
@@ -428,7 +430,7 @@ public function dirsCollectionDataProvider()
428430
*/
429431
protected function generalTestGetDirsCollection($path, $collectionArray = [], $expectedRemoveKeys = [])
430432
{
431-
/** @var StorageCollection|\PHPUnit_Framework_MockObject_MockObject $storageCollectionMock */
433+
/** @var StorageCollection|\PHPUnit\Framework\MockObject\MockObject $storageCollectionMock */
432434
$storageCollectionMock = $this->getMockBuilder(\Magento\Cms\Model\Wysiwyg\Images\Storage\Collection::class)
433435
->disableOriginalConstructor()
434436
->getMock();

0 commit comments

Comments
 (0)