aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2017-01-24 20:42:02 +0100
committerThomas Citharel <tcit@tcit.fr>2017-01-24 20:42:02 +0100
commit3b0380f049d408f0721e28218170c562153a56e5 (patch)
treeabab8726f1c71ddc8a0d1d35f1123dd219d1245d /src
parenta607b7a9c0870bcdfb4b4e7920d20b5ed39f14fe (diff)
downloadwallabag-3b0380f049d408f0721e28218170c562153a56e5.tar.gz
wallabag-3b0380f049d408f0721e28218170c562153a56e5.tar.zst
wallabag-3b0380f049d408f0721e28218170c562153a56e5.zip
Fix phpcs and tests
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Command/ExportCommand.php23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/Wallabag/CoreBundle/Command/ExportCommand.php b/src/Wallabag/CoreBundle/Command/ExportCommand.php
index 0cf5de48..e3d3b399 100644
--- a/src/Wallabag/CoreBundle/Command/ExportCommand.php
+++ b/src/Wallabag/CoreBundle/Command/ExportCommand.php
@@ -7,7 +7,6 @@ use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7use Symfony\Component\Console\Input\InputArgument; 7use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Input\InputInterface; 8use Symfony\Component\Console\Input\InputInterface;
9use Symfony\Component\Console\Output\OutputInterface; 9use Symfony\Component\Console\Output\OutputInterface;
10use Symfony\Component\Console\Output\StreamOutput;
11 10
12class ExportCommand extends ContainerAwareCommand 11class ExportCommand extends ContainerAwareCommand
13{ 12{
@@ -33,11 +32,13 @@ class ExportCommand extends ContainerAwareCommand
33 protected function execute(InputInterface $input, OutputInterface $output) 32 protected function execute(InputInterface $input, OutputInterface $output)
34 { 33 {
35 try { 34 try {
36 $user = $this->getUser($input->getArgument('username')); 35 $user = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($input->getArgument('username'));
37 } catch (NoResultException $e) { 36 } catch (NoResultException $e) {
38 $output->writeln(sprintf('<error>User "%s" not found.</error>', $input->getArgument('username'))); 37 $output->writeln(sprintf('<error>User "%s" not found.</error>', $input->getArgument('username')));
38
39 return 1; 39 return 1;
40 } 40 }
41
41 $entries = $this->getDoctrine() 42 $entries = $this->getDoctrine()
42 ->getRepository('WallabagCoreBundle:Entry') 43 ->getRepository('WallabagCoreBundle:Entry')
43 ->getBuilderForAllByUser($user->getId()) 44 ->getBuilderForAllByUser($user->getId())
@@ -47,9 +48,11 @@ class ExportCommand extends ContainerAwareCommand
47 $output->write(sprintf('Exporting %d entrie(s) for user « <comment>%s</comment> »... ', count($entries), $user->getUserName())); 48 $output->write(sprintf('Exporting %d entrie(s) for user « <comment>%s</comment> »... ', count($entries), $user->getUserName()));
48 49
49 $filePath = $input->getArgument('filepath'); 50 $filePath = $input->getArgument('filepath');
51
50 if (!$filePath) { 52 if (!$filePath) {
51 $filePath = $this->getContainer()->getParameter('kernel.root_dir') . '/../' . sprintf('%s-export', $user->getUsername()); 53 $filePath = $this->getContainer()->getParameter('kernel.root_dir').'/../'.sprintf('%s-export.json', $user->getUsername());
52 } 54 }
55
53 try { 56 try {
54 $data = $this->getContainer()->get('wallabag_core.helper.entries_export') 57 $data = $this->getContainer()->get('wallabag_core.helper.entries_export')
55 ->setEntries($entries) 58 ->setEntries($entries)
@@ -58,21 +61,13 @@ class ExportCommand extends ContainerAwareCommand
58 file_put_contents($filePath, $data); 61 file_put_contents($filePath, $data);
59 } catch (\InvalidArgumentException $e) { 62 } catch (\InvalidArgumentException $e) {
60 $output->writeln(sprintf('<error>Error: "%s"</error>', $e->getMessage())); 63 $output->writeln(sprintf('<error>Error: "%s"</error>', $e->getMessage()));
64
65 return 1;
61 } 66 }
62 67
63 $output->writeln('<info>Done.</info>'); 68 $output->writeln('<info>Done.</info>');
64 }
65 69
66 /** 70 return 0;
67 * Fetches a user from its username.
68 *
69 * @param string $username
70 *
71 * @return \Wallabag\UserBundle\Entity\User
72 */
73 private function getUser($username)
74 {
75 return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username);
76 } 71 }
77 72
78 private function getDoctrine() 73 private function getDoctrine()