Skip to content

Commit 5c240ba

Browse files
author
ybohaienko
committed
Merge branch '2.3.0-qwerty' into MAGETWO-91785
2 parents 086a437 + ae3221e commit 5c240ba

File tree

423 files changed

+9182
-3844
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

423 files changed

+9182
-3844
lines changed

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,35 @@
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+
* @inheritDoc
25+
*/
26+
public function __construct(
27+
\Magento\Backend\Block\Template\Context $context,
28+
\Magento\Framework\Registry $registry,
29+
\Magento\Framework\Data\FormFactory $formFactory,
30+
array $data = [],
31+
?BackupHelper $backup = null
32+
) {
33+
parent::__construct($context, $registry, $formFactory, $data);
34+
$this->backup = $backup ?? ObjectManager::getInstance()->get(BackupHelper::class);
35+
}
36+
1537
/**
1638
* Init form
1739
*
@@ -25,7 +47,7 @@ protected function _construct()
2547
}
2648

2749
/**
28-
* {@inheritdoc}
50+
* @inheritDoc
2951
*/
3052
protected function _prepareForm()
3153
{
@@ -45,15 +67,21 @@ protected function _prepareForm()
4567

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

70+
$backupOptions = ['0' => __('No')];
71+
$backupSelected = '0';
72+
if ($this->backup->isEnabled()) {
73+
$backupOptions['1'] = __('Yes');
74+
$backupSelected = '1';
75+
}
4876
$fieldset->addField(
4977
'create_backup',
5078
'select',
5179
[
5280
'label' => __('Create DB Backup'),
5381
'title' => __('Create DB Backup'),
5482
'name' => 'create_backup',
55-
'options' => ['1' => __('Yes'), '0' => __('No')],
56-
'value' => '1'
83+
'options' => $backupOptions,
84+
'value' => $backupSelected
5785
]
5886
);
5987

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Store controller
1515
*
1616
* @author Magento Core Team <core@magentocommerce.com>
17+
* @SuppressWarnings(PHPMD.AllPurposeAction)
1718
*/
1819
abstract class Store extends Action
1920
{
@@ -86,6 +87,8 @@ protected function createPage()
8687
* Backup database
8788
*
8889
* @return bool
90+
*
91+
* @deprecated Backup module is to be removed.
8992
*/
9093
protected function _backupDatabase()
9194
{

app/code/Magento/Backend/view/adminhtml/web/js/validate-store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ define([
6767
* 'Confirm' action handler.
6868
*/
6969
confirm: function () {
70+
$('body').trigger('processStart');
7071
dataPost().postData(requestData);
7172
}
7273
}

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
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>
1215
* @api
1316
* @since 100.0.2
17+
* @SuppressWarnings(PHPMD.AllPurposeAction)
1418
*/
1519
abstract class Index extends \Magento\Backend\App\Action
1620
{
@@ -48,27 +52,47 @@ abstract class Index extends \Magento\Backend\App\Action
4852
*/
4953
protected $maintenanceMode;
5054

55+
/**
56+
* @var Helper
57+
*/
58+
private $helper;
59+
5160
/**
5261
* @param \Magento\Backend\App\Action\Context $context
5362
* @param \Magento\Framework\Registry $coreRegistry
5463
* @param \Magento\Framework\Backup\Factory $backupFactory
5564
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
5665
* @param \Magento\Backup\Model\BackupFactory $backupModelFactory
5766
* @param \Magento\Framework\App\MaintenanceMode $maintenanceMode
67+
* @param Helper|null $helper
5868
*/
5969
public function __construct(
6070
\Magento\Backend\App\Action\Context $context,
6171
\Magento\Framework\Registry $coreRegistry,
6272
\Magento\Framework\Backup\Factory $backupFactory,
6373
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
6474
\Magento\Backup\Model\BackupFactory $backupModelFactory,
65-
\Magento\Framework\App\MaintenanceMode $maintenanceMode
75+
\Magento\Framework\App\MaintenanceMode $maintenanceMode,
76+
?Helper $helper = null
6677
) {
6778
$this->_coreRegistry = $coreRegistry;
6879
$this->_backupFactory = $backupFactory;
6980
$this->_fileFactory = $fileFactory;
7081
$this->_backupModelFactory = $backupModelFactory;
7182
$this->maintenanceMode = $maintenanceMode;
83+
$this->helper = $helper ?? ObjectManager::getInstance()->get(Helper::class);
7284
parent::__construct($context);
7385
}
86+
87+
/**
88+
* @inheritDoc
89+
*/
90+
public function dispatch(\Magento\Framework\App\RequestInterface $request)
91+
{
92+
if (!$this->helper->isEnabled()) {
93+
return $this->_redirect('*/*/disabled');
94+
}
95+
96+
return parent::dispatch($request);
97+
}
7498
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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\App\Action\HttpGetActionInterface;
14+
use Magento\Framework\View\Result\PageFactory;
15+
16+
/**
17+
* Inform that backup is disabled.
18+
*/
19+
class Disabled extends Action implements HttpGetActionInterface
20+
{
21+
/**
22+
* @see _isAllowed()
23+
*/
24+
const ADMIN_RESOURCE = 'Magento_Backend::backup';
25+
26+
/**
27+
* @var PageFactory
28+
*/
29+
private $pageFactory;
30+
31+
/**
32+
* @param Context $context
33+
* @param PageFactory $pageFactory
34+
*/
35+
public function __construct(Context $context, PageFactory $pageFactory)
36+
{
37+
parent::__construct($context);
38+
$this->pageFactory = $pageFactory;
39+
}
40+
41+
/**
42+
* @inheritDoc
43+
*/
44+
public function execute()
45+
{
46+
return $this->pageFactory->create();
47+
}
48+
}

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';
@@ -101,6 +104,10 @@ public function __construct(
101104
*/
102105
public function execute()
103106
{
107+
if (!$this->_backupData->isEnabled()) {
108+
return $this;
109+
}
110+
104111
if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_ENABLED, ScopeInterface::SCOPE_STORE)) {
105112
return $this;
106113
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Backup\Helper;
710

811
use Magento\Framework\App\Filesystem\DirectoryList;
@@ -285,4 +288,14 @@ public function extractDataFromFilename($filename)
285288

286289
return $result;
287290
}
291+
292+
/**
293+
* Is backup functionality enabled.
294+
*
295+
* @return bool
296+
*/
297+
public function isEnabled(): bool
298+
{
299+
return $this->scopeConfig->isSetFlag('system/backup/functionality_enabled');
300+
}
288301
}

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

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
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\RuntimeException;
11+
812
/**
913
* Database backup model
1014
*
1115
* @api
1216
* @since 100.0.2
17+
* @deprecated Backup module is to be removed.
1318
*/
1419
class Db implements \Magento\Framework\Backup\Db\BackupDbInterface
1520
{
@@ -33,16 +38,24 @@ class Db implements \Magento\Framework\Backup\Db\BackupDbInterface
3338
*/
3439
protected $_resource = null;
3540

41+
/**
42+
* @var Helper
43+
*/
44+
private $helper;
45+
3646
/**
3747
* @param \Magento\Backup\Model\ResourceModel\Db $resourceDb
3848
* @param \Magento\Framework\App\ResourceConnection $resource
49+
* @param Helper|null $helper
3950
*/
4051
public function __construct(
4152
\Magento\Backup\Model\ResourceModel\Db $resourceDb,
42-
\Magento\Framework\App\ResourceConnection $resource
53+
\Magento\Framework\App\ResourceConnection $resource,
54+
?Helper $helper = null
4355
) {
4456
$this->_resourceDb = $resourceDb;
4557
$this->_resource = $resource;
58+
$this->helper = $helper ?? ObjectManager::getInstance()->get(Helper::class);
4659
}
4760

4861
/**
@@ -63,6 +76,8 @@ public function getResource()
6376
}
6477

6578
/**
79+
* Tables list.
80+
*
6681
* @return array
6782
*/
6883
public function getTables()
@@ -71,6 +86,8 @@ public function getTables()
7186
}
7287

7388
/**
89+
* Command to recreate given table.
90+
*
7491
* @param string $tableName
7592
* @param bool $addDropIfExists
7693
* @return string
@@ -81,6 +98,8 @@ public function getTableCreateScript($tableName, $addDropIfExists = false)
8198
}
8299

83100
/**
101+
* Generate table's data dump.
102+
*
84103
* @param string $tableName
85104
* @return string
86105
*/
@@ -90,6 +109,8 @@ public function getTableDataDump($tableName)
90109
}
91110

92111
/**
112+
* Header for dumps.
113+
*
93114
* @return string
94115
*/
95116
public function getHeader()
@@ -98,6 +119,8 @@ public function getHeader()
98119
}
99120

100121
/**
122+
* Footer for dumps.
123+
*
101124
* @return string
102125
*/
103126
public function getFooter()
@@ -106,6 +129,8 @@ public function getFooter()
106129
}
107130

108131
/**
132+
* Get backup SQL.
133+
*
109134
* @return string
110135
*/
111136
public function renderSql()
@@ -124,13 +149,14 @@ public function renderSql()
124149
}
125150

126151
/**
127-
* Create backup and stream write to adapter
128-
*
129-
* @param \Magento\Framework\Backup\Db\BackupInterface $backup
130-
* @return $this
152+
* @inheritDoc
131153
*/
132154
public function createBackup(\Magento\Framework\Backup\Db\BackupInterface $backup)
133155
{
156+
if (!$this->helper->isEnabled()) {
157+
throw new RuntimeException(__('Backup functionality is disabled'));
158+
}
159+
134160
$backup->open(true);
135161

136162
$this->getResource()->beginTransaction();
@@ -179,8 +205,6 @@ public function createBackup(\Magento\Framework\Backup\Db\BackupInterface $backu
179205
$this->getResource()->commitTransaction();
180206

181207
$backup->close();
182-
183-
return $this;
184208
}
185209

186210
/**

0 commit comments

Comments
 (0)