Skip to content

Commit

Permalink
Merge pull request #3294 from magento-qwerty/2.3-bugfixes-081018
Browse files Browse the repository at this point in the history
Fixed issues:
- MAGETWO-92170: Redundant File Names for Quote Attachments
- MAGETWO-90725: Wrong session messages behavior
- MAGETWO-94173: Disable backups by default
  • Loading branch information
dvoskoboinikov authored Oct 12, 2018
2 parents 91e6e33 + af91268 commit b93bcf8
Show file tree
Hide file tree
Showing 26 changed files with 349 additions and 390 deletions.
34 changes: 31 additions & 3 deletions app/code/Magento/Backend/Block/System/Store/Delete/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,35 @@
*/
namespace Magento\Backend\Block\System\Store\Delete;

use Magento\Backup\Helper\Data as BackupHelper;
use Magento\Framework\App\ObjectManager;

/**
* Adminhtml cms block edit form
*
* @author Magento Core Team <core@magentocommerce.com>
*/
class Form extends \Magento\Backend\Block\Widget\Form\Generic
{
/**
* @var BackupHelper
*/
private $backup;

/**
* @inheritDoc
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
array $data = [],
?BackupHelper $backup = null
) {
parent::__construct($context, $registry, $formFactory, $data);
$this->backup = $backup ?? ObjectManager::getInstance()->get(BackupHelper::class);
}

/**
* Init form
*
Expand All @@ -25,7 +47,7 @@ protected function _construct()
}

/**
* {@inheritdoc}
* @inheritDoc
*/
protected function _prepareForm()
{
Expand All @@ -45,15 +67,21 @@ protected function _prepareForm()

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

$backupOptions = ['0' => __('No')];
$backupSelected = '0';
if ($this->backup->isEnabled()) {
$backupOptions['1'] = __('Yes');
$backupSelected = '1';
}
$fieldset->addField(
'create_backup',
'select',
[
'label' => __('Create DB Backup'),
'title' => __('Create DB Backup'),
'name' => 'create_backup',
'options' => ['1' => __('Yes'), '0' => __('No')],
'value' => '1'
'options' => $backupOptions,
'value' => $backupSelected
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Store controller
*
* @author Magento Core Team <core@magentocommerce.com>
* @SuppressWarnings(PHPMD.AllPurposeAction)
*/
abstract class Store extends Action
{
Expand Down Expand Up @@ -86,6 +87,8 @@ protected function createPage()
* Backup database
*
* @return bool
*
* @deprecated Backup module is to be removed.
*/
protected function _backupDatabase()
{
Expand Down
26 changes: 25 additions & 1 deletion app/code/Magento/Backup/Controller/Adminhtml/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
*/
namespace Magento\Backup\Controller\Adminhtml;

use Magento\Backup\Helper\Data as Helper;
use Magento\Framework\App\ObjectManager;

/**
* Backup admin controller
*
* @author Magento Core Team <core@magentocommerce.com>
* @api
* @since 100.0.2
* @SuppressWarnings(PHPMD.AllPurposeAction)
*/
abstract class Index extends \Magento\Backend\App\Action
{
Expand Down Expand Up @@ -48,27 +52,47 @@ abstract class Index extends \Magento\Backend\App\Action
*/
protected $maintenanceMode;

/**
* @var Helper
*/
private $helper;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\Backup\Factory $backupFactory
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
* @param \Magento\Backup\Model\BackupFactory $backupModelFactory
* @param \Magento\Framework\App\MaintenanceMode $maintenanceMode
* @param Helper|null $helper
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\Backup\Factory $backupFactory,
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
\Magento\Backup\Model\BackupFactory $backupModelFactory,
\Magento\Framework\App\MaintenanceMode $maintenanceMode
\Magento\Framework\App\MaintenanceMode $maintenanceMode,
?Helper $helper = null
) {
$this->_coreRegistry = $coreRegistry;
$this->_backupFactory = $backupFactory;
$this->_fileFactory = $fileFactory;
$this->_backupModelFactory = $backupModelFactory;
$this->maintenanceMode = $maintenanceMode;
$this->helper = $helper ?? ObjectManager::getInstance()->get(Helper::class);
parent::__construct($context);
}

/**
* @inheritDoc
*/
public function dispatch(\Magento\Framework\App\RequestInterface $request)
{
if (!$this->helper->isEnabled()) {
return $this->_redirect('*/*/disabled');
}

return parent::dispatch($request);
}
}
48 changes: 48 additions & 0 deletions app/code/Magento/Backup/Controller/Adminhtml/Index/Disabled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Backup\Controller\Adminhtml\Index;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\View\Result\PageFactory;

/**
* Inform that backup is disabled.
*/
class Disabled extends Action implements HttpGetActionInterface
{
/**
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Backend::backup';

/**
* @var PageFactory
*/
private $pageFactory;

/**
* @param Context $context
* @param PageFactory $pageFactory
*/
public function __construct(Context $context, PageFactory $pageFactory)
{
parent::__construct($context);
$this->pageFactory = $pageFactory;
}

/**
* @inheritDoc
*/
public function execute()
{
return $this->pageFactory->create();
}
}
7 changes: 7 additions & 0 deletions app/code/Magento/Backup/Cron/SystemBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Store\Model\ScopeInterface;

/**
* Performs scheduled backup.
*/
class SystemBackup
{
const XML_PATH_BACKUP_ENABLED = 'system/backup/enabled';
Expand Down Expand Up @@ -101,6 +104,10 @@ public function __construct(
*/
public function execute()
{
if (!$this->_backupData->isEnabled()) {
return $this;
}

if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_ENABLED, ScopeInterface::SCOPE_STORE)) {
return $this;
}
Expand Down
13 changes: 13 additions & 0 deletions app/code/Magento/Backup/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Backup\Helper;

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

return $result;
}

/**
* Is backup functionality enabled.
*
* @return bool
*/
public function isEnabled(): bool
{
return $this->scopeConfig->isSetFlag('system/backup/functionality_enabled');
}
}
38 changes: 31 additions & 7 deletions app/code/Magento/Backup/Model/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
*/
namespace Magento\Backup\Model;

use Magento\Backup\Helper\Data as Helper;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\RuntimeException;

/**
* Database backup model
*
* @api
* @since 100.0.2
* @deprecated Backup module is to be removed.
*/
class Db implements \Magento\Framework\Backup\Db\BackupDbInterface
{
Expand All @@ -33,16 +38,24 @@ class Db implements \Magento\Framework\Backup\Db\BackupDbInterface
*/
protected $_resource = null;

/**
* @var Helper
*/
private $helper;

/**
* @param \Magento\Backup\Model\ResourceModel\Db $resourceDb
* @param \Magento\Framework\App\ResourceConnection $resource
* @param Helper|null $helper
*/
public function __construct(
\Magento\Backup\Model\ResourceModel\Db $resourceDb,
\Magento\Framework\App\ResourceConnection $resource
\Magento\Framework\App\ResourceConnection $resource,
?Helper $helper = null
) {
$this->_resourceDb = $resourceDb;
$this->_resource = $resource;
$this->helper = $helper ?? ObjectManager::getInstance()->get(Helper::class);
}

/**
Expand All @@ -63,6 +76,8 @@ public function getResource()
}

/**
* Tables list.
*
* @return array
*/
public function getTables()
Expand All @@ -71,6 +86,8 @@ public function getTables()
}

/**
* Command to recreate given table.
*
* @param string $tableName
* @param bool $addDropIfExists
* @return string
Expand All @@ -81,6 +98,8 @@ public function getTableCreateScript($tableName, $addDropIfExists = false)
}

/**
* Generate table's data dump.
*
* @param string $tableName
* @return string
*/
Expand All @@ -90,6 +109,8 @@ public function getTableDataDump($tableName)
}

/**
* Header for dumps.
*
* @return string
*/
public function getHeader()
Expand All @@ -98,6 +119,8 @@ public function getHeader()
}

/**
* Footer for dumps.
*
* @return string
*/
public function getFooter()
Expand All @@ -106,6 +129,8 @@ public function getFooter()
}

/**
* Get backup SQL.
*
* @return string
*/
public function renderSql()
Expand All @@ -124,13 +149,14 @@ public function renderSql()
}

/**
* Create backup and stream write to adapter
*
* @param \Magento\Framework\Backup\Db\BackupInterface $backup
* @return $this
* @inheritDoc
*/
public function createBackup(\Magento\Framework\Backup\Db\BackupInterface $backup)
{
if (!$this->helper->isEnabled()) {
throw new RuntimeException(__('Backup functionality is disabled'));
}

$backup->open(true);

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

$backup->close();

return $this;
}

/**
Expand Down
Loading

0 comments on commit b93bcf8

Please sign in to comment.