1
0

Delete.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\Files_External\Command;
  25. use OC\Core\Command\Base;
  26. use OCA\Files_External\NotFoundException;
  27. use OCA\Files_External\Service\GlobalStoragesService;
  28. use OCA\Files_External\Service\UserStoragesService;
  29. use OCP\IUserManager;
  30. use OCP\IUserSession;
  31. use Symfony\Component\Console\Input\ArrayInput;
  32. use Symfony\Component\Console\Input\InputArgument;
  33. use Symfony\Component\Console\Input\InputInterface;
  34. use Symfony\Component\Console\Input\InputOption;
  35. use Symfony\Component\Console\Output\OutputInterface;
  36. use Symfony\Component\Console\Question\ConfirmationQuestion;
  37. use Symfony\Component\HttpFoundation\Response;
  38. class Delete extends Base {
  39. public function __construct(
  40. protected GlobalStoragesService $globalService,
  41. protected UserStoragesService $userService,
  42. protected IUserSession $userSession,
  43. protected IUserManager $userManager,
  44. ) {
  45. parent::__construct();
  46. }
  47. protected function configure(): void {
  48. $this
  49. ->setName('files_external:delete')
  50. ->setDescription('Delete an external mount')
  51. ->addArgument(
  52. 'mount_id',
  53. InputArgument::REQUIRED,
  54. 'The id of the mount to edit'
  55. )->addOption(
  56. 'yes',
  57. 'y',
  58. InputOption::VALUE_NONE,
  59. 'Skip confirmation'
  60. );
  61. parent::configure();
  62. }
  63. protected function execute(InputInterface $input, OutputInterface $output): int {
  64. $mountId = $input->getArgument('mount_id');
  65. try {
  66. $mount = $this->globalService->getStorage($mountId);
  67. } catch (NotFoundException $e) {
  68. $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>');
  69. return Response::HTTP_NOT_FOUND;
  70. }
  71. $noConfirm = $input->getOption('yes');
  72. if (!$noConfirm) {
  73. $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
  74. $listInput = new ArrayInput([], $listCommand->getDefinition());
  75. $listInput->setOption('output', $input->getOption('output'));
  76. $listCommand->listMounts(null, [$mount], $listInput, $output);
  77. $questionHelper = $this->getHelper('question');
  78. $question = new ConfirmationQuestion('Delete this mount? [y/N] ', false);
  79. if (!$questionHelper->ask($input, $output, $question)) {
  80. return self::FAILURE;
  81. }
  82. }
  83. $this->globalService->removeStorage($mountId);
  84. return self::SUCCESS;
  85. }
  86. }