Skip to content

Commit 02a273f

Browse files
safwkhaneddielau
authored andcommitted
MAGETWO-38151: Data Rollback
- Validation on rollback filename and few message changes.
1 parent 908e46d commit 02a273f

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public function codeRollback($rollbackFile, $type = Factory::TYPE_FILESYSTEM)
158158
$fsRollback->setBackupsDir($backupsDir);
159159
$fsRollback->setBackupExtension('tgz');
160160
$time = explode('_', $rollbackFile);
161+
$this->checkRollbackFileValidity($time, 'tgz');
161162
$fsRollback->setTime($time[0]);
162163
$this->log->log($granularType . ' rollback is starting ...');
163164
$fsRollback->rollback();
@@ -215,6 +216,7 @@ public function dbRollback($rollbackFile)
215216
$dbRollback->setBackupsDir($backupsDir);
216217
$dbRollback->setBackupExtension('gz');
217218
$time = explode('_', $rollbackFile);
219+
$this->checkRollbackFileValidity($time, 'gz');
218220
if (count($time) === 3) {
219221
$thirdPart = explode('.', $time[2]);
220222
$dbRollback->setName($thirdPart[0]);
@@ -281,4 +283,25 @@ private function getMediaBackupIgnorePaths()
281283
}
282284
return $ignorePaths;
283285
}
286+
287+
/**
288+
* Check if the provided backup file for rollback is valid
289+
*
290+
* @param array $time
291+
* @param string $type
292+
* @return void
293+
* @throws LocalizedException
294+
*/
295+
private function checkRollbackFileValidity($time, $type)
296+
{
297+
$invalidFileNameMsg = 'Invalid rollback file.';
298+
$count = count($time);
299+
if (!in_array(count($time), [2, 3])) {
300+
throw new LocalizedException(new Phrase($invalidFileNameMsg));
301+
}
302+
$extension = explode('.', $time[count($time) - 1]);
303+
if ($extension[count($extension) - 1] !== $type) {
304+
throw new LocalizedException(new Phrase($invalidFileNameMsg));
305+
}
306+
}
284307
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ public function testDbRollback()
152152
$this->database->expects($this->once())->method('rollback');
153153
$this->file->expects($this->once())
154154
->method('isExists')
155-
->with($this->path . '/backups/RollbackFile_A.tgz')
155+
->with($this->path . '/backups/RollbackFile_A.gz')
156156
->willReturn(true);
157-
$this->model->dbRollback('RollbackFile_A.tgz');
157+
$this->model->dbRollback('RollbackFile_A.gz');
158158
}
159159

160160
private function setupCodeBackupRollback()
@@ -187,10 +187,10 @@ private function setupDbBackupRollback()
187187
->method('setTime');
188188
$this->database->expects($this->once())
189189
->method('getBackupFilename')
190-
->willReturn('RollbackFile_A.tgz');
190+
->willReturn('RollbackFile_A.gz');
191191
$this->database->expects($this->once())
192192
->method('getBackupPath')
193-
->willReturn('pathToFile/RollbackFile_A.tgz');
193+
->willReturn('pathToFile/RollbackFile_A.gz');
194194
$this->log->expects($this->once())
195195
->method('logSuccess');
196196
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
119119
$this->maintenanceMode->set(true);
120120
$helper = $this->getHelper('question');
121121
$question = new ConfirmationQuestion(
122-
'<info>You are about to remove current code and database tables. Are you sure?[y/N]<info>',
122+
'<info>You are about to remove current code and/or database tables. Are you sure?[y/N]<info>',
123123
false
124124
);
125125
if (!$helper->ask($input, $output, $question) && $input->isInteractive()) {
126126
return;
127127
}
128128
$this->doRollback($input, $output);
129+
$output->writeln('<info>Please set file permission of bin/magento to executable</info>');
129130

130131
} catch (\Exception $e) {
131132
$output->writeln('<error>' . $e->getMessage() . '</error>');

0 commit comments

Comments
 (0)