6
6
*/
7
7
namespace Magento \Theme \Controller \Adminhtml \System \Design \Theme ;
8
8
9
+ use Magento \Backend \App \Action \Context ;
10
+ use Magento \Framework \App \Action \HttpGetActionInterface ;
11
+ use Magento \Framework \App \Response \Http \FileFactory ;
9
12
use Magento \Framework \App \ResponseInterface ;
10
13
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 ;
11
22
12
23
/**
13
- * Class DownloadCss
24
+ * Class for Download Css.
14
25
* @deprecated 100.2.0
26
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27
+ * @SuppressWarnings(PHPMD.Superglobals)
15
28
*/
16
- class DownloadCss extends \ Magento \ Theme \ Controller \ Adminhtml \ System \ Design \Theme
29
+ class DownloadCss extends Theme implements HttpGetActionInterface
17
30
{
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
+
18
57
/**
19
58
* Download css file
20
59
*
@@ -25,20 +64,19 @@ public function execute()
25
64
$ themeId = $ this ->getRequest ()->getParam ('theme_id ' );
26
65
$ file = $ this ->getRequest ()->getParam ('file ' );
27
66
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);
30
69
$ fileId = $ urlDecoder ->decode ($ file );
31
70
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 );
36
73
if (!$ theme ->getId ()) {
37
- throw new \InvalidArgumentException (sprintf ('Theme not found: "%1 ". ' , $ themeId ));
74
+ throw new \InvalidArgumentException (sprintf ('Theme not found: "%d ". ' , $ themeId ));
38
75
}
39
76
$ asset = $ this ->_assetRepo ->createAsset ($ fileId , ['themeModel ' => $ theme ]);
40
77
$ relPath = $ this ->_appFileSystem ->getDirectoryRead (DirectoryList::ROOT )
41
78
->getRelativePath ($ asset ->getSourceFile ());
79
+
42
80
return $ this ->_fileFactory ->create (
43
81
$ relPath ,
44
82
[
@@ -47,10 +85,14 @@ public function execute()
47
85
],
48
86
DirectoryList::ROOT
49
87
);
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 );
50
92
} 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) ));
52
94
$ this ->getResponse ()->setRedirect ($ this ->_redirect ->getRefererUrl ());
53
- $ this ->_objectManager ->get (\ Psr \ Log \ LoggerInterface::class)->critical ($ e );
95
+ $ this ->_objectManager ->get (LoggerInterface::class)->critical ($ e );
54
96
}
55
97
}
56
98
}
0 commit comments