Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Data Class Reference
Inheritance diagram for Data:
AbstractHelper

Public Member Functions

 __construct (\Magento\Framework\App\Helper\Context $context, Filesystem $filesystem, \Magento\Framework\AuthorizationInterface $authorization, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList)
 
 getBackupTypes ()
 
 getBackupTypesList ()
 
 getDefaultBackupType ()
 
 getBackupsDir ()
 
 getExtensionByType ($type)
 
 getExtensions ()
 
 generateBackupDownloadName (\Magento\Backup\Model\Backup $backup)
 
 isRollbackAllowed ()
 
 getBackupIgnorePaths ()
 
 getRollbackIgnorePaths ()
 
 getCreateSuccessMessageByType ($type)
 
 invalidateCache ()
 
 nameToDisplayName ($name)
 
 extractDataFromFilename ($filename)
 
 isEnabled ()
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Protected Attributes

 $_filesystem
 
 $_authorization
 
 $_cacheTypeList
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Detailed Description

Backup data helper @api

Since
100.0.2

Definition at line 20 of file Data.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Helper\Context  $context,
Filesystem  $filesystem,
\Magento\Framework\AuthorizationInterface  $authorization,
\Magento\Framework\App\Cache\TypeListInterface  $cacheTypeList 
)

Construct

Parameters
\Magento\Framework\App\Helper\Context$context
Filesystem$filesystem
\Magento\Framework\AuthorizationInterface$authorization
\Magento\Framework\App\Cache\TypeListInterface$cacheTypeList

Definition at line 45 of file Data.php.

50  {
51  parent::__construct($context);
52  $this->_authorization = $authorization;
53  $this->_filesystem = $filesystem;
54  $this->_cacheTypeList = $cacheTypeList;
55  }
$filesystem

Member Function Documentation

◆ extractDataFromFilename()

extractDataFromFilename (   $filename)

Extracts information from backup's filename

Parameters
string$filename
Returns
\Magento\Framework\DataObject

Definition at line 262 of file Data.php.

263  {
264  $extensions = $this->getExtensions();
265 
266  $filenameWithoutExtension = $filename;
267 
268  foreach ($extensions as $extension) {
269  $filenameWithoutExtension = preg_replace(
270  '/' . preg_quote($extension, '/') . '$/',
271  '',
272  $filenameWithoutExtension
273  );
274  }
275 
276  $filenameWithoutExtension = substr($filenameWithoutExtension, 0, strrpos($filenameWithoutExtension, "."));
277 
278  list($time, $type) = explode("_", $filenameWithoutExtension);
279 
280  $name = str_replace($time . '_' . $type, '', $filenameWithoutExtension);
281 
282  if (!empty($name)) {
283  $name = substr($name, 1);
284  }
285 
286  $result = new \Magento\Framework\DataObject();
287  $result->addData(['name' => $name, 'type' => $type, 'time' => $time]);
288 
289  return $result;
290  }
$type
Definition: item.phtml:13
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ generateBackupDownloadName()

generateBackupDownloadName ( \Magento\Backup\Model\Backup  $backup)

Generate backup download name

Parameters
\Magento\Backup\Model\Backup$backup
Returns
string

Definition at line 140 of file Data.php.

141  {
142  $additionalExtension = $backup->getType() == \Magento\Framework\Backup\Factory::TYPE_DB ? '.sql' : '';
143  return $backup->getTime() .
144  '_' .
145  $backup->getType() .
146  '_' .
147  $backup->getName() .
148  $additionalExtension .
149  '.' .
150  $this->getExtensionByType(
151  $backup->getType()
152  );
153  }

◆ getBackupIgnorePaths()

getBackupIgnorePaths ( )

Get paths that should be ignored when creating system snapshots

Returns
string[]

Definition at line 170 of file Data.php.

171  {
172  return [
173  '.git',
174  '.svn',
175  $this->_filesystem->getDirectoryRead(MaintenanceMode::FLAG_DIR)
176  ->getAbsolutePath(MaintenanceMode::FLAG_FILENAME),
177  $this->_filesystem->getDirectoryRead(DirectoryList::SESSION)->getAbsolutePath(),
178  $this->_filesystem->getDirectoryRead(DirectoryList::CACHE)->getAbsolutePath(),
179  $this->_filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath(),
180  $this->_filesystem->getDirectoryRead(DirectoryList::VAR_DIR)->getAbsolutePath('full_page_cache'),
181  $this->_filesystem->getDirectoryRead(DirectoryList::VAR_DIR)->getAbsolutePath('locks'),
182  $this->_filesystem->getDirectoryRead(DirectoryList::VAR_DIR)->getAbsolutePath('report'),
183  ];
184  }

