]> git.immae.eu Git - github/wallabag/wallabag.git/blame_incremental - src/Wallabag/CoreBundle/Command/ShowUserCommand.php
Fix image downloading on null image path
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Command / ShowUserCommand.php
... / ...
CommitLineData
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;
10use Symfony\Component\Console\Style\SymfonyStyle;
11use Wallabag\UserBundle\Entity\User;
12
13class ShowUserCommand extends ContainerAwareCommand
14{
15 /** @var SymfonyStyle */
16 protected $io;
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 {
33 $this->io = new SymfonyStyle($input, $output);
34
35 $username = $input->getArgument('username');
36
37 try {
38 $user = $this->getUser($username);
39 $this->showUser($user);
40 } catch (NoResultException $e) {
41 $this->io->error(sprintf('User "%s" not found.', $username));
42
43 return 1;
44 }
45
46 return 0;
47 }
48
49 /**
50 * @param User $user
51 */
52 private function showUser(User $user)
53 {
54 $this->io->listing([
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')),
59 sprintf('Last login: %s', null !== $user->getLastLogin() ? $user->getLastLogin()->format('Y-m-d H:i:s') : 'never'),
60 sprintf('2FA activated: %s', $user->isTwoFactorAuthentication() ? 'yes' : 'no'),
61 ]);
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 {
73 return $this->getContainer()->get('wallabag_user.user_repository')->findOneByUserName($username);
74 }
75}