aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Command
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Command')
-rw-r--r--src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php3
-rw-r--r--src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php96
-rw-r--r--src/Wallabag/CoreBundle/Command/InstallCommand.php19
-rw-r--r--src/Wallabag/CoreBundle/Command/ShowUserCommand.php6
4 files changed, 107 insertions, 17 deletions
diff --git a/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php b/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php
index 99170967..64b91520 100644
--- a/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php
+++ b/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php
@@ -63,9 +63,6 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
63 return 0; 63 return 0;
64 } 64 }
65 65
66 /**
67 * @param User $user
68 */
69 private function cleanDuplicates(User $user) 66 private function cleanDuplicates(User $user)
70 { 67 {
71 $em = $this->getContainer()->get('doctrine.orm.entity_manager'); 68 $em = $this->getContainer()->get('doctrine.orm.entity_manager');
diff --git a/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php b/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php
new file mode 100644
index 00000000..a0e9221e
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Command/GenerateUrlHashesCommand.php
@@ -0,0 +1,96 @@
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 Wallabag\CoreBundle\Helper\UrlHasher;
11use Wallabag\UserBundle\Entity\User;
12
13class 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 private function generateHashedUrls(User $user)
58 {
59 $em = $this->getContainer()->get('doctrine.orm.entity_manager');
60 $repo = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
61
62 $entries = $repo->findByUser($user->getId());
63
64 $i = 1;
65 foreach ($entries as $entry) {
66 $entry->setHashedUrl(UrlHasher::hashUrl($entry->getUrl()));
67 $em->persist($entry);
68
69 if (0 === ($i % 20)) {
70 $em->flush();
71 }
72 ++$i;
73 }
74
75 $em->flush();
76
77 $this->output->writeln(sprintf('Generated hashed urls for user: %s', $user->getUserName()));
78 }
79
80 /**
81 * Fetches a user from its username.
82 *
83 * @param string $username
84 *
85 * @return User
86 */
87 private function getUser($username)
88 {
89 return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username);
90 }
91
92 private function getDoctrine()
93 {
94 return $this->getContainer()->get('doctrine');
95 }
96}
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index 3c76545c..3aa332f1 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -2,7 +2,6 @@
2 2
3namespace Wallabag\CoreBundle\Command; 3namespace Wallabag\CoreBundle\Command;
4 4
5use Craue\ConfigBundle\Entity\Setting;
6use FOS\UserBundle\Event\UserEvent; 5use FOS\UserBundle\Event\UserEvent;
7use FOS\UserBundle\FOSUserEvents; 6use FOS\UserBundle\FOSUserEvents;
8use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 7use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
@@ -13,6 +12,7 @@ use Symfony\Component\Console\Output\BufferedOutput;
13use Symfony\Component\Console\Output\OutputInterface; 12use Symfony\Component\Console\Output\OutputInterface;
14use Symfony\Component\Console\Question\Question; 13use Symfony\Component\Console\Question\Question;
15use Symfony\Component\Console\Style\SymfonyStyle; 14use Symfony\Component\Console\Style\SymfonyStyle;
15use Wallabag\CoreBundle\Entity\InternalSetting;
16 16
17class InstallCommand extends ContainerAwareCommand 17class InstallCommand extends ContainerAwareCommand
18{ 18{
@@ -54,7 +54,7 @@ class InstallCommand extends ContainerAwareCommand
54 54
55 $this->io = new SymfonyStyle($input, $output); 55 $this->io = new SymfonyStyle($input, $output);
56 56
57 $this->io->title('Wallabag installer'); 57 $this->io->title('wallabag installer');
58 58
59 $this 59 $this
60 ->checkRequirements() 60 ->checkRequirements()
@@ -63,7 +63,7 @@ class InstallCommand extends ContainerAwareCommand
63 ->setupConfig() 63 ->setupConfig()
64 ; 64 ;
65 65
66 $this->io->success('Wallabag has been successfully installed.'); 66 $this->io->success('wallabag has been successfully installed.');
67 $this->io->success('You can now configure your web server, see https://doc.wallabag.org'); 67 $this->io->success('You can now configure your web server, see https://doc.wallabag.org');
68 } 68 }
69 69
@@ -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');
@@ -275,10 +276,10 @@ class InstallCommand extends ContainerAwareCommand
275 $em = $this->getContainer()->get('doctrine.orm.entity_manager'); 276 $em = $this->getContainer()->get('doctrine.orm.entity_manager');
276 277
277 // cleanup before insert new stuff 278 // cleanup before insert new stuff
278 $em->createQuery('DELETE FROM CraueConfigBundle:Setting')->execute(); 279 $em->createQuery('DELETE FROM WallabagCoreBundle:InternalSetting')->execute();
279 280
280 foreach ($this->getContainer()->getParameter('wallabag_core.default_internal_settings') as $setting) { 281 foreach ($this->getContainer()->getParameter('wallabag_core.default_internal_settings') as $setting) {
281 $newSetting = new Setting(); 282 $newSetting = new InternalSetting();
282 $newSetting->setName($setting['name']); 283 $newSetting->setName($setting['name']);
283 $newSetting->setValue($setting['value']); 284 $newSetting->setValue($setting['value']);
284 $newSetting->setSection($setting['section']); 285 $newSetting->setSection($setting['section']);
@@ -325,9 +326,7 @@ class InstallCommand extends ContainerAwareCommand
325 if (0 !== $exitCode) { 326 if (0 !== $exitCode) {
326 $this->getApplication()->setAutoExit(true); 327 $this->getApplication()->setAutoExit(true);
327 328
328 throw new \RuntimeException( 329 throw new \RuntimeException('The command "' . $command . "\" generates some errors: \n\n" . $output->fetch());
329 'The command "' . $command . "\" generates some errors: \n\n"
330 . $output->fetch());
331 } 330 }
332 331
333 return $this; 332 return $this;
diff --git a/src/Wallabag/CoreBundle/Command/ShowUserCommand.php b/src/Wallabag/CoreBundle/Command/ShowUserCommand.php
index a0184267..87bccf71 100644
--- a/src/Wallabag/CoreBundle/Command/ShowUserCommand.php
+++ b/src/Wallabag/CoreBundle/Command/ShowUserCommand.php
@@ -46,9 +46,6 @@ class ShowUserCommand extends ContainerAwareCommand
46 return 0; 46 return 0;
47 } 47 }
48 48
49 /**
50 * @param User $user
51 */
52 private function showUser(User $user) 49 private function showUser(User $user)
53 { 50 {
54 $this->io->listing([ 51 $this->io->listing([
@@ -57,7 +54,8 @@ class ShowUserCommand extends ContainerAwareCommand
57 sprintf('Display name: %s', $user->getName()), 54 sprintf('Display name: %s', $user->getName()),
58 sprintf('Creation date: %s', $user->getCreatedAt()->format('Y-m-d H:i:s')), 55 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'), 56 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'), 57 sprintf('2FA (email) activated: %s', $user->isEmailTwoFactor() ? 'yes' : 'no'),
58 sprintf('2FA (OTP) activated: %s', $user->isGoogleAuthenticatorEnabled() ? 'yes' : 'no'),
61 ]); 59 ]);
62 } 60 }
63 61