1 | <?php |
||
14 | class Rollback extends Command |
||
15 | { |
||
16 | private bool |
||
|
|||
17 | $dryRun; |
||
18 | |||
19 | 36 | public function __construct(Application $app) |
|
20 | { |
||
21 | 36 | parent::__construct($app); |
|
22 | |||
23 | 36 | $this->dryRun = false; |
|
24 | 36 | } |
|
25 | |||
26 | 36 | protected function configure(): void |
|
27 | { |
||
28 | 36 | parent::configure(); |
|
29 | |||
30 | $this |
||
31 | 36 | ->setName('rollback') |
|
32 | 36 | ->setDescription('Restore files from backup ones') |
|
33 | |||
34 | 36 | ->addArgument('sourcePath', InputArgument::OPTIONAL, 'source path to hydrate') |
|
35 | |||
36 | 36 | ->addOption('dry-run', null, InputOption::VALUE_NONE, 'Simulation mode') |
|
37 | ; |
||
38 | 36 | } |
|
39 | |||
40 | 4 | protected function execute(InputInterface $input, OutputInterface $output): int |
|
41 | { |
||
42 | 4 | parent::execute($input, $output); |
|
43 | |||
44 | 4 | $this->processInputs($input); |
|
45 | 3 | $this->launchRollback(); |
|
46 | |||
47 | 3 | return 0; |
|
48 | } |
||
49 | |||
50 | 4 | private function processInputs(InputInterface $input): void |
|
51 | { |
||
52 | 4 | $sourcePath = $input->getArgument('sourcePath'); |
|
53 | 4 | if($sourcePath === null) |
|
54 | { |
||
55 | 2 | $profile = $this->app['profile']; |
|
56 | 2 | if($profile->hasSourcePath() !== true) |
|
57 | { |
||
58 | 1 | throw new \RuntimeException('Missing argument sourcePath'); |
|
59 | } |
||
60 | |||
61 | 1 | $sourcePath = $profile->getSourcePath(); |
|
62 | } |
||
63 | |||
64 | 3 | $this->output->writeln(sprintf( |
|
65 | 3 | '<info>Rollback <comment>%s</comment></info>', |
|
66 | $sourcePath |
||
67 | )); |
||
68 | |||
69 | 3 | $this->app['sources.path'] = $sourcePath; |
|
70 | |||
71 | 3 | if($input->getOption('dry-run')) |
|
72 | { |
||
73 | 1 | $this->output->writeln("<fg=cyan>Run in dry-run mode</fg=cyan>"); |
|
74 | 1 | $this->dryRun = true; |
|
75 | } |
||
76 | |||
77 | 3 | $this->output->writeln(''); |
|
78 | 3 | } |
|
79 | |||
80 | 3 | private function launchRollback(): void |
|
81 | { |
||
82 | 3 | $hydrator = $this->app['hydrator']; |
|
83 | |||
84 | 3 | if($this->dryRun === true) |
|
85 | { |
||
86 | 1 | $hydrator->setDryRun(); |
|
87 | } |
||
88 | |||
89 | 3 | $hydrator->rollback(); |
|
90 | 3 | } |
|
92 |