Skip to content

Commit d16b8c1

Browse files
author
Yuri Kovsher
committed
Merge remote-tracking branch 'remotes/tango-ce/MAGETWO-2204' into MAGETWO-33812
2 parents 987994b + 5f1b15d commit d16b8c1

File tree

6 files changed

+656
-19
lines changed

6 files changed

+656
-19
lines changed

app/code/Magento/Backup/Controller/Adminhtml/Index/Download.php

100644100755
Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,51 @@
1010

1111
class Download extends \Magento\Backup\Controller\Adminhtml\Index
1212
{
13+
/**
14+
* @var \Magento\Framework\Controller\Result\RawFactory
15+
*/
16+
protected $resultRawFactory;
17+
18+
/**
19+
* @var \Magento\Backend\Model\View\Result\RedirectFactory
20+
*/
21+
protected $resultRedirectFactory;
22+
23+
/**
24+
* @param \Magento\Backend\App\Action\Context $context
25+
* @param \Magento\Framework\Registry $coreRegistry
26+
* @param \Magento\Framework\Backup\Factory $backupFactory
27+
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
28+
* @param \Magento\Backup\Model\BackupFactory $backupModelFactory
29+
* @param \Magento\Framework\App\MaintenanceMode $maintenanceMode
30+
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
31+
* @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory
32+
*/
33+
public function __construct(
34+
\Magento\Backend\App\Action\Context $context,
35+
\Magento\Framework\Registry $coreRegistry,
36+
\Magento\Framework\Backup\Factory $backupFactory,
37+
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
38+
\Magento\Backup\Model\BackupFactory $backupModelFactory,
39+
\Magento\Framework\App\MaintenanceMode $maintenanceMode,
40+
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
41+
\Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory) {
42+
parent::__construct(
43+
$context,
44+
$coreRegistry,
45+
$backupFactory,
46+
$fileFactory,
47+
$backupModelFactory,
48+
$maintenanceMode
49+
);
50+
$this->resultRawFactory = $resultRawFactory;
51+
$this->resultRedirectFactory = $resultRedirectFactory;
52+
}
53+
1354
/**
1455
* Download backup action
1556
*
1657
* @return void|\Magento\Backend\App\Action
17-
* @SuppressWarnings(PHPMD.ExitExpression)
1858
*/
1959
public function execute()
2060
{
@@ -25,22 +65,25 @@ public function execute()
2565
);
2666

2767
if (!$backup->getTime() || !$backup->exists()) {
28-
return $this->_redirect('backup/*');
68+
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
69+
$resultRedirect = $this->resultRedirectFactory->create();
70+
$resultRedirect->setPath('backup/*');
71+
return $resultRedirect;
2972
}
3073

3174
$fileName = $this->_objectManager->get('Magento\Backup\Helper\Data')->generateBackupDownloadName($backup);
3275

33-
$response = $this->_fileFactory->create(
76+
$this->_fileFactory->create(
3477
$fileName,
3578
null,
3679
DirectoryList::VAR_DIR,
3780
'application/octet-stream',
3881
$backup->getSize()
3982
);
4083

41-
$response->sendHeaders();
42-
43-
$backup->output();
44-
exit;
84+
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
85+
$resultRaw = $this->resultRawFactory->create();
86+
$resultRaw->setContents($backup->output());
87+
return $resultRaw;
4588
}
4689
}

app/code/Magento/Backup/Model/Backup.php

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ public function close()
381381
/**
382382
* Print output
383383
*
384-
* @return void
384+
* @return string
385385
*/
386386
public function output()
387387
{
@@ -393,7 +393,7 @@ public function output()
393393
$directory = $this->_filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
394394
$directory = $directory->readFile($this->_getFilePath());
395395

396-
echo $directory;
396+
return $directory;
397397
}
398398

399399
/**

app/code/Magento/Customer/Controller/Adminhtml/Index/Viewfile.php

100644100755
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
*/
2121
class Viewfile extends \Magento\Customer\Controller\Adminhtml\Index
2222
{
23+
/**
24+
* @var \Magento\Framework\Controller\Result\RawFactory
25+
*/
26+
protected $resultRawFactory;
27+
2328
/**
2429
* @var \Magento\Framework\Url\DecoderInterface
2530
*/
@@ -52,6 +57,7 @@ class Viewfile extends \Magento\Customer\Controller\Adminhtml\Index
5257
* @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory
5358
* @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
5459
* @param \Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory
60+
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
5561
* @param \Magento\Framework\Url\DecoderInterface $urlDecoder
5662
*
5763
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -83,6 +89,7 @@ public function __construct(
8389
\Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory,
8490
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
8591
\Magento\Framework\Controller\Result\JSONFactory $resultJsonFactory,
92+
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
8693
\Magento\Framework\Url\DecoderInterface $urlDecoder
8794
) {
8895
parent::__construct(
@@ -113,6 +120,7 @@ public function __construct(
113120
$resultForwardFactory,
114121
$resultJsonFactory
115122
);
123+
$this->resultRawFactory = $resultRawFactory;
116124
$this->urlDecoder = $urlDecoder;
117125
}
118126

@@ -174,21 +182,22 @@ public function execute()
174182
$contentLength = $stat['size'];
175183
$contentModify = $stat['mtime'];
176184

177-
$this->getResponse()
178-
->setHttpResponseCode(200)
185+
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
186+
$resultRaw = $this->resultRawFactory->create();
187+
$resultRaw->setHttpResponseCode(200)
179188
->setHeader('Pragma', 'public', true)
180189
->setHeader('Content-type', $contentType, true)
181190
->setHeader('Content-Length', $contentLength)
182-
->setHeader('Last-Modified', date('r', $contentModify))
183-
->clearBody();
184-
$this->getResponse()->sendHeaders();
185-
186-
echo $directory->readFile($fileName);
191+
->setHeader('Last-Modified', date('r', $contentModify));
192+
$resultRaw->setContents($directory->readFile($fileName));
193+
return $resultRaw;
187194
} else {
188195
$name = pathinfo($path, PATHINFO_BASENAME);
189-
$this->_fileFactory->create($name, ['type' => 'filename', 'value' => $fileName], DirectoryList::MEDIA)
190-
->sendResponse();
196+
$this->_fileFactory->create(
197+
$name,
198+
['type' => 'filename', 'value' => $fileName],
199+
DirectoryList::MEDIA
200+
);
191201
}
192-
exit;
193202
}
194203
}

0 commit comments

Comments
 (0)