Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Db.php
Go to the documentation of this file.
1 <?php
7 
11 
19 class Db extends AbstractBackup
20 {
24  protected $_backupFactory;
25 
29  public function __construct(BackupFactory $backupFactory)
30  {
31  $this->_backupFactory = $backupFactory;
32  }
33 
39  public function rollback()
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  }
61 
68  protected function _isLineLastInCommand($line)
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  }
83 
89  public function create()
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  }
113 
119  public function getDBSize()
120  {
121  $backupDb = $this->_backupFactory->createBackupDbModel();
122  return $backupDb->getDBBackupSize();
123  }
124 
130  public function getType()
131  {
132  return 'db';
133  }
134 }
$source
Definition: source.php:23
__construct(BackupFactory $backupFactory)
Definition: Db.php:29
_isLineLastInCommand($line)
Definition: Db.php:68