From c630e4a7b7ba8cf2c638f50f2ec39304b6ee70f9 Mon Sep 17 00:00:00 2001 From: Pieter Cappelle Date: Fri, 20 Oct 2017 21:58:43 +0200 Subject: [PATCH] Fix issue 10032 --- .../Magento/Backup/Model/BackupFactory.php | 19 +++--- .../Test/Unit/Model/BackupFactoryTest.php | 59 ++++++++----------- 2 files changed, 31 insertions(+), 47 deletions(-) diff --git a/app/code/Magento/Backup/Model/BackupFactory.php b/app/code/Magento/Backup/Model/BackupFactory.php index c4e2be9758f72..28b0a7baf43cb 100644 --- a/app/code/Magento/Backup/Model/BackupFactory.php +++ b/app/code/Magento/Backup/Model/BackupFactory.php @@ -39,23 +39,20 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan */ public function create($timestamp, $type) { - $backupId = $timestamp . '_' . $type; $fsCollection = $this->_objectManager->get(\Magento\Backup\Model\Fs\Collection::class); $backupInstance = $this->_objectManager->get(\Magento\Backup\Model\Backup::class); + foreach ($fsCollection as $backup) { - if ($backup->getId() == $backupId) { - $backupInstance->setType( - $backup->getType() - )->setTime( - $backup->getTime() - )->setName( - $backup->getName() - )->setPath( - $backup->getPath() - ); + if ($backup->getTime() === (int) $timestamp && $backup->getType() === $type) { + $backupInstance->setData(['id' => $backup->getId()]) + ->setType($backup->getType()) + ->setTime($backup->getTime()) + ->setName($backup->getName()) + ->setPath($backup->getPath()); break; } } + return $backupInstance; } } diff --git a/app/code/Magento/Backup/Test/Unit/Model/BackupFactoryTest.php b/app/code/Magento/Backup/Test/Unit/Model/BackupFactoryTest.php index dca65db48650f..629028bfd6f15 100644 --- a/app/code/Magento/Backup/Test/Unit/Model/BackupFactoryTest.php +++ b/app/code/Magento/Backup/Test/Unit/Model/BackupFactoryTest.php @@ -77,42 +77,29 @@ protected function setUp() public function testCreate() { - $this->_backupModel->expects( - $this->once() - )->method( - 'setType' - )->with( - $this->_data['type'] - )->will( - $this->returnSelf() - ); - $this->_backupModel->expects( - $this->once() - )->method( - 'setTime' - )->with( - $this->_data['time'] - )->will( - $this->returnSelf() - ); - $this->_backupModel->expects( - $this->once() - )->method( - 'setName' - )->with( - $this->_data['name'] - )->will( - $this->returnSelf() - ); - $this->_backupModel->expects( - $this->once() - )->method( - 'setPath' - )->with( - $this->_data['path'] - )->will( - $this->returnSelf() - ); + $this->_backupModel->expects($this->once()) + ->method('setType') + ->with($this->_data['type']) + ->will($this->returnSelf()); + + $this->_backupModel->expects($this->once()) + ->method('setTime') + ->with($this->_data['time']) + ->will($this->returnSelf()); + + $this->_backupModel->expects($this->once()) + ->method('setName') + ->with($this->_data['name']) + ->will($this->returnSelf()); + + $this->_backupModel->expects($this->once()) + ->method('setPath') + ->with($this->_data['path']) + ->will($this->returnSelf()); + + $this->_backupModel->expects($this->once()) + ->method('setData') + ->will($this->returnSelf()); $this->_instance->create('1385661590', 'snapshot'); }