Skip to content

Commit 2cb7214

Browse files
committed
add occ app:install command
Signed-off-by: Klaus Herberth <[email protected]>
1 parent 8d751ff commit 2cb7214

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

core/Command/App/Install.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
use OC\Installer;
24+
use Symfony\Component\Console\Command\Command;
25+
use Symfony\Component\Console\Input\InputArgument;
26+
use Symfony\Component\Console\Input\InputInterface;
27+
use Symfony\Component\Console\Output\OutputInterface;
28+
29+
class Install extends Command {
30+
31+
protected function configure() {
32+
$this
33+
->setName('app:install')
34+
->setDescription('install an app')
35+
->addArgument(
36+
'app-id',
37+
InputArgument::REQUIRED,
38+
'install the specified app'
39+
)
40+
;
41+
}
42+
43+
protected function execute(InputInterface $input, OutputInterface $output) {
44+
$appId = $input->getArgument('app-id');
45+
46+
if (\OC_App::getAppPath($appId)) {
47+
$output->writeln($appId . ' already installed');
48+
return 1;
49+
}
50+
51+
try {
52+
$installer = new Installer(
53+
\OC::$server->getAppFetcher(),
54+
\OC::$server->getHTTPClientService(),
55+
\OC::$server->getTempManager(),
56+
\OC::$server->getLogger(),
57+
\OC::$server->getConfig()
58+
);
59+
$installer->downloadApp($appId);
60+
$result = $installer->installApp($appId);
61+
} catch(\Exception $e) {
62+
$output->writeln('Error: ' . $e->getMessage());
63+
return 1;
64+
}
65+
66+
if($result === false) {
67+
$output->writeln($appId . ' couldn\'t be installed');
68+
return 1;
69+
}
70+
71+
$output->writeln($appId . ' installed');
72+
73+
return 0;
74+
}
75+
}

core/register_command.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@
5959
if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
6060
$application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager()));
6161
$application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager()));
62+
$application->add(new OC\Core\Command\App\Install());
6263
$application->add(new OC\Core\Command\App\GetPath());
6364
$application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager()));
64-
65+
6566
$application->add(new OC\Core\Command\TwoFactorAuth\Enable(
6667
\OC::$server->getTwoFactorAuthManager(), \OC::$server->getUserManager()
6768
));

0 commit comments

Comments
 (0)