Disable.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Vincent Petry <pvince81@owncloud.com>
  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. namespace OC\Core\Command\App;
  26. use OCP\App\IAppManager;
  27. use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
  28. use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
  29. use Symfony\Component\Console\Command\Command;
  30. use Symfony\Component\Console\Input\InputArgument;
  31. use Symfony\Component\Console\Input\InputInterface;
  32. use Symfony\Component\Console\Output\OutputInterface;
  33. class Disable extends Command implements CompletionAwareInterface {
  34. /** @var IAppManager */
  35. protected $appManager;
  36. /** @var int */
  37. protected $exitCode = 0;
  38. /**
  39. * @param IAppManager $appManager
  40. */
  41. public function __construct(IAppManager $appManager) {
  42. parent::__construct();
  43. $this->appManager = $appManager;
  44. }
  45. protected function configure(): void {
  46. $this
  47. ->setName('app:disable')
  48. ->setDescription('disable an app')
  49. ->addArgument(
  50. 'app-id',
  51. InputArgument::REQUIRED | InputArgument::IS_ARRAY,
  52. 'disable the specified app'
  53. );
  54. }
  55. protected function execute(InputInterface $input, OutputInterface $output) {
  56. $appIds = $input->getArgument('app-id');
  57. foreach ($appIds as $appId) {
  58. $this->disableApp($appId, $output);
  59. }
  60. return $this->exitCode;
  61. }
  62. private function disableApp(string $appId, OutputInterface $output): void {
  63. if ($this->appManager->isInstalled($appId) === false) {
  64. $output->writeln('No such app enabled: ' . $appId);
  65. return;
  66. }
  67. try {
  68. $this->appManager->disableApp($appId);
  69. $output->writeln($appId . ' disabled');
  70. } catch (\Exception $e) {
  71. $output->writeln($e->getMessage());
  72. $this->exitCode = 2;
  73. }
  74. }
  75. /**
  76. * @param string $optionName
  77. * @param CompletionContext $context
  78. * @return string[]
  79. */
  80. public function completeOptionValues($optionName, CompletionContext $context) {
  81. return [];
  82. }
  83. /**
  84. * @param string $argumentName
  85. * @param CompletionContext $context
  86. * @return string[]
  87. */
  88. public function completeArgumentValues($argumentName, CompletionContext $context) {
  89. if ($argumentName === 'app-id') {
  90. return array_diff(\OC_App::getEnabledApps(true, true), $this->appManager->getAlwaysEnabledApps());
  91. }
  92. return [];
  93. }
  94. }