Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 22c6937

Browse files
Merge forwardport of magento/magento2#12108 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/12108.patch (created by @RomaKis) based on commit(s): 1. 66677ae 2. 74980f2 Fixed GitHub Issues in 2.3-develop branch: - magento/magento2#12064: Database Rollback not working with magento 2.1.9? (reported by @whereowareadmin)
2 parents 1dcb55d + 63958cd commit 22c6937

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

lib/internal/Magento/Framework/Setup/BackupRollback.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Magento\Framework\App\Filesystem\DirectoryList;
1010
use Magento\Framework\Backup\Exception\NotEnoughPermissions;
1111
use Magento\Framework\Backup\Factory;
12-
use Magento\Framework\Backup\Filesystem;
1312
use Magento\Framework\Backup\Filesystem\Helper;
1413
use Magento\Framework\Exception\LocalizedException;
1514
use Magento\Framework\Filesystem\Driver\File;
@@ -245,6 +244,10 @@ public function dbRollback($rollbackFile, $keepSourceFile = false)
245244
$this->log->log('DB rollback is starting...');
246245
$dbRollback->setKeepSourceFile($keepSourceFile);
247246
$dbRollback->setResourceModel($this->objectManager->create(\Magento\Backup\Model\ResourceModel\Db::class));
247+
if ($dbRollback->getBackupFilename() !== $rollbackFile) {
248+
$correctName = $this->getCorrectFileNameWithoutPrefix($dbRollback, $rollbackFile);
249+
$dbRollback->setName($correctName);
250+
}
248251
$dbRollback->rollback();
249252
$this->log->log('DB rollback filename: ' . $dbRollback->getBackupFilename());
250253
$this->log->log('DB rollback path: ' . $dbRollback->getBackupPath());
@@ -332,4 +335,25 @@ public function getDBDiskSpace()
332335
$dbBackup = $this->objectManager->create(\Magento\Framework\Backup\Db::class);
333336
return $dbBackup->getDBSize();
334337
}
338+
339+
/**
340+
* Get correct file name without prefix.
341+
*
342+
* @param \Magento\Framework\Backup\Db $dbRollback
343+
* @param string $rollbackFile
344+
*
345+
* @return string
346+
*/
347+
private function getCorrectFileNameWithoutPrefix(\Magento\Framework\Backup\Db $dbRollback, $rollbackFile)
348+
{
349+
$namePrefix = $dbRollback->getTime() . '_' . $dbRollback->getType();
350+
//delete prefix.
351+
$fileNameWithoutPrefix = str_replace($namePrefix, '', $rollbackFile);
352+
//change '_' to ' '.
353+
$fileNameWithoutPrefix = str_replace('_', ' ', $fileNameWithoutPrefix);
354+
//delete file extension.
355+
$fileNameWithoutPrefix = pathinfo($fileNameWithoutPrefix, PATHINFO_FILENAME);
356+
357+
return $fileNameWithoutPrefix;
358+
}
335359
}

lib/internal/Magento/Framework/Setup/Test/Unit/BackupRollbackTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public function testMediaRollback()
181181
public function testDbBackup()
182182
{
183183
$this->setupDbBackupRollback();
184+
$this->database->expects($this->once())->method('getBackupFilename')->willReturn('RollbackFile_A.gz');
184185
$this->database->expects($this->once())->method('create');
185186
$this->file->expects($this->once())->method('isExists')->willReturn(false);
186187
$this->file->expects($this->once())->method('createDirectory');
@@ -190,12 +191,20 @@ public function testDbBackup()
190191
public function testDbRollback()
191192
{
192193
$this->setupDbBackupRollback();
194+
193195
$this->database->expects($this->once())->method('rollback');
196+
$this->database->expects($this->exactly(2))->method('getBackupFilename')
197+
->willReturnOnConsecutiveCalls('test', '1510140748_db_test_backup');
198+
$this->database->expects($this->once())->method('getTime')->willReturn(1510140748);
199+
$this->database->expects($this->once())->method('getType')->willReturn('db');
200+
$this->database->expects($this->once())->method('setName')->with(' test backup');
201+
194202
$this->file->expects($this->once())
195203
->method('isExists')
196-
->with($this->path . '/backups/12345_db.sql')
204+
->with($this->path . '/backups/1510140748_db_test_backup.sql')
197205
->willReturn(true);
198-
$this->model->dbRollback('12345_db.sql');
206+
207+
$this->model->dbRollback('1510140748_db_test_backup.sql');
199208
}
200209

201210
private function setupCodeBackupRollback()
@@ -226,9 +235,6 @@ private function setupDbBackupRollback()
226235
->method('setBackupExtension');
227236
$this->database->expects($this->once())
228237
->method('setTime');
229-
$this->database->expects($this->once())
230-
->method('getBackupFilename')
231-
->willReturn('RollbackFile_A.gz');
232238
$this->database->expects($this->atLeastOnce())
233239
->method('getBackupPath')
234240
->willReturn('pathToFile/12345_db.sql');

0 commit comments

Comments
 (0)