|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Del\Console; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use Del\Common\ContainerService; |
|
7
|
|
|
use Del\Criteria\UserCriteria; |
|
8
|
|
|
use Del\Service\UserService; |
|
9
|
|
|
use Symfony\Component\Console\Command\Command; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
|
|
15
|
|
|
class UserCommand extends Command |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var UserService $userService */ |
|
18
|
|
|
private $userService; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* UserCommand constructor. |
|
22
|
|
|
* @throws \Doctrine\ORM\ORMException |
|
23
|
|
|
*/ |
|
24
|
2 |
|
public function __construct() |
|
25
|
|
|
{ |
|
26
|
2 |
|
parent::__construct(); |
|
27
|
2 |
|
$container = ContainerService::getInstance()->getContainer(); |
|
28
|
2 |
|
$this->userService = $container[UserService::class]; |
|
29
|
2 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* |
|
33
|
|
|
*/ |
|
34
|
2 |
|
protected function configure() |
|
35
|
|
|
{ |
|
36
|
|
|
$this |
|
37
|
2 |
|
->setName('reset-pass') |
|
38
|
2 |
|
->setDescription('Resets a user\'s password') |
|
39
|
2 |
|
->addArgument( |
|
40
|
2 |
|
'email', |
|
41
|
2 |
|
InputArgument::REQUIRED, |
|
42
|
2 |
|
'The email of the user' |
|
43
|
2 |
|
)->addArgument( |
|
44
|
2 |
|
'newPassword', |
|
45
|
2 |
|
InputArgument::REQUIRED, |
|
46
|
2 |
|
'The email of the user' |
|
47
|
|
|
) |
|
48
|
|
|
; |
|
49
|
2 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param InputInterface $input |
|
53
|
|
|
* @param OutputInterface $output |
|
54
|
|
|
* @return int|void|null |
|
55
|
|
|
* @throws \Doctrine\ORM\OptimisticLockException |
|
56
|
|
|
*/ |
|
57
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
58
|
|
|
{ |
|
59
|
2 |
|
$email = $input->getArgument('email'); |
|
60
|
2 |
|
$pass = $input->getArgument('newPassword'); |
|
61
|
2 |
|
$criteria = new UserCriteria(); |
|
62
|
2 |
|
$criteria->setEmail($email); |
|
|
|
|
|
|
63
|
2 |
|
$user = $this->userService->findOneByCriteria($criteria); |
|
64
|
2 |
|
if ($user === null) { |
|
65
|
1 |
|
$output->writeln('No User Found.'); |
|
66
|
|
|
} else { |
|
67
|
1 |
|
$this->userService->changePassword($user, $pass); |
|
|
|
|
|
|
68
|
1 |
|
$this->userService->saveUser($user); |
|
69
|
1 |
|
$output->writeln('Password changed for '.$email); |
|
70
|
|
|
} |
|
71
|
2 |
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.