|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Joas Schilling <[email protected]> |
|
6
|
|
|
* @author Morris Jobke <[email protected]> |
|
7
|
|
|
* @author Robin Appelman <[email protected]> |
|
8
|
|
|
* @author Vincent Petry <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* @license AGPL-3.0 |
|
11
|
|
|
* |
|
12
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
14
|
|
|
* as published by the Free Software Foundation. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU Affero General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace OC\Core\Command\App; |
|
27
|
|
|
|
|
28
|
|
|
use OCP\App\IAppManager; |
|
29
|
|
|
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface; |
|
30
|
|
|
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
|
31
|
|
|
use Symfony\Component\Console\Command\Command; |
|
32
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
33
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
34
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
35
|
|
|
|
|
36
|
|
|
class Disable extends Command implements CompletionAwareInterface { |
|
37
|
|
|
|
|
38
|
|
|
/** @var IAppManager */ |
|
39
|
|
|
protected $appManager; |
|
40
|
|
|
|
|
41
|
|
|
/** @var int */ |
|
42
|
|
|
protected $exitCode = 0; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param IAppManager $appManager |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct(IAppManager $appManager) { |
|
48
|
|
|
parent::__construct(); |
|
49
|
|
|
$this->appManager = $appManager; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function configure(): void { |
|
53
|
|
|
$this |
|
54
|
|
|
->setName('app:disable') |
|
55
|
|
|
->setDescription('disable an app') |
|
56
|
|
|
->addArgument( |
|
57
|
|
|
'app-id', |
|
58
|
|
|
InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
|
59
|
|
|
'disable the specified app' |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
|
64
|
|
|
$appIds = $input->getArgument('app-id'); |
|
65
|
|
|
|
|
66
|
|
|
foreach ($appIds as $appId) { |
|
67
|
|
|
$this->disableApp($appId, $output); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $this->exitCode; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
private function disableApp(string $appId, OutputInterface $output): void { |
|
74
|
|
|
if ($this->appManager->isInstalled($appId) === false) { |
|
75
|
|
|
$output->writeln('No such app enabled: ' . $appId); |
|
76
|
|
|
return; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
try { |
|
80
|
|
|
$this->appManager->disableApp($appId); |
|
81
|
|
|
$output->writeln($appId . ' disabled'); |
|
82
|
|
|
} catch (\Exception $e) { |
|
83
|
|
|
$output->writeln($e->getMessage()); |
|
84
|
|
|
$this->exitCode = 2; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param string $optionName |
|
90
|
|
|
* @param CompletionContext $context |
|
91
|
|
|
* @return string[] |
|
92
|
|
|
*/ |
|
93
|
|
|
public function completeOptionValues($optionName, CompletionContext $context) { |
|
94
|
|
|
return []; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param string $argumentName |
|
99
|
|
|
* @param CompletionContext $context |
|
100
|
|
|
* @return string[] |
|
101
|
|
|
*/ |
|
102
|
|
|
public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
103
|
|
|
if ($argumentName === 'app-id') { |
|
104
|
|
|
return array_diff(\OC_App::getEnabledApps(true, true), $this->appManager->getAlwaysEnabledApps()); |
|
105
|
|
|
} |
|
106
|
|
|
return []; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|