Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Backup Class Reference
Inheritance diagram for Backup:
DataObject BackupInterface

Public Member Functions

 __construct (\Magento\Backup\Helper\Data $helper, \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Backend\Model\Auth\Session $authSession, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Framework\Filesystem $filesystem, $data=[])
 
 setTime ($time)
 
 setPath ($path)
 
 setName ($name)
 
 load ($fileName, $filePath)
 
 exists ()
 
 getFileName ()
 
 setType ($value='db')
 
 getType ()
 
 setFile (&$content)
 
getFile ()
 
 deleteFile ()
 
 read ($length)
 
 eof ()
 
 write ($string)
 
 close ()
 
 getSize ()
 
 validateUserPassword ($password)
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from BackupInterface
 open ($write=false)
 

Data Fields

const COMPRESS_RATE = 9
 

Protected Member Functions

 _getStream ()
 
 _getFilePath ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_stream = null
 
 $_filesystem
 
 $_helper
 
 $_localeResolver
 
 $_backendAuthSession
 
 $_encryptor
 
 $varDirectory
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Backup file item model

@method string getPath() @method string getName() @method string getTime() @SuppressWarnings(PHPMD.CouplingBetweenObjects) @api

Since
100.0.2

Definition at line 21 of file Backup.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Backup\Helper\Data  $helper,
\Magento\Framework\Locale\ResolverInterface  $localeResolver,
\Magento\Backend\Model\Auth\Session  $authSession,
\Magento\Framework\Encryption\EncryptorInterface  $encryptor,
\Magento\Framework\Filesystem  $filesystem,
  $data = [] 
)
Parameters
\Magento\Backup\Helper\Data$helper
\Magento\Framework\Locale\ResolverInterface$localeResolver
\Magento\Backend\Model\Auth\Session$authSession
\Magento\Framework\Encryption\EncryptorInterface$encryptor
\Magento\Framework\Filesystem$filesystem
array$data

Definition at line 84 of file Backup.php.

91  {
92  $this->_encryptor = $encryptor;
93  parent::__construct($data);
94 
95  $this->_filesystem = $filesystem;
96  $this->varDirectory = $this->_filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
97  $this->_helper = $helper;
98  $this->_localeResolver = $localeResolver;
99  $this->_backendAuthSession = $authSession;
100  }
$helper
Definition: iframe.phtml:13
$filesystem

Member Function Documentation

◆ _getFilePath()

_getFilePath ( )
protected

Get file path.

Returns
string

Definition at line 434 of file Backup.php.

435  {
436  return $this->varDirectory->getRelativePath($this->getPath() . '/' . $this->getFileName());
437  }

◆ _getStream()

_getStream ( )
protected

Get zlib handler

Returns
\Magento\Framework\Filesystem\File\WriteInterface
Exceptions

Definition at line 320 of file Backup.php.

321  {
322  if ($this->_stream === null) {
323  throw new \Magento\Framework\Exception\InputException(__('The backup file handler was unspecified.'));
324  }
325  return $this->_stream;
326  }
__()
Definition: __.php:13

◆ close()

close ( )

Close open backup file

Returns
$this

Implements BackupInterface.

Definition at line 374 of file Backup.php.

375  {
376  $this->_getStream()->close();
377  $this->_stream = null;
378 
379  return $this;
380  }

◆ deleteFile()

deleteFile ( )

Delete backup file

Returns
$this
Exceptions

Definition at line 263 of file Backup.php.

264  {
265  if (!$this->exists()) {
266  throw new \Magento\Framework\Exception\LocalizedException(__('The backup file does not exist.'));
267  }
268 
269  $this->varDirectory->delete($this->_getFilePath());
270  return $this;
271  }
__()
Definition: __.php:13

◆ eof()

eof ( )

Check end of file.

Returns
bool

Definition at line 344 of file Backup.php.

345  {
346  return $this->_getStream()->eof();
347  }

◆ exists()

exists ( )

Checks backup file exists.

Returns
bool

Definition at line 170 of file Backup.php.

171  {
172  return $this->varDirectory->isFile($this->_getFilePath());
173  }

◆ getFile()

& getFile ( )

Return content of backup file

Returns
string
Exceptions

Definition at line 248 of file Backup.php.

249  {
250  if (!$this->exists()) {
251  throw new \Magento\Framework\Exception\LocalizedException(__('The backup file does not exist.'));
252  }
253 
254  return $this->varDirectory->read($this->_getFilePath());
255  }
__()
Definition: __.php:13

◆ getFileName()

getFileName ( )

Return file name of backup file

Returns
string

Definition at line 180 of file Backup.php.

181  {
182  $filename = $this->getTime() . "_" . $this->getType();
183  $backupName = $this->getName();
184 
185  if (!empty($backupName)) {
186  $filename .= '_' . $backupName;
187  }
188 
189  $filename .= '.' . $this->_helper->getExtensionByType($this->getType());
190 
191  return $filename;
192  }

◆ getSize()

getSize ( )
Returns
int|mixed

Definition at line 403 of file Backup.php.

