|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Karma\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
9
|
|
|
use Karma\Application; |
|
10
|
|
|
use Karma\Command; |
|
11
|
|
|
|
|
12
|
|
|
class Rollback extends Command |
|
13
|
|
|
{ |
|
14
|
|
|
private |
|
15
|
|
|
$dryRun; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct(Application $app) |
|
18
|
|
|
{ |
|
19
|
|
|
parent::__construct($app); |
|
20
|
|
|
|
|
21
|
|
|
$this->dryRun = false; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
protected function configure() |
|
25
|
|
|
{ |
|
26
|
|
|
parent::configure(); |
|
27
|
|
|
|
|
28
|
|
|
$this |
|
29
|
|
|
->setName('rollback') |
|
30
|
|
|
->setDescription('Restore files from backup ones') |
|
31
|
|
|
|
|
32
|
|
|
->addArgument('sourcePath', InputArgument::REQUIRED, 'source path to hydrate') |
|
33
|
|
|
|
|
34
|
|
|
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Simulation mode') |
|
35
|
|
|
; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
39
|
|
|
{ |
|
40
|
|
|
parent::execute($input, $output); |
|
41
|
|
|
|
|
42
|
|
|
$this->processInputs($input); |
|
43
|
|
|
$this->launchRollback(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
private function processInputs(InputInterface $input) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->output->writeln(sprintf( |
|
49
|
|
|
'<info>Rollback <comment>%s</comment></info>', |
|
50
|
|
|
$input->getArgument('sourcePath') |
|
51
|
|
|
)); |
|
52
|
|
|
|
|
53
|
|
|
$this->app['sources.path'] = $input->getArgument('sourcePath'); |
|
54
|
|
|
|
|
55
|
|
|
if($input->getOption('dry-run')) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->output->writeln("<fg=cyan>Run in dry-run mode</fg=cyan>"); |
|
58
|
|
|
$this->dryRun = true; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$this->output->writeln(''); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
private function launchRollback() |
|
65
|
|
|
{ |
|
66
|
|
|
$hydrator = $this->app['hydrator']; |
|
67
|
|
|
|
|
68
|
|
|
if($this->dryRun === true) |
|
69
|
|
|
{ |
|
70
|
|
|
$hydrator->setDryRun(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$hydrator->rollback(); |
|
74
|
|
|
} |
|
75
|
|
|
} |