diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Command')
-rw-r--r-- | src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php | 99 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Command/InstallCommand.php | 5 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Command/ShowUserCommand.php | 3 |
3 files changed, 104 insertions, 3 deletions
diff --git a/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php b/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php new file mode 100644 index 00000000..8f2bff11 --- /dev/null +++ b/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php | |||
@@ -0,0 +1,99 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Command; | ||
4 | |||
5 | use Doctrine\ORM\NoResultException; | ||
6 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
7 | use Symfony\Component\Console\Input\InputArgument; | ||
8 | use Symfony\Component\Console\Input\InputInterface; | ||
9 | use Symfony\Component\Console\Output\OutputInterface; | ||
10 | use Wallabag\CoreBundle\Helper\UrlHasher; | ||
11 | use Wallabag\UserBundle\Entity\User; | ||
12 | |||
13 | class GenerateUrlHashesCommand extends ContainerAwareCommand | ||
14 | { | ||
15 | /** @var OutputInterface */ | ||
16 | protected $output; | ||
17 | |||
18 | protected function configure() | ||
19 | { | ||
20 | $this | ||
21 | ->setName('wallabag:generate-hashed-urls') | ||
22 | ->setDescription('Generates hashed urls for each entry') | ||
23 | ->setHelp('This command helps you to generates hashes of the url of each entry, to check through API if an URL is already saved') | ||
24 | ->addArgument('username', InputArgument::OPTIONAL, 'User to process entries'); | ||
25 | } | ||
26 | |||
27 | protected function execute(InputInterface $input, OutputInterface $output) | ||
28 | { | ||
29 | $this->output = $output; | ||
30 | |||
31 | $username = (string) $input->getArgument('username'); | ||
32 | |||
33 | if ($username) { | ||
34 | try { | ||
35 | $user = $this->getUser($username); | ||
36 | $this->generateHashedUrls($user); | ||
37 | } catch (NoResultException $e) { | ||
38 | $output->writeln(sprintf('<error>User "%s" not found.</error>', $username)); | ||
39 | |||
40 | return 1; | ||
41 | } | ||
42 | } else { | ||
43 | $users = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findAll(); | ||
44 | |||
45 | $output->writeln(sprintf('Generating hashed urls for "%d" users', \count($users))); | ||
46 | |||
47 | foreach ($users as $user) { | ||
48 | $output->writeln(sprintf('Processing user: %s', $user->getUsername())); | ||
49 | $this->generateHashedUrls($user); | ||
50 | } | ||
51 | $output->writeln('Finished generated hashed urls'); | ||
52 | } | ||
53 | |||
54 | return 0; | ||
55 | } | ||
56 | |||
57 | /** | ||
58 | * @param User $user | ||
59 | */ | ||
60 | private function generateHashedUrls(User $user) | ||
61 | { | ||
62 | $em = $this->getContainer()->get('doctrine.orm.entity_manager'); | ||
63 | $repo = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); | ||
64 | |||
65 | $entries = $repo->findByUser($user->getId()); | ||
66 | |||
67 | $i = 1; | ||
68 | foreach ($entries as $entry) { | ||
69 | $entry->setHashedUrl(UrlHasher::hashUrl($entry->getUrl())); | ||
70 | $em->persist($entry); | ||
71 | |||
72 | if (0 === ($i % 20)) { | ||
73 | $em->flush(); | ||
74 | } | ||
75 | ++$i; | ||
76 | } | ||
77 | |||
78 | $em->flush(); | ||
79 | |||
80 | $this->output->writeln(sprintf('Generated hashed urls for user: %s', $user->getUserName())); | ||
81 | } | ||
82 | |||
83 | /** | ||
84 | * Fetches a user from its username. | ||
85 | * | ||
86 | * @param string $username | ||
87 | * | ||
88 | * @return User | ||
89 | */ | ||
90 | private function getUser($username) | ||
91 | { | ||
92 | return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username); | ||
93 | } | ||
94 | |||
95 | private function getDoctrine() | ||
96 | { | ||
97 | return $this->getContainer()->get('doctrine'); | ||
98 | } | ||
99 | } | ||
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 3c76545c..c58ae2b5 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php | |||
@@ -94,8 +94,9 @@ class InstallCommand extends ContainerAwareCommand | |||
94 | $status = '<info>OK!</info>'; | 94 | $status = '<info>OK!</info>'; |
95 | $help = ''; | 95 | $help = ''; |
96 | 96 | ||
97 | $conn = $this->getContainer()->get('doctrine')->getManager()->getConnection(); | ||
98 | |||
97 | try { | 99 | try { |
98 | $conn = $this->getContainer()->get('doctrine')->getManager()->getConnection(); | ||
99 | $conn->connect(); | 100 | $conn->connect(); |
100 | } catch (\Exception $e) { | 101 | } catch (\Exception $e) { |
101 | if (false === strpos($e->getMessage(), 'Unknown database') | 102 | if (false === strpos($e->getMessage(), 'Unknown database') |
@@ -253,7 +254,7 @@ class InstallCommand extends ContainerAwareCommand | |||
253 | $question->setHidden(true); | 254 | $question->setHidden(true); |
254 | $user->setPlainPassword($this->io->askQuestion($question)); | 255 | $user->setPlainPassword($this->io->askQuestion($question)); |
255 | 256 | ||
256 | $user->setEmail($this->io->ask('Email', '')); | 257 | $user->setEmail($this->io->ask('Email', 'wallabag@wallabag.io')); |
257 | 258 | ||
258 | $user->setEnabled(true); | 259 | $user->setEnabled(true); |
259 | $user->addRole('ROLE_SUPER_ADMIN'); | 260 | $user->addRole('ROLE_SUPER_ADMIN'); |
diff --git a/src/Wallabag/CoreBundle/Command/ShowUserCommand.php b/src/Wallabag/CoreBundle/Command/ShowUserCommand.php index a0184267..c95efbf3 100644 --- a/src/Wallabag/CoreBundle/Command/ShowUserCommand.php +++ b/src/Wallabag/CoreBundle/Command/ShowUserCommand.php | |||
@@ -57,7 +57,8 @@ class ShowUserCommand extends ContainerAwareCommand | |||
57 | sprintf('Display name: %s', $user->getName()), | 57 | sprintf('Display name: %s', $user->getName()), |
58 | sprintf('Creation date: %s', $user->getCreatedAt()->format('Y-m-d H:i:s')), | 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'), | 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'), | 60 | sprintf('2FA (email) activated: %s', $user->isEmailTwoFactor() ? 'yes' : 'no'), |
61 | sprintf('2FA (OTP) activated: %s', $user->isGoogleAuthenticatorEnabled() ? 'yes' : 'no'), | ||
61 | ]); | 62 | ]); |
62 | } | 63 | } |
63 | 64 | ||