|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @copyright Copyright (c) 2018 Denis Mosolov <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @author Denis Mosolov <[email protected]> |
|
9
|
|
|
* @author Joas Schilling <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* @license GNU AGPL version 3 or any later version |
|
12
|
|
|
* |
|
13
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
14
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
15
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
16
|
|
|
* License, or (at your option) any later version. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is distributed in the hope that it will be useful, |
|
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21
|
|
|
* GNU Affero General Public License for more details. |
|
22
|
|
|
* |
|
23
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
24
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
25
|
|
|
* |
|
26
|
|
|
*/ |
|
27
|
|
|
namespace OC\Core\Command\Group; |
|
28
|
|
|
|
|
29
|
|
|
use OC\Core\Command\Base; |
|
30
|
|
|
use OCP\IGroup; |
|
31
|
|
|
use OCP\IGroupManager; |
|
32
|
|
|
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
|
33
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
34
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
35
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
36
|
|
|
|
|
37
|
|
|
class Delete extends Base { |
|
38
|
|
|
/** @var IGroupManager */ |
|
39
|
|
|
protected $groupManager; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param IGroupManager $groupManager |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct(IGroupManager $groupManager) { |
|
45
|
|
|
$this->groupManager = $groupManager; |
|
46
|
|
|
parent::__construct(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
protected function configure() { |
|
50
|
|
|
$this |
|
51
|
|
|
->setName('group:delete') |
|
52
|
|
|
->setDescription('Remove a group') |
|
53
|
|
|
->addArgument( |
|
54
|
|
|
'groupid', |
|
55
|
|
|
InputArgument::REQUIRED, |
|
56
|
|
|
'Group name' |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int { |
|
61
|
|
|
$gid = $input->getArgument('groupid'); |
|
62
|
|
|
if ($gid === 'admin') { |
|
63
|
|
|
$output->writeln('<error>Group "' . $gid . '" could not be deleted.</error>'); |
|
64
|
|
|
return 1; |
|
65
|
|
|
} |
|
66
|
|
|
if (!$this->groupManager->groupExists($gid)) { |
|
67
|
|
|
$output->writeln('<error>Group "' . $gid . '" does not exist.</error>'); |
|
68
|
|
|
return 1; |
|
69
|
|
|
} |
|
70
|
|
|
$group = $this->groupManager->get($gid); |
|
71
|
|
|
if ($group->delete()) { |
|
72
|
|
|
$output->writeln('Group "' . $gid . '" was removed'); |
|
73
|
|
|
} else { |
|
74
|
|
|
$output->writeln('<error>Group "' . $gid . '" could not be deleted. Please check the logs.</error>'); |
|
75
|
|
|
return 1; |
|
76
|
|
|
} |
|
77
|
|
|
return 0; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param string $argumentName |
|
82
|
|
|
* @param CompletionContext $context |
|
83
|
|
|
* @return string[] |
|
84
|
|
|
*/ |
|
85
|
|
|
public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
86
|
|
|
if ($argumentName === 'groupid') { |
|
87
|
|
|
return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord())); |
|
88
|
|
|
} |
|
89
|
|
|
return []; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|