|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
/** |
|
4
|
|
|
* /src/Command/User/RemoveUserGroupCommand.php |
|
5
|
|
|
* |
|
6
|
|
|
* @author TLe, Tarmo Leppänen <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace App\Command\User; |
|
10
|
|
|
|
|
11
|
|
|
use App\Command\Traits\SymfonyStyleTrait; |
|
12
|
|
|
use App\Entity\UserGroup; |
|
13
|
|
|
use App\Resource\UserGroupResource; |
|
14
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
|
15
|
|
|
use Symfony\Component\Console\Command\Command; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
use Throwable; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class RemoveUserGroupCommand |
|
22
|
|
|
* |
|
23
|
|
|
* @package App\Command\User |
|
24
|
|
|
* @author TLe, Tarmo Leppänen <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
#[AsCommand( |
|
27
|
|
|
name: self::NAME, |
|
28
|
|
|
description: 'Console command to remove existing user group', |
|
29
|
|
|
)] |
|
30
|
|
|
class RemoveUserGroupCommand extends Command |
|
31
|
|
|
{ |
|
32
|
|
|
use SymfonyStyleTrait; |
|
33
|
|
|
|
|
34
|
|
|
final public const NAME = 'user:remove-group'; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct( |
|
37
|
|
|
private readonly UserGroupResource $userGroupResource, |
|
38
|
|
|
private readonly UserHelper $userHelper, |
|
39
|
|
|
) { |
|
40
|
|
|
parent::__construct(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @noinspection PhpMissingParentCallCommonInspection |
|
45
|
|
|
* |
|
46
|
|
|
* @throws Throwable |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
49
|
|
|
{ |
|
50
|
|
|
$io = $this->getSymfonyStyle($input, $output); |
|
51
|
|
|
$userGroup = $this->userHelper->getUserGroup($io, 'Which user group you want to remove?'); |
|
52
|
|
|
$message = $userGroup instanceof UserGroup ? $this->delete($userGroup) : null; |
|
53
|
|
|
|
|
54
|
|
|
if ($input->isInteractive()) { |
|
55
|
|
|
$io->success($message ?? 'Nothing changed - have a nice day'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return 0; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @throws Throwable |
|
63
|
|
|
*/ |
|
64
|
|
|
private function delete(UserGroup $userGroup): string |
|
65
|
|
|
{ |
|
66
|
|
|
$this->userGroupResource->delete($userGroup->getId()); |
|
67
|
|
|
|
|
68
|
|
|
return 'User group removed - have a nice day'; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|