Skip to content

Commit 26c1f7b

Browse files
MAGETWO-82710: Fix issue #10032 - Download back-up .tgz always takes the latest that's created (2.2-develop) #11595
2 parents 90c86a5 + 00e9b6a commit 26c1f7b

File tree

2 files changed

+31
-47
lines changed

2 files changed

+31
-47
lines changed

app/code/Magento/Backup/Model/BackupFactory.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,20 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan
3939
*/
4040
public function create($timestamp, $type)
4141
{
42-
$backupId = $timestamp . '_' . $type;
4342
$fsCollection = $this->_objectManager->get(\Magento\Backup\Model\Fs\Collection::class);
4443
$backupInstance = $this->_objectManager->get(\Magento\Backup\Model\Backup::class);
44+
4545
foreach ($fsCollection as $backup) {
46-
if ($backup->getId() == $backupId) {
47-
$backupInstance->setType(
48-
$backup->getType()
49-
)->setTime(
50-
$backup->getTime()
51-
)->setName(
52-
$backup->getName()
53-
)->setPath(
54-
$backup->getPath()
55-
);
46+
if ($backup->getTime() === (int) $timestamp && $backup->getType() === $type) {
47+
$backupInstance->setData(['id' => $backup->getId()])
48+
->setType($backup->getType())
49+
->setTime($backup->getTime())
50+
->setName($backup->getName())
51+
->setPath($backup->getPath());
5652
break;
5753
}
5854
}
55+
5956
return $backupInstance;
6057
}
6158
}

app/code/Magento/Backup/Test/Unit/Model/BackupFactoryTest.php

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -77,42 +77,29 @@ protected function setUp()
7777

7878
public function testCreate()
7979
{
80-
$this->_backupModel->expects(
81-
$this->once()
82-
)->method(
83-
'setType'
84-
)->with(
85-
$this->_data['type']
86-
)->will(
87-
$this->returnSelf()
88-
);
89-
$this->_backupModel->expects(
90-
$this->once()
91-
)->method(
92-
'setTime'
93-
)->with(
94-
$this->_data['time']
95-
)->will(
96-
$this->returnSelf()
97-
);
98-
$this->_backupModel->expects(
99-
$this->once()
100-
)->method(
101-
'setName'
102-
)->with(
103-
$this->_data['name']
104-
)->will(
105-
$this->returnSelf()
106-
);
107-
$this->_backupModel->expects(
108-
$this->once()
109-
)->method(
110-
'setPath'
111-
)->with(
112-
$this->_data['path']
113-
)->will(
114-
$this->returnSelf()
115-
);
80+
$this->_backupModel->expects($this->once())
81+
->method('setType')
82+
->with($this->_data['type'])
83+
->will($this->returnSelf());
84+
85+
$this->_backupModel->expects($this->once())
86+
->method('setTime')
87+
->with($this->_data['time'])
88+
->will($this->returnSelf());
89+
90+
$this->_backupModel->expects($this->once())
91+
->method('setName')
92+
->with($this->_data['name'])
93+
->will($this->returnSelf());
94+
95+
$this->_backupModel->expects($this->once())
96+
->method('setPath')
97+
->with($this->_data['path'])
98+
->will($this->returnSelf());
99+
100+
$this->_backupModel->expects($this->once())
101+
->method('setData')
102+
->will($this->returnSelf());
116103

117104
$this->_instance->create('1385661590', 'snapshot');
118105
}

0 commit comments

Comments
 (0)