Skip to content

Commit 80dc7ac

Browse files
committed
Merge remote-tracking branch 'origin/2.3.7-develop' into MC-38676
2 parents 5e7f1ce + 82d04e8 commit 80dc7ac

File tree

2 files changed

+143
-103
lines changed

2 files changed

+143
-103
lines changed

app/code/Magento/Theme/Controller/Adminhtml/System/Design/Theme/DownloadCss.php

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,54 @@
66
*/
77
namespace Magento\Theme\Controller\Adminhtml\System\Design\Theme;
88

9+
use Magento\Backend\App\Action\Context;
10+
use Magento\Framework\App\Action\HttpGetActionInterface;
11+
use Magento\Framework\App\Response\Http\FileFactory;
912
use Magento\Framework\App\ResponseInterface;
1013
use Magento\Framework\App\Filesystem\DirectoryList;
14+
use Magento\Framework\Escaper;
15+
use Magento\Framework\Filesystem;
16+
use Magento\Framework\Registry;
17+
use Magento\Framework\Url\DecoderInterface;
18+
use Magento\Framework\View\Asset\Repository;
19+
use Magento\Framework\View\Design\ThemeInterface;
20+
use Magento\Theme\Controller\Adminhtml\System\Design\Theme;
21+
use Psr\Log\LoggerInterface;
1122

1223
/**
13-
* Class DownloadCss
24+
* Class for Download Css.
1425
* @deprecated 100.2.0
26+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27+
* @SuppressWarnings(PHPMD.Superglobals)
1528
*/
16-
class DownloadCss extends \Magento\Theme\Controller\Adminhtml\System\Design\Theme
29+
class DownloadCss extends Theme implements HttpGetActionInterface
1730
{
31+
/**
32+
* @var Escaper
33+
*/
34+
private $escaper;
35+
36+
/**
37+
* DownloadCss constructor.
38+
* @param Context $context
39+
* @param Registry $coreRegistry
40+
* @param FileFactory $fileFactory
41+
* @param Repository $assetRepo
42+
* @param Filesystem $appFileSystem
43+
* @param Escaper|null $escaper
44+
*/
45+
public function __construct(
46+
Context $context,
47+
Registry $coreRegistry,
48+
FileFactory $fileFactory,
49+
Repository $assetRepo,
50+
Filesystem $appFileSystem,
51+
Escaper $escaper = null
52+
) {
53+
$this->escaper = $escaper ?? $context->getObjectManager()->get(Escaper::class);
54+
parent::__construct($context, $coreRegistry, $fileFactory, $assetRepo, $appFileSystem);
55+
}
56+
1857
/**
1958
* Download css file
2059
*
@@ -25,20 +64,19 @@ public function execute()
2564
$themeId = $this->getRequest()->getParam('theme_id');
2665
$file = $this->getRequest()->getParam('file');
2766

28-
/** @var $urlDecoder \Magento\Framework\Url\DecoderInterface */
29-
$urlDecoder = $this->_objectManager->get(\Magento\Framework\Url\DecoderInterface::class);
67+
/** @var $urlDecoder DecoderInterface */
68+
$urlDecoder = $this->_objectManager->get(DecoderInterface::class);
3069
$fileId = $urlDecoder->decode($file);
3170
try {
32-
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */
33-
$theme = $this->_objectManager->create(
34-
\Magento\Framework\View\Design\ThemeInterface::class
35-
)->load($themeId);
71+
/** @var $theme ThemeInterface */
72+
$theme = $this->_objectManager->create(ThemeInterface::class)->load($themeId);
3673
if (!$theme->getId()) {
37-
throw new \InvalidArgumentException(sprintf('Theme not found: "%1".', $themeId));
74+
throw new \InvalidArgumentException(sprintf('Theme not found: "%d".', $themeId));
3875
}
3976
$asset = $this->_assetRepo->createAsset($fileId, ['themeModel' => $theme]);
4077
$relPath = $this->_appFileSystem->getDirectoryRead(DirectoryList::ROOT)
4178
->getRelativePath($asset->getSourceFile());
79+
4280
return $this->_fileFactory->create(
4381
$relPath,
4482
[
@@ -47,10 +85,14 @@ public function execute()
4785
],
4886
DirectoryList::ROOT
4987
);
88+
} catch (\InvalidArgumentException $e) {
89+
$this->messageManager->addException($e, __('Theme not found: "%1".', $this->escaper->escapeHtml($themeId)));
90+
$this->getResponse()->setRedirect($this->_redirect->getRefererUrl());
91+
$this->_objectManager->get(LoggerInterface::class)->critical($e);
5092
} catch (\Exception $e) {
51-
$this->messageManager->addException($e, __('File not found: "%1".', $fileId));
93+
$this->messageManager->addException($e, __('File not found: "%1".', $this->escaper->escapeHtml($fileId)));
5294
$this->getResponse()->setRedirect($this->_redirect->getRefererUrl());
53-
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
95+
$this->_objectManager->get(LoggerInterface::class)->critical($e);
5496
}
5597
}
5698
}

0 commit comments

Comments
 (0)