1<?php
2/**
3 * @author Joas Schilling <coding@schilljs.com>
4 * @author Morris Jobke <hey@morrisjobke.de>
5 * @author Robin Appelman <icewind@owncloud.com>
6 * @author Vincent Petry <pvince81@owncloud.com>
7 *
8 * @copyright Copyright (c) 2018, ownCloud GmbH
9 * @license AGPL-3.0
10 *
11 * This code is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Affero General Public License, version 3,
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
19 *
20 * You should have received a copy of the GNU Affero General Public License, version 3,
21 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22 *
23 */
24
25namespace OC\Core\Command\App;
26
27use OCP\App\IAppManager;
28use Symfony\Component\Console\Command\Command;
29use Symfony\Component\Console\Input\InputArgument;
30use Symfony\Component\Console\Input\InputInterface;
31use Symfony\Component\Console\Output\OutputInterface;
32
33class Disable extends Command {
34
35	/** @var IAppManager */
36	protected $manager;
37
38	/**
39	 * @param IAppManager $manager
40	 */
41	public function __construct(IAppManager $manager) {
42		parent::__construct();
43		$this->manager = $manager;
44	}
45
46	protected function configure() {
47		$this
48			->setName('app:disable')
49			->setDescription('Disable an app.')
50			->addArgument(
51				'app-id',
52				InputArgument::REQUIRED,
53				'Disable the specified app.'
54			);
55	}
56
57	protected function execute(InputInterface $input, OutputInterface $output) {
58		$appId = $input->getArgument('app-id');
59		if ($this->manager->isInstalled($appId)) {
60			try {
61				$this->manager->disableApp($appId);
62				$output->writeln($appId . ' disabled');
63			} catch (\Exception $e) {
64				$output->writeln($e->getMessage());
65				return 2;
66			}
67		} else {
68			$output->writeln('No such app enabled: ' . $appId);
69		}
70	}
71}
72