Skip to content

Commit

Permalink
Merge pull request #3253 from magento-tsg/2.2.7-develop-pr45
Browse files Browse the repository at this point in the history
[TSG] Upporting for 2.2 (pr45) (2.2.7-develop)
  • Loading branch information
Alexander Akimov authored Oct 4, 2018
2 parents 52498f2 + 449516b commit 799a90d
Show file tree
Hide file tree
Showing 41 changed files with 580 additions and 435 deletions.
9 changes: 9 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@
Require all denied
</IfVersion>
</Files>
<Files .user.ini>
<IfVersion < 2.4>
order allow,deny
deny from all
</IfVersion>
<IfVersion >= 2.4>
Require all denied
</IfVersion>
</Files>

# For 404s and 403s that aren't handled by the application, show plain 404 response
ErrorDocument 404 /pub/errors/404.php
Expand Down
9 changes: 9 additions & 0 deletions .htaccess.sample
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,15 @@
Require all denied
</IfVersion>
</Files>
<Files .user.ini>
<IfVersion < 2.4>
order allow,deny
deny from all
</IfVersion>
<IfVersion >= 2.4>
Require all denied
</IfVersion>
</Files>

# For 404s and 403s that aren't handled by the application, show plain 404 response
ErrorDocument 404 /pub/errors/404.php
Expand Down
38 changes: 35 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,39 @@
*/
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;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Data\FormFactory $formFactory
* @param array $data
* @param BackupHelper|null $backup
*/
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 +51,7 @@ protected function _construct()
}

/**
* {@inheritdoc}
* @inheritDoc
*/
protected function _prepareForm()
{
Expand All @@ -45,15 +71,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);
}
}
47 changes: 47 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,47 @@
<?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\View\Result\PageFactory;

/**
* Inform that backup is disabled.
*/
class Disabled extends Action
{
/**
* @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');
}
}
Loading

0 comments on commit 799a90d

Please sign in to comment.