◆ getBackupsDir()

getBackupsDir ( )

Get directory path where backups stored

Returns
string

Definition at line 102 of file Data.php.

103  {
104  return $this->_filesystem->getDirectoryWrite(DirectoryList::VAR_DIR)->getAbsolutePath('backups');
105  }

◆ getBackupTypes()

getBackupTypes ( )

Get all possible backup type values with descriptive title

Returns
array

Definition at line 62 of file Data.php.

◆ getBackupTypesList()

getBackupTypesList ( )

◆ getCreateSuccessMessageByType()

getCreateSuccessMessageByType (   $type)

Get backup create success message by backup type

Parameters
string$type
Returns
void|string

Definition at line 213 of file Data.php.

214  {
215  $messagesMap = [
216  \Magento\Framework\Backup\Factory::TYPE_SYSTEM_SNAPSHOT => __('You created the system backup.'),
218  'You created the system backup (excluding media).'
219  ),
220  \Magento\Framework\Backup\Factory::TYPE_MEDIA => __('You created the database and media backup.'),
221  \Magento\Framework\Backup\Factory::TYPE_DB => __('You created the database backup.'),
222  ];
223 
224  if (!isset($messagesMap[$type])) {
225  return;
226  }
227 
228  return $messagesMap[$type];
229  }
__()
Definition: __.php:13
$type
Definition: item.phtml:13

◆ getDefaultBackupType()

getDefaultBackupType ( )

Get default backup type value

Returns
string

Definition at line 92 of file Data.php.

93  {
94  return \Magento\Framework\Backup\Factory::TYPE_DB;
95  }

◆ getExtensionByType()

getExtensionByType (   $type)

Get backup file extension by backup type

Parameters
string$type
Returns
string

Definition at line 113 of file Data.php.

114  {
115  $extensions = $this->getExtensions();
116  return $extensions[$type] ?? '';
117  }
$type
Definition: item.phtml:13

◆ getExtensions()

getExtensions ( )

Get all types to extensions map

Returns
array

Definition at line 124 of file Data.php.

◆ getRollbackIgnorePaths()

getRollbackIgnorePaths ( )

Get paths that should be ignored when rolling back system snapshots

Returns
string[]

Definition at line 191 of file Data.php.

192  {
193  return [
194  '.svn',
195  '.git',
196  $this->_filesystem->getDirectoryRead(MaintenanceMode::FLAG_DIR)
197  ->getAbsolutePath(MaintenanceMode::FLAG_FILENAME),
198  $this->_filesystem->getDirectoryRead(DirectoryList::SESSION)->getAbsolutePath(),
199  $this->_filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath(),
200  $this->_filesystem->getDirectoryRead(DirectoryList::VAR_DIR)->getAbsolutePath('locks'),
201  $this->_filesystem->getDirectoryRead(DirectoryList::VAR_DIR)->getAbsolutePath('report'),
202  $this->_filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath('errors'),
203  $this->_filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath('index.php'),
204  ];
205  }

◆ invalidateCache()

invalidateCache ( )

Invalidate Cache

Returns
$this

Definition at line 236 of file Data.php.

237  {
238  if ($cacheTypes = $this->_cacheConfig->getTypes()) {
239  $cacheTypesList = array_keys($cacheTypes);
240  $this->_cacheTypeList->invalidate($cacheTypesList);
241  }
242  return $this;
243  }

◆ isEnabled()

isEnabled ( )

Is backup functionality enabled.

Returns
bool

Definition at line 297 of file Data.php.

297  : bool
298  {
299  return $this->scopeConfig->isSetFlag('system/backup/functionality_enabled');
300  }

◆ isRollbackAllowed()

isRollbackAllowed ( )

Check Permission for Rollback

Returns
bool

Definition at line 160 of file Data.php.

161  {
162  return $this->_authorization->isAllowed('Magento_Backup::rollback');
163  }

◆ nameToDisplayName()

nameToDisplayName (   $name)

Creates backup's display name from it's name

Parameters
string$name
Returns
string

Definition at line 251 of file Data.php.

252  {
253  return str_replace('_', ' ', $name);
254  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

Field Documentation

◆ $_authorization

$_authorization
protected

Definition at line 30 of file Data.php.

◆ $_cacheTypeList

$_cacheTypeList
protected

Definition at line 35 of file Data.php.

◆ $_filesystem

$_filesystem
protected

Definition at line 25 of file Data.php.


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