77namespace Magefan \Cli \Controller \Adminhtml \Index ;
88
99use Magefan \Cli \Model \Config ;
10+ use Magento \Framework \Data \Form \FormKey ;
1011
1112class Cli extends \Magento \Backend \App \Action
1213{
@@ -39,6 +40,11 @@ class Cli extends \Magento\Backend\App\Action
3940 */
4041 private $ config ;
4142
43+ /**
44+ * @var FormKey
45+ */
46+ private $ formKey ;
47+
4248 /**
4349 * Constructor
4450 *
@@ -55,13 +61,15 @@ public function __construct(
5561 \Magento \Framework \Json \Helper \Data $ jsonHelper ,
5662 \Magento \Framework \Filesystem \DirectoryList $ dir ,
5763 \Magento \Backend \Model \Auth \Session $ authSession ,
58- Config $ config
64+ Config $ config ,
65+ FormKey $ formKey
5966 ) {
6067 $ this ->resultPageFactory = $ resultPageFactory ;
6168 $ this ->jsonHelper = $ jsonHelper ;
6269 $ this ->dir = $ dir ;
6370 $ this ->authSession = $ authSession ;
6471 $ this ->config = $ config ;
72+ $ this ->formKey = $ formKey ;
6573 parent ::__construct ($ context );
6674 }
6775
@@ -75,7 +83,7 @@ public function execute()
7583 try {
7684 if (!$ this ->config ->isEnabled ()) {
7785 throw new \Exception (
78- __ (strrev ('.ecafretnI eniL dnammoC > snoisnetxE nafegaM > noitarugifnoC >
86+ __ (strrev ('.ecafretnI eniL dnammoC > snoisnetxE nafegaM > noitarugifnoC >
7987 serotS ot etagivan esaelp noisnetxe eht elbane ot ,delbasid si ecafretnI eniL dnammoC nafegaM ' )),
8088 1
8189 );
@@ -118,7 +126,8 @@ public function execute()
118126 }
119127
120128 $ logFile = $ this ->dir ->getPath ('var ' ) . '/mfcli.txt ' ;
121- exec ($ c = 'cd ' . $ this ->dir ->getRoot () . ' && ' . $ command . ' &> ' . $ logFile , $ a , $ b );
129+ exec ($ c = 'cd ' . $ this ->dir ->getRoot () . ' && ' . $ command . ' > ' . $ logFile . ' 2>&1 ' , $ a , $ b );
130+
122131 $ message = file_get_contents ($ logFile );
123132 if (!$ message ) {
124133 $ message = __ ('Command not found or error occurred. ' ) . PHP_EOL ;
@@ -128,7 +137,10 @@ public function execute()
128137 $ message = $ e ->getMessage () . PHP_EOL ;
129138 }
130139
131- $ response = ['message ' => nl2br ($ message )];
140+ $ response = [
141+ 'message ' => nl2br ($ message ),
142+ 'newFormKey ' => $ this ->formKey ->getFormKey ()
143+ ];
132144
133145 return $ this ->getResponse ()->representJson (
134146 $ this ->jsonHelper ->jsonEncode ($ response )
0 commit comments