|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the zibios/sharep. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Zbigniew Ślązak |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace App\Command\Functional; |
|
12
|
|
|
|
|
13
|
|
|
use App\Command\AbstractCommand; |
|
14
|
|
|
use App\Enum\Functional\RoleEnum; |
|
15
|
|
|
use App\Repository\Entity\Account\UserRepository; |
|
16
|
|
|
use App\Service\Functional\ApplicationInitializeService; |
|
17
|
|
|
use App\Service\Parking\MemberService; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
21
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
22
|
|
|
|
|
23
|
|
|
class ApplicationInitializeCommand extends AbstractCommand |
|
24
|
|
|
{ |
|
25
|
|
|
protected static $defaultName = 'app:application:initialize'; |
|
26
|
|
|
/** |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $environments = [self::ENV_TEST, self::ENV_PROD]; |
|
30
|
|
|
/** |
|
31
|
|
|
* @var ApplicationInitializeService |
|
32
|
|
|
*/ |
|
33
|
|
|
private $applicationInitializeService; |
|
34
|
|
|
/** |
|
35
|
|
|
* @var MemberService |
|
36
|
|
|
*/ |
|
37
|
|
|
private $memberService; |
|
38
|
|
|
|
|
39
|
4 |
|
public function __construct( |
|
40
|
|
|
UserRepository $userRepository, |
|
41
|
|
|
TokenStorageInterface $tokenStorage, |
|
42
|
|
|
ApplicationInitializeService $applicationInitializeService, |
|
43
|
|
|
MemberService $memberService |
|
44
|
|
|
) { |
|
45
|
4 |
|
parent::__construct($userRepository, $tokenStorage); |
|
46
|
4 |
|
$this->applicationInitializeService = $applicationInitializeService; |
|
47
|
4 |
|
$this->memberService = $memberService; |
|
48
|
4 |
|
} |
|
49
|
|
|
|
|
50
|
4 |
|
protected function configure(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$this |
|
53
|
4 |
|
->setDescription('Initialize application, creates first manager account.') |
|
54
|
4 |
|
->setHelp('This command allows you to initialize a fresh account. Can be executed only once.'); |
|
55
|
4 |
|
$this->addOption( |
|
56
|
4 |
|
'name', |
|
57
|
4 |
|
null, |
|
58
|
4 |
|
InputOption::VALUE_REQUIRED, |
|
59
|
4 |
|
'Name for Manager' |
|
60
|
4 |
|
)->addOption( |
|
61
|
4 |
|
'email', |
|
62
|
4 |
|
null, |
|
63
|
4 |
|
InputOption::VALUE_REQUIRED, |
|
64
|
4 |
|
'Email for Manager' |
|
65
|
|
|
); |
|
66
|
4 |
|
parent::configure(); |
|
67
|
4 |
|
} |
|
68
|
|
|
|
|
69
|
6 |
|
protected function executeBody(InputInterface $input, OutputInterface $output): int |
|
70
|
|
|
{ |
|
71
|
|
|
/** @var string $name */ |
|
72
|
6 |
|
$name = $input->getOption('name'); |
|
73
|
|
|
/** @var string $email */ |
|
74
|
6 |
|
$email = $input->getOption('email'); |
|
75
|
|
|
|
|
76
|
6 |
|
$this->applicationInitializeService->createSystemMember(); |
|
77
|
4 |
|
$this->logInAsSystemMember(); |
|
78
|
4 |
|
$this->memberService->createMember( |
|
79
|
4 |
|
$name, |
|
80
|
|
|
$email, |
|
81
|
4 |
|
RoleEnum::MANAGER() |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
4 |
|
return self::CODE_SUCCESS; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|