1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
4
|
|
|
* |
5
|
|
|
* @author Christoph Wurst <[email protected]> |
6
|
|
|
* @author Joas Schilling <[email protected]> |
7
|
|
|
* @author John Molakvoæ <[email protected]> |
8
|
|
|
* @author Maxopoly <[email protected]> |
9
|
|
|
* @author Morris Jobke <[email protected]> |
10
|
|
|
* @author Roeland Jago Douma <[email protected]> |
11
|
|
|
* @author sualko <[email protected]> |
12
|
|
|
* |
13
|
|
|
* @license AGPL-3.0 |
14
|
|
|
* |
15
|
|
|
* This code is free software: you can redistribute it and/or modify |
16
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
17
|
|
|
* as published by the Free Software Foundation. |
18
|
|
|
* |
19
|
|
|
* This program is distributed in the hope that it will be useful, |
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22
|
|
|
* GNU Affero General Public License for more details. |
23
|
|
|
* |
24
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
25
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
26
|
|
|
* |
27
|
|
|
*/ |
28
|
|
|
namespace OC\Core\Command\App; |
29
|
|
|
|
30
|
|
|
use OC\Installer; |
31
|
|
|
use OCP\App\IAppManager; |
32
|
|
|
use Symfony\Component\Console\Command\Command; |
33
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
34
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
35
|
|
|
use Symfony\Component\Console\Input\InputOption; |
36
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
37
|
|
|
|
38
|
|
|
class Install extends Command { |
39
|
|
|
protected function configure() { |
40
|
|
|
$this |
41
|
|
|
->setName('app:install') |
42
|
|
|
->setDescription('install an app') |
43
|
|
|
->addArgument( |
44
|
|
|
'app-id', |
45
|
|
|
InputArgument::REQUIRED, |
46
|
|
|
'install the specified app' |
47
|
|
|
) |
48
|
|
|
->addOption( |
49
|
|
|
'keep-disabled', |
50
|
|
|
null, |
51
|
|
|
InputOption::VALUE_NONE, |
52
|
|
|
'don\'t enable the app afterwards' |
53
|
|
|
) |
54
|
|
|
->addOption( |
55
|
|
|
'force', |
56
|
|
|
'f', |
57
|
|
|
InputOption::VALUE_NONE, |
58
|
|
|
'install the app regardless of the Nextcloud version requirement' |
59
|
|
|
) |
60
|
|
|
->addOption( |
61
|
|
|
'allow-unstable', |
62
|
|
|
null, |
63
|
|
|
InputOption::VALUE_NONE, |
64
|
|
|
'allow installing an unstable releases' |
65
|
|
|
) |
66
|
|
|
; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int { |
70
|
|
|
$appId = $input->getArgument('app-id'); |
71
|
|
|
$forceEnable = (bool) $input->getOption('force'); |
72
|
|
|
|
73
|
|
|
if (\OC_App::getAppPath($appId)) { |
74
|
|
|
$output->writeln($appId . ' already installed'); |
75
|
|
|
return 1; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
try { |
79
|
|
|
/** @var Installer $installer */ |
80
|
|
|
$installer = \OC::$server->query(Installer::class); |
81
|
|
|
$installer->downloadApp($appId, $input->getOption('allow-unstable')); |
82
|
|
|
$result = $installer->installApp($appId, $forceEnable); |
83
|
|
|
} catch (\Exception $e) { |
84
|
|
|
$output->writeln('Error: ' . $e->getMessage()); |
85
|
|
|
return 1; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ($result === false) { |
|
|
|
|
89
|
|
|
$output->writeln($appId . ' couldn\'t be installed'); |
90
|
|
|
return 1; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$appVersion = \OCP\Server::get(IAppManager::class)->getAppVersion($appId); |
94
|
|
|
$output->writeln($appId . ' ' . $appVersion . ' installed'); |
95
|
|
|
|
96
|
|
|
if (!$input->getOption('keep-disabled')) { |
97
|
|
|
$appClass = new \OC_App(); |
98
|
|
|
$appClass->enable($appId); |
99
|
|
|
$output->writeln($appId . ' enabled'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return 0; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|