Skip to content

Commit 5d4fdb1

Browse files
safwkhaneddielau
authored andcommitted
MAGETWO-38150: Data Backup
- Changes based on code review feedback. - Changed info:backups:list to show sorted list based on type.
1 parent 02a273f commit 5d4fdb1

File tree

8 files changed

+70
-28
lines changed

8 files changed

+70
-28
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public function codeBackup($time, $type = Factory::TYPE_FILESYSTEM)
9292
if ($type === Factory::TYPE_FILESYSTEM) {
9393
$fsBackup->addIgnorePaths($this->getCodeBackupIgnorePaths());
9494
$granularType = 'Code';
95+
$fsBackup->setName('code');
9596
} elseif ($type === Factory::TYPE_MEDIA) {
9697
$fsBackup->addIgnorePaths($this->getMediaBackupIgnorePaths());
9798
$granularType = 'Media';
@@ -295,7 +296,6 @@ private function getMediaBackupIgnorePaths()
295296
private function checkRollbackFileValidity($time, $type)
296297
{
297298
$invalidFileNameMsg = 'Invalid rollback file.';
298-
$count = count($time);
299299
if (!in_array(count($time), [2, 3])) {
300300
throw new LocalizedException(new Phrase($invalidFileNameMsg));
301301
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testCreate()
2020
'',
2121
false
2222
);
23-
$objectManager->expects($this->any())
23+
$objectManager->expects($this->exactly(2))
2424
->method('create')
2525
->will($this->returnValueMap([
2626
['Magento\Framework\Setup\ConsoleLogger', ['output' => $output], $consoleLogger],

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ public function testCodeBackup()
105105
$this->model->codeBackup(time());
106106
}
107107

108+
/**
109+
* @expectedException \Magento\Framework\Exception\LocalizedException
110+
* @expectedExceptionMessage This backup type \'txt\' is not supported.
111+
*/
112+
public function testCodeBackupWithInvalidType()
113+
{
114+
$this->model->codeBackup(time(), 'txt');
115+
}
116+
108117
public function testCodeRollback()
109118
{
110119
$this->filesystem->expects($this->once())->method('rollback');
@@ -116,6 +125,42 @@ public function testCodeRollback()
116125
$this->model->codeRollback('RollbackFile_A.tgz');
117126
}
118127

128+
/**
129+
* @expectedException \Magento\Framework\Exception\LocalizedException
130+
* @expectedExceptionMessage The rollback file does not exist.
131+
*/
132+
public function testCodeRollbackWithInvalidFilePath()
133+
{
134+
$this->file->expects($this->once())
135+
->method('isExists')
136+
->willReturn(false);
137+
$this->model->codeRollback('RollbackFile_A.tgz');
138+
}
139+
140+
/**
141+
* @expectedException \Magento\Framework\Exception\LocalizedException
142+
* @expectedExceptionMessage Invalid rollback file.
143+
*/
144+
public function testCodeRollbackWithInvalidFileType()
145+
{
146+
$this->file->expects($this->once())
147+
->method('isExists')
148+
->willReturn(true);
149+
$this->model->codeRollback('RollbackFile_A.txt');
150+
}
151+
152+
/**
153+
* @expectedException \Magento\Framework\Exception\LocalizedException
154+
* @expectedExceptionMessage Invalid rollback file.
155+
*/
156+
public function testCodeRollbackWithInvalidFileFormat()
157+
{
158+
$this->file->expects($this->once())
159+
->method('isExists')
160+
->willReturn(true);
161+
$this->model->codeRollback('RollbackFile.gz');
162+
}
163+
119164
public function testMediaBackup()
120165
{
121166
$this->setupCodeBackupRollback();

setup/src/Magento/Setup/Console/Command/BackupCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class BackupCommand extends AbstractSetupCommand
2525
/**
2626
* Name of input options
2727
*/
28-
2928
const INPUT_KEY_CODE = 'code';
3029
const INPUT_KEY_MEDIA = 'media';
3130
const INPUT_KEY_DB = 'db';
@@ -38,11 +37,15 @@ class BackupCommand extends AbstractSetupCommand
3837
private $objectManager;
3938

4039
/**
40+
* Handler for maintenance mode
41+
*
4142
* @var MaintenanceMode
4243
*/
4344
private $maintenanceMode;
4445

4546
/**
47+
* Factory for BackupRollback
48+
*
4649
* @var BackupRollbackFactory
4750
*/
4851
private $backupRollbackFactory;

setup/src/Magento/Setup/Console/Command/InfoBackupsListCommand.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
6565
$backupsDir = $this->directoryList->getPath(DirectoryList::VAR_DIR)
6666
. '/' . BackupRollback::DEFAULT_BACKUP_DIRECTORY;
6767
if ($this->file->isExists($backupsDir)) {
68-
$output->writeln(
69-
'<info>Showing backup files in ' . $backupsDir
70-
. ' (first part of the filename is the time it was taken) ...</info>'
71-
);
7268
$contents = $this->file->readDirectoryRecursively($backupsDir);
73-
if (empty($contents)) {
74-
$output->writeln('<info>No backup files found.</info>');
75-
return;
76-
}
77-
$table = $this->getHelperSet()->get('table');
78-
$table->setHeaders(['Backup Filename', 'Backup Type']);
69+
$tempTable = [];
7970
foreach ($contents as $path) {
8071
$partsOfPath = explode('/', str_replace('\\', '/', $path));
8172
$fileName = $partsOfPath[count($partsOfPath) - 1];
@@ -86,14 +77,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
8677
// and filename contains the type of backup separated by '_'
8778
$fileNameParts = explode('_', $filenameWithoutExtension[0]);
8879
if (in_array(Factory::TYPE_MEDIA, $fileNameParts)) {
89-
$table->addRow([$fileName, Factory::TYPE_MEDIA]);
80+
$tempTable[$fileName] = Factory::TYPE_MEDIA;
9081
} elseif (in_array(Factory::TYPE_DB, $fileNameParts)) {
91-
$table->addRow([$fileName, Factory::TYPE_DB]);
92-
} elseif (in_array(Factory::TYPE_FILESYSTEM, $fileNameParts)) {
93-
$table->addRow([$fileName, Factory::TYPE_FILESYSTEM]);
82+
$tempTable[$fileName] = Factory::TYPE_DB;
83+
} elseif (in_array('code', $fileNameParts)) {
84+
$tempTable[$fileName] = 'code';
9485
}
9586
}
9687
}
88+
if (empty($tempTable)) {
89+
$output->writeln('<info>No backup files found.</info>');
90+
return;
91+
}
92+
$output->writeln("<info>Showing backup files in $backupsDir.</info>");
93+
/** @var \Symfony\Component\Console\Helper\Table $table */
94+
$table = $this->getHelperSet()->get('table');
95+
$table->setHeaders(['Backup Filename', 'Backup Type']);
96+
asort($tempTable);
97+
foreach ($tempTable as $key => $value) {
98+
$table->addRow([$key, $value]);
99+
}
97100
$table->render($output);
98101
} else {
99102
$output->writeln('<info>No backup files found.</info>');

setup/src/Magento/Setup/Console/Command/ModuleUninstallCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
238238

239239
$helper = $this->getHelper('question');
240240
$question = new ConfirmationQuestion(
241-
'You are about to remove code and database tables. Are you sure?[y/N]',
241+
'You are about to remove code and/or database tables. Are you sure?[y/N]',
242242
false
243243
);
244244
if (!$helper->ask($input, $output, $question) && $input->isInteractive()) {

setup/src/Magento/Setup/Test/Unit/Console/Command/BackupCommandTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ public function setUp()
6060
$this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
6161
$this->objectManager->expects($this->any())
6262
->method('get')
63-
->will($this->returnValueMap([
64-
['Magento\Framework\Setup\BackupRollbackFactory', $this->backupRollbackFactory],
65-
]));
63+
->will($this->returnValue($this->backupRollbackFactory));
6664
$command = new BackupCommand(
6765
$objectManagerProvider,
6866
$maintenanceMode,

setup/src/Magento/Setup/Test/Unit/Console/Command/InfoBackupsListCommandTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ public function testExecute()
2323
* |\PHPUnit_Framework_MockObject_MockObject $directoryList
2424
*/
2525
$directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
26-
$path = realpath(__DIR__);
27-
$directoryList->expects($this->any())
28-
->method('getRoot')
29-
->willReturn($path);
30-
$directoryList->expects($this->any())
31-
->method('getPath')
32-
->willReturn($path);
3326
/** @var \Magento\Framework\Filesystem\Driver\File|\PHPUnit_Framework_MockObject_MockObject $file */
3427
$file = $this->getMock('Magento\Framework\Filesystem\Driver\File', [], [], '', false);
3528
$file->expects($this->once())->method('isExists')->will($this->returnValue(true));

0 commit comments

Comments
 (0)