Completed
Push — master ( 63aa12...c7757b )
by Morris
17:27 queued 24s
created

Install   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
B execute() 0 32 4
A configure() 0 11 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Klaus Herberth <[email protected]>
6
 *
7
 * @license AGPL-3.0
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace OC\Core\Command\App;
24
25
use OC\Installer;
26
use Symfony\Component\Console\Command\Command;
27
use Symfony\Component\Console\Input\InputArgument;
28
use Symfony\Component\Console\Input\InputInterface;
29
use Symfony\Component\Console\Output\OutputInterface;
30
31
class Install extends Command {
32
33
	protected function configure() {
34
		$this
35
			->setName('app:install')
36
			->setDescription('install an app')
37
			->addArgument(
38
				'app-id',
39
				InputArgument::REQUIRED,
40
				'install the specified app'
41
			)
42
		;
43
	}
44
45
	protected function execute(InputInterface $input, OutputInterface $output) {
46
		$appId = $input->getArgument('app-id');
47
48
		if (\OC_App::getAppPath($appId)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression \OC_App::getAppPath($appId) of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
49
			$output->writeln($appId . ' already installed');
50
			return 1;
51
		}
52
53
		try {
54
			$installer = new Installer(
55
				\OC::$server->getAppFetcher(),
56
				\OC::$server->getHTTPClientService(),
57
				\OC::$server->getTempManager(),
58
				\OC::$server->getLogger(),
59
				\OC::$server->getConfig()
60
			);
61
			$installer->downloadApp($appId);
62
			$result = $installer->installApp($appId);
63
		} catch(\Exception $e) {
64
			$output->writeln('Error: ' . $e->getMessage());
65
			return 1;
66
		}
67
68
		if($result === false) {
69
			$output->writeln($appId . ' couldn\'t be installed');
70
			return 1;
71
		}
72
73
		$output->writeln($appId . ' installed');
74
75
		return 0;
76
	}
77
}
78