Skip to content

12064: Database Rollback not working with magento 2.1.9? #12108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/internal/Magento/Framework/Setup/BackupRollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ public function dbRollback($rollbackFile)
$dbRollback->setTime($time[0]);
$this->log->log('DB rollback is starting...');
$dbRollback->setResourceModel($this->objectManager->create(\Magento\Backup\Model\ResourceModel\Db::class));
if ($dbRollback->getBackupFilename() !== $rollbackFile) {
$correctName = $this->getCorrectFileNameWithoutPrefix($dbRollback, $rollbackFile);
$dbRollback->setName($correctName);
}
$dbRollback->rollback();
$this->log->log('DB rollback filename: ' . $dbRollback->getBackupFilename());
$this->log->log('DB rollback path: ' . $dbRollback->getBackupPath());
Expand Down Expand Up @@ -329,4 +333,25 @@ public function getDBDiskSpace()
$dbBackup = $this->objectManager->create(\Magento\Framework\Backup\Db::class);
return $dbBackup->getDBSize();
}

/**
* Get correct file name without prefix.
*
* @param \Magento\Framework\Backup\Db $dbRollback
* @param string $rollbackFile
*
* @return string
*/
private function getCorrectFileNameWithoutPrefix(\Magento\Framework\Backup\Db $dbRollback, $rollbackFile)
{
$namePrefix = $dbRollback->getTime() . '_' . $dbRollback->getType();
//delete prefix.
$fileNameWithoutPrefix = str_replace($namePrefix, '', $rollbackFile);
//change '_' to ' '.
$fileNameWithoutPrefix = str_replace('_', ' ', $fileNameWithoutPrefix);
//delete file extension.
$fileNameWithoutPrefix = pathinfo($fileNameWithoutPrefix, PATHINFO_FILENAME);

return $fileNameWithoutPrefix;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public function testMediaRollback()
public function testDbBackup()
{
$this->setupDbBackupRollback();
$this->database->expects($this->once())->method('getBackupFilename')->willReturn('RollbackFile_A.gz');
$this->database->expects($this->once())->method('create');
$this->file->expects($this->once())->method('isExists')->willReturn(false);
$this->file->expects($this->once())->method('createDirectory');
Expand All @@ -190,12 +191,20 @@ public function testDbBackup()
public function testDbRollback()
{
$this->setupDbBackupRollback();

$this->database->expects($this->once())->method('rollback');
$this->database->expects($this->exactly(2))->method('getBackupFilename')
->willReturnOnConsecutiveCalls('test', '1510140748_db_test_backup');
$this->database->expects($this->once())->method('getTime')->willReturn(1510140748);
$this->database->expects($this->once())->method('getType')->willReturn('db');
$this->database->expects($this->once())->method('setName')->with(' test backup');

$this->file->expects($this->once())
->method('isExists')
->with($this->path . '/backups/12345_db.sql')
->with($this->path . '/backups/1510140748_db_test_backup.sql')
->willReturn(true);
$this->model->dbRollback('12345_db.sql');

$this->model->dbRollback('1510140748_db_test_backup.sql');
}

private function setupCodeBackupRollback()
Expand Down Expand Up @@ -226,9 +235,6 @@ private function setupDbBackupRollback()
->method('setBackupExtension');
$this->database->expects($this->once())
->method('setTime');
$this->database->expects($this->once())
->method('getBackupFilename')
->willReturn('RollbackFile_A.gz');
$this->database->expects($this->atLeastOnce())
->method('getBackupPath')
->willReturn('pathToFile/12345_db.sql');
Expand Down