|
| 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 | +} |
0 commit comments