]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/ImportBundle/Command/ImportCommand.php
Rewrote Wallabag v1 import
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Command / ImportCommand.php
CommitLineData
56ea1de9
NL
1<?php
2
77a7752a 3namespace Wallabag\ImportBundle\Command;
56ea1de9
NL
4
5use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
8c3c77c1 6use Symfony\Component\Config\Definition\Exception\Exception;
a1bb1b3c 7use Symfony\Component\Console\Input\InputArgument;
56ea1de9
NL
8use Symfony\Component\Console\Input\InputInterface;
9use Symfony\Component\Console\Output\OutputInterface;
56ea1de9
NL
10
11class ImportCommand extends ContainerAwareCommand
12{
13 protected function configure()
14 {
15 $this
b1d05721
JB
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')
20 ;
56ea1de9
NL
21 }
22
23 protected function execute(InputInterface $input, OutputInterface $output)
24 {
b1d05721 25 $output->writeln('Start : '.(new \DateTime())->format('d-m-Y G:i:s').' ---');
56ea1de9
NL
26
27 $em = $this->getContainer()->get('doctrine')->getManager();
28 // Turning off doctrine default logs queries for saving memory
29 $em->getConnection()->getConfiguration()->setSQLLogger(null);
30
b1d05721 31 $user = $em->getRepository('WallabagUserBundle:User')->findOneById($input->getArgument('userId'));
8c3c77c1
NL
32
33 if (!is_object($user)) {
b1d05721 34 throw new Exception(sprintf('User with id "%s" not found', $input->getArgument('userId')));
8c3c77c1
NL
35 }
36
b1d05721
JB
37 $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import');
38 $res = $wallabag
39 ->setUser($user)
40 ->setFilepath($input->getArgument('filepath'))
41 ->import();
56ea1de9 42
b1d05721
JB
43 if (true === $res) {
44 $summary = $wallabag->getSummary();
45 $output->writeln('<info>'.$summary['imported'].' imported</info>');
46 $output->writeln('<comment>'.$summary['skipped'].' already saved</comment>');
56ea1de9
NL
47 }
48
56ea1de9 49 $em->clear();
56ea1de9 50
b1d05721 51 $output->writeln('End : '.(new \DateTime())->format('d-m-Y G:i:s').' ---');
56ea1de9
NL
52 }
53}