3 namespace Wallabag\ImportBundle\Command
;
5 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
;
6 use Symfony\Component\Config\Definition\Exception\Exception
;
7 use Symfony\Component\Console\Input\InputArgument
;
8 use Symfony\Component\Console\Input\InputOption
;
9 use Symfony\Component\Console\Input\InputInterface
;
10 use Symfony\Component\Console\Output\OutputInterface
;
12 class ImportCommand
extends ContainerAwareCommand
14 protected function configure()
17 ->setName('wallabag:import')
18 ->setDescription('Import entries from a JSON export')
19 ->addArgument('username', InputArgument
::REQUIRED
, 'User to populate')
20 ->addArgument('filepath', InputArgument
::REQUIRED
, 'Path to the JSON file')
21 ->addOption('importer', null, InputArgument
::OPTIONAL
, 'The importer to use: v1, v2, instapaper, pinboard, readability, firefox or chrome', 'v1')
22 ->addOption('markAsRead', null, InputArgument
::OPTIONAL
, 'Mark all entries as read', false)
23 ->addOption('disableContentUpdate', null, InputOption
::VALUE_NONE
, 'Disable fetching updated content from URL')
27 protected function execute(InputInterface
$input, OutputInterface
$output)
29 $output->writeln('Start : '.(new \
DateTime())->format('d-m-Y G:i:s').' ---');
31 if (!file_exists($input->getArgument('filepath'))) {
32 throw new Exception(sprintf('File "%s" not found', $input->getArgument('filepath')));
35 $em = $this->getContainer()->get('doctrine')->getManager();
36 // Turning off doctrine default logs queries for saving memory
37 $em->getConnection()->getConfiguration()->setSQLLogger(null);
39 if ($input->getOption('useUserId')) {
40 $user = $em->getRepository('WallabagUserBundle:User')->findOneById($input->getArgument('username'));
42 $user = $em->getRepository('WallabagUserBundle:User')->findOneByUsername($input->getArgument('username'));
45 if (!is_object($user)) {
46 throw new Exception(sprintf('User "%s" not found', $input->getArgument('username')));
49 switch ($input->getOption('importer')) {
51 $import = $this->getContainer()->get('wallabag_import.wallabag_v2.import');
54 $import = $this->getContainer()->get('wallabag_import.firefox.import');
57 $import = $this->getContainer()->get('wallabag_import.chrome.import');
60 $import = $this->getContainer()->get('wallabag_import.readability.import');
63 $import = $this->getContainer()->get('wallabag_import.instapaper.import');
66 $import = $this->getContainer()->get('wallabag_import.pinboard.import');
69 $import = $this->getContainer()->get('wallabag_import.wallabag_v1.import');
72 $import->setMarkAsRead($input->getOption('markAsRead'));
73 $import->setDisableContentUpdate($input->getOption('disableContentUpdate'));
74 $import->setUser($user);
77 ->setFilepath($input->getArgument('filepath'))
81 $summary = $import->getSummary();
82 $output->writeln('<info>'.$summary['imported'].' imported</info>');
83 $output->writeln('<comment>'.$summary['skipped'].' already saved</comment>');
88 $output->writeln('End : '.(new \
DateTime())->format('d-m-Y G:i:s').' ---');