Disable.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author John Molakvoæ <skjnldsv@protonmail.com>
  8. * @author Robin Appelman <robin@icewind.nl>
  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): int {
  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. $appVersion = \OC_App::getAppVersion($appId);
  70. $output->writeln($appId . ' ' . $appVersion . ' disabled');
  71. } catch (\Exception $e) {
  72. $output->writeln($e->getMessage());
  73. $this->exitCode = 2;
  74. }
  75. }
  76. /**
  77. * @param string $optionName
  78. * @param CompletionContext $context
  79. * @return string[]
  80. */
  81. public function completeOptionValues($optionName, CompletionContext $context) {
  82. return [];
  83. }
  84. /**
  85. * @param string $argumentName
  86. * @param CompletionContext $context
  87. * @return string[]
  88. */
  89. public function completeArgumentValues($argumentName, CompletionContext $context) {
  90. if ($argumentName === 'app-id') {
  91. return array_diff(\OC_App::getEnabledApps(true, true), $this->appManager->getAlwaysEnabledApps());
  92. }
  93. return [];
  94. }
  95. }