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
|
|
|
public function __construct(UserService $userService) |
25
|
|
|
{ |
26
|
|
|
parent::__construct(); |
27
|
|
|
$this->userService = $userService; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* |
32
|
|
|
*/ |
33
|
|
|
protected function configure() |
34
|
|
|
{ |
35
|
|
|
$this |
36
|
|
|
->setName('reset-pass') |
37
|
|
|
->setDescription('Resets a user\'s password') |
38
|
|
|
->addArgument( |
39
|
|
|
'email', |
40
|
|
|
InputArgument::REQUIRED, |
41
|
|
|
'The email of the user' |
42
|
|
|
)->addArgument( |
43
|
|
|
'newPassword', |
44
|
|
|
InputArgument::REQUIRED, |
45
|
|
|
'The email of the user' |
46
|
|
|
) |
47
|
|
|
; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param InputInterface $input |
52
|
|
|
* @param OutputInterface $output |
53
|
|
|
* @return int|void|null |
54
|
|
|
* @throws \Doctrine\ORM\OptimisticLockException |
55
|
|
|
*/ |
56
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
57
|
|
|
{ |
58
|
|
|
$email = $input->getArgument('email'); |
59
|
|
|
$pass = $input->getArgument('newPassword'); |
60
|
|
|
$criteria = new UserCriteria(); |
61
|
|
|
$criteria->setEmail($email); |
|
|
|
|
62
|
|
|
$user = $this->userService->findOneByCriteria($criteria); |
63
|
|
|
if ($user === null) { |
64
|
|
|
$output->writeln('No User Found.'); |
65
|
|
|
} else { |
66
|
|
|
$this->userService->changePassword($user, $pass); |
|
|
|
|
67
|
|
|
$this->userService->saveUser($user); |
68
|
|
|
$output->writeln('Password changed for '.$email); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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.