Delete.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2018 Denis Mosolov <denismosolov@gmail.com>
  5. *
  6. * @author Denis Mosolov <denismosolov@gmail.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  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
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OC\Core\Command\Group;
  26. use OC\Core\Command\Base;
  27. use OCP\IGroupManager;
  28. use Symfony\Component\Console\Input\InputArgument;
  29. use Symfony\Component\Console\Input\InputInterface;
  30. use Symfony\Component\Console\Output\OutputInterface;
  31. class Delete extends Base {
  32. /** @var IGroupManager */
  33. protected $groupManager;
  34. /**
  35. * @param IGroupManager $groupManager
  36. */
  37. public function __construct(IGroupManager $groupManager) {
  38. $this->groupManager = $groupManager;
  39. parent::__construct();
  40. }
  41. protected function configure() {
  42. $this
  43. ->setName('group:delete')
  44. ->setDescription('Remove a group')
  45. ->addArgument(
  46. 'groupid',
  47. InputArgument::REQUIRED,
  48. 'Group name'
  49. );
  50. }
  51. protected function execute(InputInterface $input, OutputInterface $output): int {
  52. $gid = $input->getArgument('groupid');
  53. if ($gid === 'admin') {
  54. $output->writeln('<error>Group "' . $gid . '" could not be deleted.</error>');
  55. return 1;
  56. }
  57. if (! $this->groupManager->groupExists($gid)) {
  58. $output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
  59. return 1;
  60. }
  61. $group = $this->groupManager->get($gid);
  62. if ($group->delete()) {
  63. $output->writeln('Group "' . $gid . '" was removed');
  64. } else {
  65. $output->writeln('<error>Group "' . $gid . '" could not be deleted. Please check the logs.</error>');
  66. return 1;
  67. }
  68. return 0;
  69. }
  70. }