diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Command/ExportCommand.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Command/ExportCommand.php | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/Wallabag/CoreBundle/Command/ExportCommand.php b/src/Wallabag/CoreBundle/Command/ExportCommand.php index e3d3b399..75e9ad91 100644 --- a/src/Wallabag/CoreBundle/Command/ExportCommand.php +++ b/src/Wallabag/CoreBundle/Command/ExportCommand.php | |||
@@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | |||
7 | use Symfony\Component\Console\Input\InputArgument; | 7 | use Symfony\Component\Console\Input\InputArgument; |
8 | use Symfony\Component\Console\Input\InputInterface; | 8 | use Symfony\Component\Console\Input\InputInterface; |
9 | use Symfony\Component\Console\Output\OutputInterface; | 9 | use Symfony\Component\Console\Output\OutputInterface; |
10 | use Symfony\Component\Console\Style\SymfonyStyle; | ||
10 | 11 | ||
11 | class ExportCommand extends ContainerAwareCommand | 12 | class ExportCommand extends ContainerAwareCommand |
12 | { | 13 | { |
@@ -31,47 +32,44 @@ class ExportCommand extends ContainerAwareCommand | |||
31 | 32 | ||
32 | protected function execute(InputInterface $input, OutputInterface $output) | 33 | protected function execute(InputInterface $input, OutputInterface $output) |
33 | { | 34 | { |
35 | $io = new SymfonyStyle($input, $output); | ||
36 | |||
34 | try { | 37 | try { |
35 | $user = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($input->getArgument('username')); | 38 | $user = $this->getContainer()->get('wallabag_user.user_repository')->findOneByUserName($input->getArgument('username')); |
36 | } catch (NoResultException $e) { | 39 | } catch (NoResultException $e) { |
37 | $output->writeln(sprintf('<error>User "%s" not found.</error>', $input->getArgument('username'))); | 40 | $io->error(sprintf('User "%s" not found.', $input->getArgument('username'))); |
38 | 41 | ||
39 | return 1; | 42 | return 1; |
40 | } | 43 | } |
41 | 44 | ||
42 | $entries = $this->getDoctrine() | 45 | $entries = $this->getContainer()->get('wallabag_core.entry_repository') |
43 | ->getRepository('WallabagCoreBundle:Entry') | ||
44 | ->getBuilderForAllByUser($user->getId()) | 46 | ->getBuilderForAllByUser($user->getId()) |
45 | ->getQuery() | 47 | ->getQuery() |
46 | ->getResult(); | 48 | ->getResult(); |
47 | 49 | ||
48 | $output->write(sprintf('Exporting %d entrie(s) for user « <comment>%s</comment> »... ', count($entries), $user->getUserName())); | 50 | $io->text(sprintf('Exporting <info>%d</info> entrie(s) for user <info>%s</info>...', count($entries), $user->getUserName())); |
49 | 51 | ||
50 | $filePath = $input->getArgument('filepath'); | 52 | $filePath = $input->getArgument('filepath'); |
51 | 53 | ||
52 | if (!$filePath) { | 54 | if (!$filePath) { |
53 | $filePath = $this->getContainer()->getParameter('kernel.root_dir').'/../'.sprintf('%s-export.json', $user->getUsername()); | 55 | $filePath = $this->getContainer()->getParameter('kernel.project_dir') . '/' . sprintf('%s-export.json', $user->getUsername()); |
54 | } | 56 | } |
55 | 57 | ||
56 | try { | 58 | try { |
57 | $data = $this->getContainer()->get('wallabag_core.helper.entries_export') | 59 | $data = $this->getContainer()->get('wallabag_core.helper.entries_export') |
58 | ->setEntries($entries) | 60 | ->setEntries($entries) |
59 | ->updateTitle('All') | 61 | ->updateTitle('All') |
62 | ->updateAuthor('All') | ||
60 | ->exportJsonData(); | 63 | ->exportJsonData(); |
61 | file_put_contents($filePath, $data); | 64 | file_put_contents($filePath, $data); |
62 | } catch (\InvalidArgumentException $e) { | 65 | } catch (\InvalidArgumentException $e) { |
63 | $output->writeln(sprintf('<error>Error: "%s"</error>', $e->getMessage())); | 66 | $io->error(sprintf('Error: "%s"', $e->getMessage())); |
64 | 67 | ||
65 | return 1; | 68 | return 1; |
66 | } | 69 | } |
67 | 70 | ||
68 | $output->writeln('<info>Done.</info>'); | 71 | $io->success('Done.'); |
69 | 72 | ||
70 | return 0; | 73 | return 0; |
71 | } | 74 | } |
72 | |||
73 | private function getDoctrine() | ||
74 | { | ||
75 | return $this->getContainer()->get('doctrine'); | ||
76 | } | ||
77 | } | 75 | } |