Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
SystemBackup Class Reference

Public Member Functions

 __construct (\Magento\Backup\Helper\Data $backupData, \Magento\Framework\Registry $coreRegistry, \Psr\Log\LoggerInterface $logger, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Backup\Factory $backupFactory, \Magento\Framework\App\MaintenanceMode $maintenanceMode)
 
 execute ()
 

Data Fields

const XML_PATH_BACKUP_ENABLED = 'system/backup/enabled'
 
const XML_PATH_BACKUP_TYPE = 'system/backup/type'
 
const XML_PATH_BACKUP_MAINTENANCE_MODE = 'system/backup/maintenance'
 

Protected Attributes

 $_errors = []
 
 $_backupData = null
 
 $_coreRegistry = null
 
 $_logger
 
 $_scopeConfig
 
 $_filesystem
 
 $_backupFactory
 
 $maintenanceMode
 

Detailed Description

Performs scheduled backup.

Definition at line 14 of file SystemBackup.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Backup\Helper\Data  $backupData,
\Magento\Framework\Registry  $coreRegistry,
\Psr\Log\LoggerInterface  $logger,
\Magento\Framework\App\Config\ScopeConfigInterface  $scopeConfig,
\Magento\Framework\Filesystem  $filesystem,
\Magento\Framework\Backup\Factory  $backupFactory,
\Magento\Framework\App\MaintenanceMode  $maintenanceMode 
)
Parameters
\Magento\Backup\Helper\Data$backupData
\Magento\Framework\Registry$coreRegistry
\Psr\Log\LoggerInterface$logger
\Magento\Framework\App\Config\ScopeConfigInterface$scopeConfig
\Magento\Framework\Filesystem$filesystem
\Magento\Framework\Backup\Factory$backupFactory
\Magento\Framework\App\MaintenanceMode$maintenanceMode

Definition at line 81 of file SystemBackup.php.

89  {
90  $this->_backupData = $backupData;
91  $this->_coreRegistry = $coreRegistry;
92  $this->_logger = $logger;
93  $this->_scopeConfig = $scopeConfig;
94  $this->_filesystem = $filesystem;
95  $this->_backupFactory = $backupFactory;
96  $this->maintenanceMode = $maintenanceMode;
97  }
$logger
$filesystem

Member Function Documentation

◆ execute()

execute ( )

Create Backup

Returns
$this
Exceptions

Definition at line 105 of file SystemBackup.php.

106  {
107  if (!$this->_backupData->isEnabled()) {
108  return $this;
109  }
110 
111  if (!$this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_ENABLED, ScopeInterface::SCOPE_STORE)) {
112  return $this;
113  }
114 
115  if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) {
116  $this->maintenanceMode->set(true);
117  }
118 
119  $type = $this->_scopeConfig->getValue(self::XML_PATH_BACKUP_TYPE, ScopeInterface::SCOPE_STORE);
120 
121  $this->_errors = [];
122  try {
123  $backupManager = $this->_backupFactory->create(
124  $type
125  )->setBackupExtension(
126  $this->_backupData->getExtensionByType($type)
127  )->setTime(
128  time()
129  )->setBackupsDir(
130  $this->_backupData->getBackupsDir()
131  );
132 
133  $this->_coreRegistry->register('backup_manager', $backupManager);
134 
135  if ($type != \Magento\Framework\Backup\Factory::TYPE_DB) {
136  $backupManager->setRootDir(
137  $this->_filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath()
138  )->addIgnorePaths(
139  $this->_backupData->getBackupIgnorePaths()
140  );
141  }
142 
143  $backupManager->create();
144  $message = $this->_backupData->getCreateSuccessMessageByType($type);
145  $this->_logger->info($message);
146  } catch (\Exception $e) {
147  $this->_errors[] = $e->getMessage();
148  $this->_errors[] = $e->getTrace();
149  throw $e;
150  }
151 
152  if ($this->_scopeConfig->isSetFlag(self::XML_PATH_BACKUP_MAINTENANCE_MODE, ScopeInterface::SCOPE_STORE)) {
153  $this->maintenanceMode->set(false);
154  }
155 
156  return $this;
157  }
$message
$type
Definition: item.phtml:13

Field Documentation

◆ $_backupData

$_backupData = null
protected

Definition at line 34 of file SystemBackup.php.

◆ $_backupFactory

$_backupFactory
protected

Definition at line 65 of file SystemBackup.php.

◆ $_coreRegistry

$_coreRegistry = null
protected

Definition at line 41 of file SystemBackup.php.

◆ $_errors

$_errors = []
protected

Definition at line 27 of file SystemBackup.php.

◆ $_filesystem

$_filesystem
protected

Definition at line 60 of file SystemBackup.php.

◆ $_logger

$_logger
protected

Definition at line 46 of file SystemBackup.php.

◆ $_scopeConfig

$_scopeConfig
protected

Definition at line 53 of file SystemBackup.php.

◆ $maintenanceMode

$maintenanceMode
protected

Definition at line 70 of file SystemBackup.php.

◆ XML_PATH_BACKUP_ENABLED

const XML_PATH_BACKUP_ENABLED = 'system/backup/enabled'

Definition at line 16 of file SystemBackup.php.

◆ XML_PATH_BACKUP_MAINTENANCE_MODE

const XML_PATH_BACKUP_MAINTENANCE_MODE = 'system/backup/maintenance'

Definition at line 20 of file SystemBackup.php.

◆ XML_PATH_BACKUP_TYPE

const XML_PATH_BACKUP_TYPE = 'system/backup/type'

Definition at line 18 of file SystemBackup.php.


The documentation for this class was generated from the following file: