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\InputInterface
;
9 use Symfony\Component\Console\Output\OutputInterface
;
11 class ImportCommand
extends ContainerAwareCommand
13 protected function configure()
16 ->setName('wallabag:import-v1')
17 ->setDescription('Import entries from a JSON export from a wallabag v1 instance')
18 ->addArgument('userId', InputArgument
::REQUIRED
, 'User ID to populate')
19 ->addArgument('filepath', InputArgument
::REQUIRED
, 'Path to the JSON file')
23 protected function execute(InputInterface
$input, OutputInterface
$output)
25 $output->writeln('Start : '.(new \
DateTime())->format('d-m-Y G:i:s').' ---');
27 $em = $this->getContainer()->get('doctrine')->getManager();
28 // Turning off doctrine default logs queries for saving memory
29 $em->getConnection()->getConfiguration()->setSQLLogger(null);
31 $user = $em->getRepository('WallabagUserBundle:User')->findOneById($input->getArgument('userId'));
33 if (!is_object($user)) {
34 throw new Exception(sprintf('User with id "%s" not found', $input->getArgument('userId')));
37 $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import');
40 ->setFilepath($input->getArgument('filepath'))
44 $summary = $wallabag->getSummary();
45 $output->writeln('<info>'.$summary['imported'].' imported</info>');
46 $output->writeln('<comment>'.$summary['skipped'].' already saved</comment>');
51 $output->writeln('End : '.(new \
DateTime())->format('d-m-Y G:i:s').' ---');