]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Command/ShowUserCommand.php
Update messages.pl.yml
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Command / ShowUserCommand.php
CommitLineData
d143fa24
TC
1<?php
2
3namespace Wallabag\CoreBundle\Command;
4
5use Doctrine\ORM\NoResultException;
6use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Input\InputInterface;
9use Symfony\Component\Console\Output\OutputInterface;
d58199f3 10use Symfony\Component\Console\Style\SymfonyStyle;
d143fa24
TC
11use Wallabag\UserBundle\Entity\User;
12
13class ShowUserCommand extends ContainerAwareCommand
14{
d58199f3
NH
15 /** @var SymfonyStyle */
16 protected $io;
d143fa24
TC
17
18 protected function configure()
19 {
20 $this
21 ->setName('wallabag:user:show')
22 ->setDescription('Show user details')
23 ->setHelp('This command shows the details for an user')
24 ->addArgument(
25 'username',
26 InputArgument::REQUIRED,
27 'User to show details for'
28 );
29 }
30
31 protected function execute(InputInterface $input, OutputInterface $output)
32 {
d58199f3 33 $this->io = new SymfonyStyle($input, $output);
d143fa24
TC
34
35 $username = $input->getArgument('username');
36
37 try {
38 $user = $this->getUser($username);
39 $this->showUser($user);
40 } catch (NoResultException $e) {
d58199f3 41 $this->io->error(sprintf('User "%s" not found.', $username));
d143fa24
TC
42
43 return 1;
44 }
45
46 return 0;
47 }
48
49 /**
50 * @param User $user
51 */
52 private function showUser(User $user)
53 {
d58199f3 54 $this->io->listing([
e1b33efb
NH
55 sprintf('Username: %s', $user->getUsername()),
56 sprintf('Email: %s', $user->getEmail()),
57 sprintf('Display name: %s', $user->getName()),
58 sprintf('Creation date: %s', $user->getCreatedAt()->format('Y-m-d H:i:s')),
3ef055ce 59 sprintf('Last login: %s', null !== $user->getLastLogin() ? $user->getLastLogin()->format('Y-m-d H:i:s') : 'never'),
d58199f3
NH
60 sprintf('2FA activated: %s', $user->isTwoFactorAuthentication() ? 'yes' : 'no'),
61 ]);
d143fa24
TC
62 }
63
64 /**
65 * Fetches a user from its username.
66 *
67 * @param string $username
68 *
69 * @return \Wallabag\UserBundle\Entity\User
70 */
71 private function getUser($username)
72 {
03ce43d4 73 return $this->getContainer()->get('wallabag_user.user_repository')->findOneByUserName($username);
d143fa24 74 }
d143fa24 75}