Disable.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  4. * SPDX-License-Identifier: AGPL-3.0-only
  5. */
  6. namespace OC\Core\Command\App;
  7. use OCP\App\IAppManager;
  8. use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
  9. use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
  10. use Symfony\Component\Console\Command\Command;
  11. use Symfony\Component\Console\Input\InputArgument;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Output\OutputInterface;
  14. class Disable extends Command implements CompletionAwareInterface {
  15. protected int $exitCode = 0;
  16. public function __construct(
  17. protected IAppManager $appManager,
  18. ) {
  19. parent::__construct();
  20. }
  21. protected function configure(): void {
  22. $this
  23. ->setName('app:disable')
  24. ->setDescription('disable an app')
  25. ->addArgument(
  26. 'app-id',
  27. InputArgument::REQUIRED | InputArgument::IS_ARRAY,
  28. 'disable the specified app'
  29. );
  30. }
  31. protected function execute(InputInterface $input, OutputInterface $output): int {
  32. $appIds = $input->getArgument('app-id');
  33. foreach ($appIds as $appId) {
  34. $this->disableApp($appId, $output);
  35. }
  36. return $this->exitCode;
  37. }
  38. private function disableApp(string $appId, OutputInterface $output): void {
  39. if ($this->appManager->isInstalled($appId) === false) {
  40. $output->writeln('No such app enabled: ' . $appId);
  41. return;
  42. }
  43. try {
  44. $this->appManager->disableApp($appId);
  45. $appVersion = $this->appManager->getAppVersion($appId);
  46. $output->writeln($appId . ' ' . $appVersion . ' disabled');
  47. } catch (\Exception $e) {
  48. $output->writeln($e->getMessage());
  49. $this->exitCode = 2;
  50. }
  51. }
  52. /**
  53. * @param string $optionName
  54. * @param CompletionContext $context
  55. * @return string[]
  56. */
  57. public function completeOptionValues($optionName, CompletionContext $context): array {
  58. return [];
  59. }
  60. /**
  61. * @param string $argumentName
  62. * @param CompletionContext $context
  63. * @return string[]
  64. */
  65. public function completeArgumentValues($argumentName, CompletionContext $context): array {
  66. if ($argumentName === 'app-id') {
  67. return array_diff(\OC_App::getEnabledApps(true, true), $this->appManager->getAlwaysEnabledApps());
  68. }
  69. return [];
  70. }
  71. }