Completed
Push — master ( 9ac21c...67ad92 )
by Victor
9s
created

CheckpointCommand::execute()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 20
ccs 0
cts 20
cp 0
rs 8.8571
cc 5
eloc 16
nc 5
nop 2
crap 30
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\InputArgument;
25
use Symfony\Component\Console\Input\InputInterface;
26
use Symfony\Component\Console\Input\InputOption;
27
use Symfony\Component\Console\Output\OutputInterface;
28
29
class CheckpointCommand extends Command {
30
31
	protected function configure(){
32
		$this
33
				->setName('upgrade:checkpoint')
34
				->setDescription('Create or restore owncloud core files')
35
				->addOption(
36
						'create', null, InputOption::VALUE_NONE, 'create a checkpoint'
37
				)
38
				->addOption(
39
						'restore', null, InputOption::VALUE_REQUIRED, 'revert files to a given checkpoint'
40
				)
41
				->addOption(
42
						'list', null, InputOption::VALUE_OPTIONAL, 'show all checkpoints'
43
				)
44
		;
45
	}
46
47
	protected function execute(InputInterface $input, OutputInterface $output){
48
		clearstatcache();
49
		$checkpoint = $this->container['utils.checkpoint'];
50
		if ($input->getOption('create')){
51
			$checkpointName = $checkpoint->create();
52
			$output->writeln('Created checkpoint ' . $checkpointName);
53
		} elseif ($input->getOption('restore')) {
54
			$checkpointId = stripslashes($input->getOption('restore'));
55
			$checkpoint->restore($checkpointId);
56
		} else {
57
			$checkpoints = $checkpoint->getAll();
58
			if (count($checkpoints)){
59
				foreach ($checkpoints as $checkpoint){
60
					$output->writeln(sprintf('%s  - %s', $checkpoint['title'], $checkpoint['date']));
61
				}
62
			} else {
63
				$output->writeln('No checkpoints found');
64
			}
65
		}
66
	}
67
68
}
69