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

Public Member Functions

 __construct (BackupFactory $backupFactory)
 
 rollback ()
 
 create ()
 
 getDBSize ()
 
 getType ()
 
- Public Member Functions inherited from AbstractBackup
 setBackupExtension ($backupExtension)
 
 getBackupExtension ()
 
 setResourceModel ($resourceModel)
 
 getResourceModel ()
 
 setTime ($time)
 
 getTime ()
 
 setRootDir ($rootDir)
 
 getRootDir ()
 
 setBackupsDir ($backupsDir)
 
 getBackupsDir ()
 
 getBackupPath ()
 
 getBackupFilename ()
 
 getIsSuccess ()
 
 getErrorMessage ()
 
 setErrorMessage ($errorMessage)
 
 setName ($name, $applyFilter=true)
 
 getName ()
 
 getDisplayName ()
 
 keepSourceFile ()
 
 setKeepSourceFile (bool $keepSourceFile)
 

Protected Member Functions

 _isLineLastInCommand ($line)
 
- Protected Member Functions inherited from AbstractBackup
 _filterName ($name)
 

Protected Attributes

 $_backupFactory
 
- Protected Attributes inherited from AbstractBackup
 $_name
 
 $_time
 
 $_backupExtension
 
 $_resourceModel
 
 $_rootDir
 
 $_backupsDir
 
 $_lastOperationSucceed = false
 
 $_lastErrorMessage
 

Detailed Description

Class to work with database backups

Author
Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m @api
Since
100.0.2

Definition at line 19 of file Db.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( BackupFactory  $backupFactory)
Parameters
BackupFactory$backupFactory

Definition at line 29 of file Db.php.

30  {
31  $this->_backupFactory = $backupFactory;
32  }

Member Function Documentation

◆ _isLineLastInCommand()

_isLineLastInCommand (   $line)
protected

Checks whether the line is last in sql command

Parameters
string$line
Returns
bool

Definition at line 68 of file Db.php.

69  {
70  $cleanLine = trim($line);
71  $lineLength = strlen($cleanLine);
72 
73  $returnResult = false;
74  if ($lineLength > 0) {
75  $lastSymbolIndex = $lineLength - 1;
76  if ($cleanLine[$lastSymbolIndex] == ';') {
77  $returnResult = true;
78  }
79  }
80 
81  return $returnResult;
82  }

◆ create()

create ( )

Implements Create Backup functionality for Db

Returns
bool

Implements BackupInterface.

Definition at line 89 of file Db.php.

90  {
91  set_time_limit(0);
92  ignore_user_abort(true);
93 
94  $this->_lastOperationSucceed = false;
95 
96  $backup = $this->_backupFactory->createBackupModel()->setTime(
97  $this->getTime()
98  )->setType(
99  $this->getType()
100  )->setPath(
101  $this->getBackupsDir()
102  )->setName(
103  $this->getName()
104  );
105 
106  $backupDb = $this->_backupFactory->createBackupDbModel();
107  $backupDb->createBackup($backup);
108 
109  $this->_lastOperationSucceed = true;
110 
111  return true;
112  }

◆ getDBSize()

getDBSize ( )

Get database size

Returns
int

Definition at line 119 of file Db.php.

120  {
121  $backupDb = $this->_backupFactory->createBackupDbModel();
122  return $backupDb->getDBBackupSize();
123  }

◆ getType()

getType ( )

Get Backup Type

Returns
string

Implements BackupInterface.

Definition at line 130 of file Db.php.

131  {
132  return 'db';
133  }

◆ rollback()

rollback ( )

Implements Rollback functionality for Db

Returns
bool

Implements BackupInterface.

Definition at line 39 of file Db.php.

40  {
41  set_time_limit(0);
42  ignore_user_abort(true);
43 
44  $this->_lastOperationSucceed = false;
45 
46  $archiveManager = new Archive();
47  $source = $archiveManager->unpack($this->getBackupPath(), $this->getBackupsDir());
48 
49  $file = new File($source);
50  foreach ($file as $statement) {
51  $this->getResourceModel()->runCommand($statement);
52  }
53  if ($this->keepSourceFile() === false) {
54  @unlink($source);
55  }
56 
57  $this->_lastOperationSucceed = true;
58 
59  return true;
60  }
$source
Definition: source.php:23

Field Documentation

◆ $_backupFactory

$_backupFactory
protected

Definition at line 24 of file Db.php.


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