1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
6
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
7
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
8
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
9
|
|
|
|
10
|
|
|
class UserEditCommand extends AbstractUserCommand |
11
|
|
|
{ |
12
|
|
|
const FIELD_PASSWORD = 'Password'; |
13
|
|
|
const FIELD_REAL_NAME = 'Real Name'; |
14
|
|
|
|
15
|
|
|
protected function configure() |
16
|
|
|
{ |
17
|
|
|
$this |
18
|
|
|
->setName('gitki:user:edit') |
19
|
|
|
->setDescription('Edits an existing user'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
23
|
|
|
{ |
24
|
|
|
$userManager = $this->getUserManager(); |
25
|
|
|
$questionHelper = $this->getQuestionHelper(); |
26
|
|
|
|
27
|
|
|
$user = $this->selectUser($input, $output); |
28
|
|
|
|
29
|
|
|
$fields = [ |
30
|
|
|
self::FIELD_REAL_NAME, |
31
|
|
|
'Email', |
32
|
|
|
'Role', |
33
|
|
|
self::FIELD_PASSWORD, |
34
|
|
|
'Github Login', |
35
|
|
|
'Google Login', |
36
|
|
|
'Done' |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
$fieldQuestion = new ChoiceQuestion( |
40
|
|
|
'Select Field: ', |
41
|
|
|
$fields |
42
|
|
|
); |
43
|
|
|
do { |
44
|
|
|
$this->printUser($user, $output); |
45
|
|
|
$field = $questionHelper->ask($input, $output, $fieldQuestion); |
46
|
|
|
switch ($field) { |
47
|
|
|
case self::FIELD_REAL_NAME: |
48
|
|
|
$user = $this->editRealName($input, $output, $user, $questionHelper); |
49
|
|
|
break; |
50
|
|
|
case 'Email': |
51
|
|
|
$user = $this->editEmail($input, $output, $user, $questionHelper); |
52
|
|
|
break; |
53
|
|
|
case 'Role': |
54
|
|
|
$user = $this->editRole($input, $output, $user, $questionHelper); |
55
|
|
|
break; |
56
|
|
|
case self::FIELD_PASSWORD: |
57
|
|
|
$user = $this->editPassword($input, $output, $user, $questionHelper, $userManager); |
58
|
|
|
break; |
59
|
|
|
case 'Github Login': |
60
|
|
|
$user = $this->editGithubId($input, $output, $user, $questionHelper); |
61
|
|
|
break; |
62
|
|
|
case 'Google Login': |
63
|
|
|
$user = $this->editGoogleId($input, $output, $user, $questionHelper); |
64
|
|
|
break; |
65
|
|
|
} |
66
|
|
|
} while ('Done' !== $field); |
67
|
|
|
|
68
|
|
|
$this->printUser($user, $output); |
69
|
|
|
|
70
|
|
|
$saveQuestion = new ConfirmationQuestion('Save? ', false); |
71
|
|
|
if ($questionHelper->ask($input, $output, $saveQuestion)) { |
72
|
|
|
$userManager->updateUser($user); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|