404  {
405  if ($this->getData('size') !== null) {
406  return $this->getData('size');
407  }
408 
409  if ($this->exists()) {
410  $this->setData('size', $this->varDirectory->stat($this->_getFilePath())['size']);
411  return $this->getData('size');
412  }
413 
414  return 0;
415  }
getData($key='', $index=null)
Definition: DataObject.php:119
setData($key, $value=null)
Definition: DataObject.php:72

◆ getType()

getType ( )

Returns type of backup file

Returns
string

Definition at line 218 of file Backup.php.

219  {
220  return $this->_type;
221  }

◆ load()

load (   $fileName,
  $filePath 
)

Load backup file info

Parameters
string$fileName
string$filePath
Returns
$this

Definition at line 145 of file Backup.php.

146  {
147  $backupData = $this->_helper->extractDataFromFilename($fileName);
148 
149  $this->addData(
150  [
151  'id' => $filePath . '/' . $fileName,
152  'time' => (int)$backupData->getTime(),
153  'path' => $filePath,
154  'extension' => $this->_helper->getExtensionByType($backupData->getType()),
155  'display_name' => $this->_helper->nameToDisplayName($backupData->getName()),
156  'name' => $backupData->getName(),
157  'date_object' => (new \DateTime())->setTimestamp($backupData->getTime()),
158  ]
159  );
160 
161  $this->setType($backupData->getType());
162  return $this;
163  }
$fileName
Definition: translate.phtml:15

◆ read()

read (   $length)

Read backup uncompressed data

Parameters
int$length
Returns
string

Definition at line 334 of file Backup.php.

335  {
336  return $this->_getStream()->read($length);
337  }

◆ setFile()

setFile ( $content)

Set the backup file content

Parameters
string&$content
Returns
$this
Exceptions

Definition at line 230 of file Backup.php.

231  {
232  if (!$this->hasData('time') || !$this->hasData('type') || !$this->hasData('path')) {
233  throw new \Magento\Framework\Exception\LocalizedException(
234  __('Please correct the order of creation for a new backup.')
235  );
236  }
237 
238  $this->varDirectory->writeFile($this->_getFilePath(), $content);
239  return $this;
240  }
__()
Definition: __.php:13

◆ setName()

setName (   $name)

Set backup name

Parameters
string$name
Returns
$this

Implements BackupInterface.

Definition at line 132 of file Backup.php.

133  {
134  $this->setData('name', $name);
135  return $this;
136  }
setData($key, $value=null)
Definition: DataObject.php:72
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setPath()

setPath (   $path)

Set backup path

Parameters
string$path
Returns
$this

Implements BackupInterface.

Definition at line 120 of file Backup.php.

121  {
122  $this->setData('path', $path);
123  return $this;
124  }
setData($key, $value=null)
Definition: DataObject.php:72

◆ setTime()

setTime (   $time)

Set backup time

Parameters
int$time
Returns
$this

Implements BackupInterface.

Definition at line 108 of file Backup.php.

109  {
110  $this->setData('time', $time);
111  return $this;
112  }
setData($key, $value=null)
Definition: DataObject.php:72

◆ setType()

setType (   $value = 'db')

Sets type of file

Parameters
string$value
Returns
$this

Implements BackupInterface.

Definition at line 200 of file Backup.php.

201  {
202  $possibleTypes = $this->_helper->getBackupTypesList();
203  if (!in_array($value, $possibleTypes)) {
204  $value = $this->_helper->getDefaultBackupType();
205  }
206 
207  $this->_type = $value;
208  $this->setData('type', $this->_type);
209 
210  return $this;
211  }
$value
Definition: gender.phtml:16
setData($key, $value=null)
Definition: DataObject.php:72

◆ validateUserPassword()

validateUserPassword (   $password)

Validate user password

Parameters
string$password
Returns
bool

Definition at line 423 of file Backup.php.

424  {
425  $userPasswordHash = $this->_backendAuthSession->getUser()->getPassword();
426  return $this->_encryptor->validateHash($password, $userPasswordHash);
427  }

◆ write()

write (   $string)

Write to backup file

Parameters
string$string
Returns
$this
Exceptions

Implements BackupInterface.

Definition at line 356 of file Backup.php.

357  {
358  try {
359  $this->_getStream()->write($string);
360  } catch (\Magento\Framework\Exception\FileSystemException $e) {
361  throw new \Magento\Framework\Exception\InputException(
362  __('Something went wrong while writing to the backup file "%1".', $this->getFileName())
363  );
364  }
365 
366  return $this;
367  }
__()
Definition: __.php:13

Field Documentation

◆ $_backendAuthSession

$_backendAuthSession
protected

Definition at line 64 of file Backup.php.

◆ $_encryptor

$_encryptor
protected

Definition at line 69 of file Backup.php.

◆ $_filesystem

$_filesystem
protected

Definition at line 45 of file Backup.php.

◆ $_helper

$_helper
protected

Definition at line 50 of file Backup.php.

◆ $_localeResolver

$_localeResolver
protected

Definition at line 57 of file Backup.php.

◆ $_stream

$_stream = null
protected

Definition at line 40 of file Backup.php.

◆ $varDirectory

$varDirectory
protected

Definition at line 74 of file Backup.php.

◆ COMPRESS_RATE

const COMPRESS_RATE = 9

Compress rate

Definition at line 26 of file Backup.php.


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