1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Victor Dubiniuk <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc. |
6
|
|
|
* @license AGPL-3.0 |
7
|
|
|
* |
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
10
|
|
|
* as published by the Free Software Foundation. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Owncloud\Updater\Command; |
23
|
|
|
|
24
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
25
|
|
|
use Symfony\Component\Console\Input\InputOption; |
26
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class CheckpointCommand |
30
|
|
|
* |
31
|
|
|
* @package Owncloud\Updater\Command |
32
|
|
|
*/ |
33
|
|
|
class CheckpointCommand extends Command { |
34
|
|
|
|
35
|
|
|
protected function configure(){ |
36
|
|
|
$this |
37
|
|
|
->setName('upgrade:checkpoint') |
38
|
|
|
->setDescription('Create or restore ownCloud core files') |
39
|
|
|
->addOption( |
40
|
|
|
'create', null, InputOption::VALUE_NONE, 'create a checkpoint' |
41
|
|
|
) |
42
|
|
|
->addOption( |
43
|
|
|
'restore', null, InputOption::VALUE_REQUIRED, 'revert files to a given checkpoint' |
44
|
|
|
) |
45
|
|
|
->addOption( |
46
|
|
|
'list', null, InputOption::VALUE_OPTIONAL, 'show all checkpoints' |
47
|
|
|
) |
48
|
|
|
->addOption( |
49
|
|
|
'remove', null, InputOption::VALUE_REQUIRED, 'remove a checkpoint' |
50
|
|
|
) |
51
|
|
|
; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param InputInterface $input |
56
|
|
|
* @param OutputInterface $output |
57
|
|
|
* @throws \Exception |
58
|
|
|
*/ |
59
|
|
|
protected function execute(InputInterface $input, OutputInterface $output){ |
60
|
|
|
clearstatcache(); |
61
|
|
|
$checkpoint = $this->container['utils.checkpoint']; |
62
|
|
|
if ($input->getOption('create')){ |
63
|
|
|
try { |
64
|
|
|
$checkpointId = $checkpoint->create(); |
65
|
|
|
$output->writeln('Created checkpoint ' . $checkpointId); |
66
|
|
|
} catch (\Exception $e){ |
67
|
|
|
$output->writeln('Error while creating a checkpoint'); |
68
|
|
|
throw $e; |
69
|
|
|
} |
70
|
|
|
} elseif ($input->getOption('remove')){ |
71
|
|
|
$checkpointId = stripslashes($input->getOption('remove')); |
72
|
|
|
try { |
73
|
|
|
$checkpoint->remove($checkpointId); |
74
|
|
|
$output->writeln('Removed checkpoint ' . $checkpointId); |
75
|
|
|
} catch (\UnexpectedValueException $e){ |
76
|
|
|
$output->writeln($e->getMessage()); |
77
|
|
|
} catch (\Exception $e){ |
78
|
|
|
$output->writeln('Error while removing a checkpoint ' . $checkpointId); |
79
|
|
|
} |
80
|
|
|
} elseif ($input->getOption('restore')) { |
81
|
|
|
$checkpointId = stripslashes($input->getOption('restore')); |
82
|
|
|
try { |
83
|
|
|
$checkpoint->restore($checkpointId); |
84
|
|
|
$checkpoint->remove($checkpointId); |
85
|
|
|
$output->writeln('Restored checkpoint ' . $checkpointId); |
86
|
|
|
} catch (\UnexpectedValueException $e){ |
87
|
|
|
$output->writeln($e->getMessage()); |
88
|
|
|
} catch (\Exception $e){ |
89
|
|
|
$output->writeln('Error while restoring a checkpoint ' . $checkpointId); |
90
|
|
|
} |
91
|
|
|
} else { |
92
|
|
|
$checkpoints = $checkpoint->getAll(); |
93
|
|
|
if (count($checkpoints)){ |
94
|
|
|
foreach ($checkpoints as $checkpoint){ |
95
|
|
|
$output->writeln(sprintf('%s - %s', $checkpoint['title'], $checkpoint['date'])); |
96
|
|
|
} |
97
|
|
|
} else { |
98
|
|
|
$output->writeln('No checkpoints found'); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|