Skip to content

Commit 2716c26

Browse files
Merge pull request #5996 from magento-borg/2.3.6-bugfixes-08072020
Resolved Issues: - MC-31227: Media folder update - MC-35015: Catalog event update
2 parents fda3267 + 1a2ee46 commit 2716c26

File tree

10 files changed

+367
-51
lines changed

10 files changed

+367
-51
lines changed

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

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,76 @@
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

12+
use Magento\Backend\App\Action\Context;
13+
use Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
914
use Magento\Framework\App\Action\HttpPostActionInterface;
10-
use Magento\Framework\App\Filesystem\DirectoryList;
15+
use Magento\Framework\App\Filesystem\DirectoryResolver;
16+
use Magento\Framework\Controller\Result\Json;
17+
use Magento\Framework\Controller\Result\JsonFactory;
18+
use Magento\Framework\Controller\Result\RawFactory;
19+
use Magento\Framework\Controller\ResultInterface;
20+
use Magento\Framework\Registry;
1121

1222
/**
1323
* Delete image folder.
1424
*/
15-
class DeleteFolder extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images implements HttpPostActionInterface
25+
class DeleteFolder extends Images implements HttpPostActionInterface
1626
{
1727
/**
18-
* @var \Magento\Framework\Controller\Result\JsonFactory
28+
* @var JsonFactory
1929
*/
2030
protected $resultJsonFactory;
2131

2232
/**
23-
* @var \Magento\Framework\Controller\Result\RawFactory
33+
* @var RawFactory
2434
*/
2535
protected $resultRawFactory;
2636

2737
/**
28-
* @var \Magento\Framework\App\Filesystem\DirectoryResolver
38+
* @var DirectoryResolver
2939
*/
3040
private $directoryResolver;
3141

3242
/**
33-
* @param \Magento\Backend\App\Action\Context $context
34-
* @param \Magento\Framework\Registry $coreRegistry
35-
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
36-
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
37-
* @param \Magento\Framework\App\Filesystem\DirectoryResolver|null $directoryResolver
43+
* @param Context $context
44+
* @param Registry $coreRegistry
45+
* @param JsonFactory $resultJsonFactory
46+
* @param RawFactory $resultRawFactory
47+
* @param DirectoryResolver|null $directoryResolver
3848
*/
3949
public function __construct(
40-
\Magento\Backend\App\Action\Context $context,
41-
\Magento\Framework\Registry $coreRegistry,
42-
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
43-
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
44-
\Magento\Framework\App\Filesystem\DirectoryResolver $directoryResolver = null
50+
Context $context,
51+
Registry $coreRegistry,
52+
JsonFactory $resultJsonFactory,
53+
RawFactory $resultRawFactory,
54+
DirectoryResolver $directoryResolver = null
4555
) {
4656
parent::__construct($context, $coreRegistry);
4757
$this->resultRawFactory = $resultRawFactory;
4858
$this->resultJsonFactory = $resultJsonFactory;
49-
$this->directoryResolver = $directoryResolver
50-
?: $this->_objectManager->get(\Magento\Framework\App\Filesystem\DirectoryResolver::class);
59+
$this->directoryResolver = $directoryResolver ?? $this->_objectManager->get(DirectoryResolver::class);
5160
}
5261

5362
/**
5463
* Delete folder action.
5564
*
56-
* @return \Magento\Framework\Controller\ResultInterface
57-
* @throws \Magento\Framework\Exception\LocalizedException
65+
* @return ResultInterface
5866
*/
5967
public function execute()
6068
{
6169
try {
6270
$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-
}
6871
$this->getStorage()->deleteDirectory($path);
69-
72+
7073
return $this->resultRawFactory->create();
7174
} catch (\Exception $e) {
7275
$result = ['error' => true, 'message' => $e->getMessage()];
73-
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
76+
/** @var Json $resultJson */
7477
$resultJson = $this->resultJsonFactory->create();
7578

7679
return $resultJson->setData($result);

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ protected function setUp()
138138

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

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

app/code/Magento/ImportExport/Block/Adminhtml/Import/Frame/Result.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function addError($message)
102102
$this->addError($row);
103103
}
104104
} else {
105-
$this->_messages['error'][] = $message;
105+
$this->_messages['error'][] = $this->escapeHtml($message);
106106
}
107107
return $this;
108108
}
@@ -140,7 +140,8 @@ public function addSuccess($message, $appendImportButton = false)
140140
$this->addSuccess($row);
141141
}
142142
} else {
143-
$this->_messages['success'][] = $message . ($appendImportButton ? $this->getImportButtonHtml() : '');
143+
$escapedMessage = $this->escapeHtml($message);
144+
$this->_messages['success'][] = $escapedMessage . ($appendImportButton ? $this->getImportButtonHtml() : '');
144145
}
145146
return $this;
146147
}

app/code/Magento/ImportExport/Controller/Adminhtml/ImportResult.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public function __construct(
5656
}
5757

5858
/**
59+
* Add Error Messages for Import
60+
*
5961
* @param \Magento\Framework\View\Element\AbstractBlock $resultBlock
6062
* @param ProcessingErrorAggregatorInterface $errorAggregator
6163
* @return $this
@@ -68,7 +70,7 @@ protected function addErrorMessages(
6870
$message = '';
6971
$counter = 0;
7072
foreach ($this->getErrorMessages($errorAggregator) as $error) {
71-
$message .= ++$counter . '. ' . $error . '<br>';
73+
$message .= (++$counter) . '. ' . $error . '<br>';
7274
if ($counter >= self::LIMIT_ERRORS_MESSAGE) {
7375
break;
7476
}
@@ -88,7 +90,7 @@ protected function addErrorMessages(
8890
. '<a href="'
8991
. $this->createDownloadUrlImportHistoryFile($this->createErrorReport($errorAggregator))
9092
. '">' . __('Download full report') . '</a><br>'
91-
. '<div class="import-error-list">' . $message . '</div></div>'
93+
. '<div class="import-error-list">' . $resultBlock->escapeHtml($message) . '</div></div>'
9294
);
9395
} catch (\Exception $e) {
9496
foreach ($this->getErrorMessages($errorAggregator) as $errorMessage) {
@@ -101,6 +103,8 @@ protected function addErrorMessages(
101103
}
102104

103105
/**
106+
* Get all Error Messages from Import Results
107+
*
104108
* @param \Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface $errorAggregator
105109
* @return array
106110
*/
@@ -115,6 +119,8 @@ protected function getErrorMessages(ProcessingErrorAggregatorInterface $errorAgg
115119
}
116120

117121
/**
122+
* Get System Generated Exception
123+
*
118124
* @param ProcessingErrorAggregatorInterface $errorAggregator
119125
* @return \Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError[]
120126
*/
@@ -124,6 +130,8 @@ protected function getSystemExceptions(ProcessingErrorAggregatorInterface $error
124130
}
125131

126132
/**
133+
* Generate Error Report File
134+
*
127135
* @param ProcessingErrorAggregatorInterface $errorAggregator
128136
* @return string
129137
*/
@@ -141,6 +149,8 @@ protected function createErrorReport(ProcessingErrorAggregatorInterface $errorAg
141149
}
142150

143151
/**
152+
* Get Import History Url
153+
*
144154
* @param string $fileName
145155
* @return string
146156
*/

0 commit comments

Comments
 (0)