Skip to content

Commit 2d9c1e6

Browse files
author
Alexander Akimov
authored
Merge pull request #3241 from magento-tsg/2.1.16-develop-pr57
[TSG] Backporting for 2.1 (pr57) (2.1.16)
2 parents 4064ada + b0a9ae0 commit 2d9c1e6

File tree

21 files changed

+488
-34
lines changed

21 files changed

+488
-34
lines changed

app/code/Magento/Backend/Block/System/Store/Delete/Form.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,39 @@
55
*/
66
namespace Magento\Backend\Block\System\Store\Delete;
77

8+
use Magento\Backup\Helper\Data as BackupHelper;
9+
use Magento\Framework\App\ObjectManager;
10+
811
/**
912
* Adminhtml cms block edit form
1013
*
1114
* @author Magento Core Team <core@magentocommerce.com>
1215
*/
1316
class Form extends \Magento\Backend\Block\Widget\Form\Generic
1417
{
18+
/**
19+
* @var BackupHelper
20+
*/
21+
private $backup;
22+
23+
/**
24+
* @param \Magento\Backend\Block\Template\Context $context
25+
* @param \Magento\Framework\Registry $registry
26+
* @param \Magento\Framework\Data\FormFactory $formFactory
27+
* @param array $data
28+
* @param BackupHelper|null $backup
29+
*/
30+
public function __construct(
31+
\Magento\Backend\Block\Template\Context $context,
32+
\Magento\Framework\Registry $registry,
33+
\Magento\Framework\Data\FormFactory $formFactory,
34+
array $data = [],
35+
BackupHelper $backup = null
36+
) {
37+
parent::__construct($context, $registry, $formFactory, $data);
38+
$this->backup = $backup ?: ObjectManager::getInstance()->get(BackupHelper::class);
39+
}
40+
1541
/**
1642
* Init form
1743
*
@@ -25,7 +51,7 @@ protected function _construct()
2551
}
2652

2753
/**
28-
* {@inheritdoc}
54+
* @inheritDoc
2955
*/
3056
protected function _prepareForm()
3157
{
@@ -45,15 +71,21 @@ protected function _prepareForm()
4571

4672
$fieldset->addField('item_id', 'hidden', ['name' => 'item_id', 'value' => $dataObject->getId()]);
4773

74+
$backupOptions = ['0' => __('No')];
75+
$backupSelected = '0';
76+
if ($this->backup->isEnabled()) {
77+
$backupOptions['1'] = __('Yes');
78+
$backupSelected = '1';
79+
}
4880
$fieldset->addField(
4981
'create_backup',
5082
'select',
5183
[
5284
'label' => __('Create DB Backup'),
5385
'title' => __('Create DB Backup'),
5486
'name' => 'create_backup',
55-
'options' => ['1' => __('Yes'), '0' => __('No')],
56-
'value' => '1'
87+
'options' => $backupOptions,
88+
'value' => $backupSelected
5789
]
5890
);
5991

app/code/Magento/Backend/Controller/Adminhtml/System/Store.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* Store controller
1717
*
1818
* @author Magento Core Team <core@magentocommerce.com>
19+
* @SuppressWarnings(PHPMD.AllPurposeAction)
1920
*/
2021
abstract class Store extends Action
2122
{
@@ -88,6 +89,8 @@ protected function createPage()
8889
* Backup database
8990
*
9091
* @return bool
92+
*
93+
* @deprecated Backup module is to be removed.
9194
*/
9295
protected function _backupDatabase()
9396
{

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
*/
66
namespace Magento\Backup\Controller\Adminhtml;
77

8+
use Magento\Backup\Helper\Data as Helper;
9+
use Magento\Framework\App\ObjectManager;
10+
811
/**
912
* Backup admin controller
1013
*
1114
* @author Magento Core Team <core@magentocommerce.com>
15+
* @SuppressWarnings(PHPMD.AllPurposeAction)
1216
*/
1317
abstract class Index extends \Magento\Backend\App\Action
1418
{
@@ -46,27 +50,47 @@ abstract class Index extends \Magento\Backend\App\Action
4650
*/
4751
protected $maintenanceMode;
4852

53+
/**
54+
* @var Helper
55+
*/
56+
private $helper;
57+
4958
/**
5059
* @param \Magento\Backend\App\Action\Context $context
5160
* @param \Magento\Framework\Registry $coreRegistry
5261
* @param \Magento\Framework\Backup\Factory $backupFactory
5362
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
5463
* @param \Magento\Backup\Model\BackupFactory $backupModelFactory
5564
* @param \Magento\Framework\App\MaintenanceMode $maintenanceMode
65+
* @param Helper|null $helper
5666
*/
5767
public function __construct(
5868
\Magento\Backend\App\Action\Context $context,
5969
\Magento\Framework\Registry $coreRegistry,
6070
\Magento\Framework\Backup\Factory $backupFactory,
6171
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
6272
\Magento\Backup\Model\BackupFactory $backupModelFactory,
63-
\Magento\Framework\App\MaintenanceMode $maintenanceMode
73+
\Magento\Framework\App\MaintenanceMode $maintenanceMode,
74+
Helper $helper = null
6475
) {
6576
$this->_coreRegistry = $coreRegistry;
6677
$this->_backupFactory = $backupFactory;
6778
$this->_fileFactory = $fileFactory;
6879
$this->_backupModelFactory = $backupModelFactory;
6980
$this->maintenanceMode = $maintenanceMode;
81+
$this->helper = $helper ?: ObjectManager::getInstance()->get(Helper::class);
7082
parent::__construct($context);
7183
}
84+
85+
/**
86+
* @inheritDoc
87+
*/
88+
public function dispatch(\Magento\Framework\App\RequestInterface $request)
89+
{
90+
if (!$this->helper->isEnabled()) {
91+
return $this->_redirect('*/*/disabled');
92+
}
93+
94+
return parent::dispatch($request);
95+
}
7296
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Backup\Controller\Adminhtml\Index;
10+
11+
use Magento\Backend\App\Action;
12+
use Magento\Backend\App\Action\Context;
13+
use Magento\Framework\View\Result\PageFactory;
14+
15+
/**
16+
* Inform that backup is disabled.
17+
*/
18+
class Disabled extends Action
19+
{
20+
/**
21+
* @see _isAllowed()
22+
*/
23+
const ADMIN_RESOURCE = 'Magento_Backend::backup';
24+
25+
/**
26+
* @var PageFactory
27+
*/
28+
private $pageFactory;
29+
30+
/**
31+
* @param Context $context
32+
* @param PageFactory $pageFactory
33+
*/
34+
public function __construct(Context $context, PageFactory $pageFactory)
35+
{
36+
parent::__construct($context);
37+
$this->pageFactory = $pageFactory;
38+
}
39+
40+
/**
41+
* @inheritDoc
42+
*/
43+
public function execute()
44+
{
45+
return $this->pageFactory->create();
46+
}
47+
}

app/code/Magento/Backup/Cron/SystemBackup.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Magento\Framework\App\Filesystem\DirectoryList;
99
use Magento\Store\Model\ScopeInterface;
1010

11+
/**
12+
* Performs scheduled backup.
13+
*/
1114
class SystemBackup
1215
{
1316
const XML_PATH_BACKUP_ENABLED = 'system/backup/enabled';
@@ -100,6 +103,10 @@ public function __construct(
100103
*/
101104
public function execute()
102105
{
106+
if (!$this->_backupData->isEnabled()) {
107+
return $this;
108+
}
109+
103110
if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_ENABLED, ScopeInterface::SCOPE_STORE)) {
104111
return $this;
105112
}

app/code/Magento/Backup/Helper/Data.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Backup\Helper;
78

89
use Magento\Framework\App\Filesystem\DirectoryList;
@@ -283,4 +284,14 @@ public function extractDataFromFilename($filename)
283284

284285
return $result;
285286
}
287+
288+
/**
289+
* Is backup functionality enabled.
290+
*
291+
* @return bool
292+
*/
293+
public function isEnabled()
294+
{
295+
return $this->scopeConfig->isSetFlag('system/backup/functionality_enabled');
296+
}
286297
}

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
*/
66
namespace Magento\Backup\Model;
77

8+
use Magento\Backup\Helper\Data as Helper;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\Exception\LocalizedException;
11+
812
/**
913
* Database backup model
1014
*
1115
* @author Magento Core Team <core@magentocommerce.com>
16+
* @deprecated Backup module is to be removed.
1217
*/
1318
class Db implements \Magento\Framework\Backup\Db\BackupDbInterface
1419
{
@@ -32,16 +37,24 @@ class Db implements \Magento\Framework\Backup\Db\BackupDbInterface
3237
*/
3338
protected $_resource = null;
3439

40+
/**
41+
* @var Helper
42+
*/
43+
private $helper;
44+
3545
/**
3646
* @param \Magento\Backup\Model\ResourceModel\Db $resourceDb
3747
* @param \Magento\Framework\App\ResourceConnection $resource
48+
* @param Helper|null $helper
3849
*/
3950
public function __construct(
4051
\Magento\Backup\Model\ResourceModel\Db $resourceDb,
41-
\Magento\Framework\App\ResourceConnection $resource
52+
\Magento\Framework\App\ResourceConnection $resource,
53+
Helper $helper = null
4254
) {
4355
$this->_resourceDb = $resourceDb;
4456
$this->_resource = $resource;
57+
$this->helper = $helper ?: ObjectManager::getInstance()->get(Helper::class);
4558
}
4659

4760
/**
@@ -62,6 +75,8 @@ public function getResource()
6275
}
6376

6477
/**
78+
* Tables list.
79+
*
6580
* @return array
6681
*/
6782
public function getTables()
@@ -70,6 +85,8 @@ public function getTables()
7085
}
7186

7287
/**
88+
* Command to recreate given table.
89+
*
7390
* @param string $tableName
7491
* @param bool $addDropIfExists
7592
* @return string
@@ -80,6 +97,8 @@ public function getTableCreateScript($tableName, $addDropIfExists = false)
8097
}
8198

8299
/**
100+
* Generate table's data dump.
101+
*
83102
* @param string $tableName
84103
* @return string
85104
*/
@@ -89,6 +108,8 @@ public function getTableDataDump($tableName)
89108
}
90109

91110
/**
111+
* Header for dumps.
112+
*
92113
* @return string
93114
*/
94115
public function getHeader()
@@ -97,6 +118,8 @@ public function getHeader()
97118
}
98119

99120
/**
121+
* Footer for dumps.
122+
*
100123
* @return string
101124
*/
102125
public function getFooter()
@@ -105,6 +128,8 @@ public function getFooter()
105128
}
106129

107130
/**
131+
* Get backup SQL.
132+
*
108133
* @return string
109134
*/
110135
public function renderSql()
@@ -123,13 +148,15 @@ public function renderSql()
123148
}
124149

125150
/**
126-
* Create backup and stream write to adapter
127-
*
128-
* @param \Magento\Framework\Backup\Db\BackupInterface $backup
129-
* @return $this
151+
* @inheritDoc
152+
* @throws LocalizedException
130153
*/
131154
public function createBackup(\Magento\Framework\Backup\Db\BackupInterface $backup)
132155
{
156+
if (!$this->helper->isEnabled()) {
157+
throw new LocalizedException(__('Backup functionality is disabled'));
158+
}
159+
133160
$backup->open(true);
134161

135162
$this->getResource()->beginTransaction();
@@ -177,8 +204,6 @@ public function createBackup(\Magento\Framework\Backup\Db\BackupInterface $backu
177204
$this->getResource()->commitTransaction();
178205

179206
$backup->close();
180-
181-
return $this;
182207
}
183208

184209
/**

0 commit comments

Comments
 (0)