Completed
Pull Request — master (#348)
by Victor
04:50
created

CheckSystemCommand::execute()   B

Complexity

Conditions 6
Paths 16

Size

Total Lines 40
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 40
ccs 0
cts 33
cp 0
rs 8.439
cc 6
eloc 27
nc 16
nop 2
crap 42
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\Output\OutputInterface;
26
use Owncloud\Updater\Utils\Collection;
27
28
class CheckSystemCommand extends Command {
29
30
	protected $message = 'Checking system health.';
31
32
	protected function configure(){
33
		$this
34
				->setName('upgrade:checkSystem')
35
				->setDescription('System check. System health and if dependencies are OK (we also count the number of files and DB entries and give time estimations based on hardcoded estimation)')
36
		;
37
	}
38
39
	protected function execute(InputInterface $input, OutputInterface $output){
40
		$locator = $this->container['utils.locator'];
41
		$fsHelper = $this->container['utils.filesystemhelper'];
42
		/** @var \Owncloud\Updater\Utils\Registry $registry */
43
		$registry = $this->container['utils.registry'];
44
		/** @var  \Owncloud\Updater\Utils\AppManager  $occRunner */
45
		$appManager = $this->container['utils.appmanager'];
46
		$registry->set(
47
			'notShippedApps',
48
			$appManager->getNotShippedApps()
49
		);
50
		$occRunner = $this->container['utils.occrunner'];
0 ignored issues
show
Unused Code introduced by
$occRunner is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
51
52
		$collection = new Collection();
53
54
		$rootDirItems= $locator->getRootDirItems();
55
		foreach ($rootDirItems as $item){
56
			$fsHelper->checkr($item, $collection);
57
		}
58
		$notReadableFiles = $collection->getNotReadable();
59
		$notWritableFiles = $collection->getNotWritable();
60
61
		if (count($notReadableFiles)){
62
			$output->writeln('<error>The following files and directories are not readable:</error>');
63
			$output->writeln($this->longArrayToString($notReadableFiles));
64
		}
65
66
		if (count($notWritableFiles)){
67
			$output->writeln('<error>The following files and directories are not writable:</error>');
68
			$output->writeln($this->longArrayToString($notWritableFiles));
69
		}
70
71
		if (count($notReadableFiles) || count($notWritableFiles)){
72
			$output->writeln('<info>Please check if owner and permissions for these files are correct.</info>');
73
			$output->writeln('<info>See https://doc.owncloud.org/server/9.0/admin_manual/installation/installation_wizard.html#strong-perms-label for details.</info>');
74
			return 2;
75
		} else {
76
			$output->writeln(' - file permissions are ok.');
77
		}
78
	}
79
80
	protected function longArrayToString($array){
81
		if (count($array)>7){
82
			$shortArray = array_slice($array, 0, 7);
83
			$more = sprintf('... and %d more items', count($array) - count($shortArray));
84
			array_push($shortArray, $more);
85
		} else {
86
			$shortArray = $array;
87
		}
88
		$string = implode(PHP_EOL, $shortArray);
89
		return $string;
90
	}
91
92
}
93