Disable.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 $manager;
  36. /**
  37. * @param IAppManager $manager
  38. */
  39. public function __construct(IAppManager $manager) {
  40. parent::__construct();
  41. $this->manager = $manager;
  42. }
  43. protected function configure() {
  44. $this
  45. ->setName('app:disable')
  46. ->setDescription('disable an app')
  47. ->addArgument(
  48. 'app-id',
  49. InputArgument::REQUIRED,
  50. 'disable the specified app'
  51. );
  52. }
  53. protected function execute(InputInterface $input, OutputInterface $output) {
  54. $appId = $input->getArgument('app-id');
  55. if ($this->manager->isInstalled($appId)) {
  56. try {
  57. $this->manager->disableApp($appId);
  58. $output->writeln($appId . ' disabled');
  59. } catch(\Exception $e) {
  60. $output->writeln($e->getMessage());
  61. return 2;
  62. }
  63. } else {
  64. $output->writeln('No such app enabled: ' . $appId);
  65. }
  66. }
  67. /**
  68. * @param string $optionName
  69. * @param CompletionContext $context
  70. * @return string[]
  71. */
  72. public function completeOptionValues($optionName, CompletionContext $context) {
  73. return [];
  74. }
  75. /**
  76. * @param string $argumentName
  77. * @param CompletionContext $context
  78. * @return string[]
  79. */
  80. public function completeArgumentValues($argumentName, CompletionContext $context) {
  81. if ($argumentName === 'app-id') {
  82. return array_diff(\OC_App::getEnabledApps(true, true), $this->manager->getAlwaysEnabledApps());
  83. }
  84. return [];
  85. }
  86. }