diff --git a/lib/internal/Magento/Framework/Setup/BackupRollback.php b/lib/internal/Magento/Framework/Setup/BackupRollback.php index c19b78101db16..a374611271039 100644 --- a/lib/internal/Magento/Framework/Setup/BackupRollback.php +++ b/lib/internal/Magento/Framework/Setup/BackupRollback.php @@ -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()); @@ -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; + } } diff --git a/lib/internal/Magento/Framework/Setup/Test/Unit/BackupRollbackTest.php b/lib/internal/Magento/Framework/Setup/Test/Unit/BackupRollbackTest.php index 1f9b776abab0a..5105b0dffdebf 100644 --- a/lib/internal/Magento/Framework/Setup/Test/Unit/BackupRollbackTest.php +++ b/lib/internal/Magento/Framework/Setup/Test/Unit/BackupRollbackTest.php @@ -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'); @@ -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() @@ -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');