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

CheckpointCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 0
cbo 4
dl 0
loc 40
ccs 0
cts 35
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 15 1
B execute() 0 20 5
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