3 namespace Wallabag\CoreBundle\Command
;
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 Symfony\Component\Console\Style\SymfonyStyle
;
12 class ExportCommand
extends ContainerAwareCommand
14 protected function configure()
17 ->setName('wallabag:export')
18 ->setDescription('Export all entries for an user')
19 ->setHelp('This command helps you to export all entries for an user')
22 InputArgument
::REQUIRED
,
23 'User from which to export entries'
27 InputArgument
::OPTIONAL
,
28 'Path of the exported file'
33 protected function execute(InputInterface
$input, OutputInterface
$output)
35 $io = new SymfonyStyle($input, $output);
38 $user = $this->getContainer()->get('wallabag_user.user_repository')->findOneByUserName($input->getArgument('username'));
39 } catch (NoResultException
$e) {
40 $io->error(sprintf('User "%s" not found.', $input->getArgument('username')));
45 $entries = $this->getContainer()->get('wallabag_core.entry_repository')
46 ->getBuilderForAllByUser($user->getId())
50 $io->text(sprintf('Exporting <info>%d</info> entrie(s) for user <info>%s</info>...', count($entries), $user->getUserName()));
52 $filePath = $input->getArgument('filepath');
55 $filePath = $this->getContainer()->getParameter('kernel.project_dir') . '/' . sprintf('%s-export.json', $user->getUsername());
59 $data = $this->getContainer()->get('wallabag_core.helper.entries_export')
60 ->setEntries($entries)
64 file_put_contents($filePath, $data);
65 } catch (\InvalidArgumentException
$e) {
66 $io->error(sprintf('Error: "%s"', $e->getMessage()));
71 $io->success('Done.');