aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Command/ImportCommand.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ImportBundle/Command/ImportCommand.php')
-rw-r--r--src/Wallabag/ImportBundle/Command/ImportCommand.php17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php
index dfbfc2f7..20ecc6e1 100644
--- a/src/Wallabag/ImportBundle/Command/ImportCommand.php
+++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php
@@ -13,10 +13,12 @@ class ImportCommand extends ContainerAwareCommand
13 protected function configure() 13 protected function configure()
14 { 14 {
15 $this 15 $this
16 ->setName('wallabag:import-v1') 16 ->setName('wallabag:import')
17 ->setDescription('Import entries from a JSON export from a wallabag v1 instance') 17 ->setDescription('Import entries from a JSON export from a wallabag v1 instance')
18 ->addArgument('userId', InputArgument::REQUIRED, 'User ID to populate') 18 ->addArgument('userId', InputArgument::REQUIRED, 'User ID to populate')
19 ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file') 19 ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file')
20 ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: v1 or v2', 'v1')
21 ->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false)
20 ; 22 ;
21 } 23 }
22 24
@@ -24,6 +26,10 @@ class ImportCommand extends ContainerAwareCommand
24 { 26 {
25 $output->writeln('Start : '.(new \DateTime())->format('d-m-Y G:i:s').' ---'); 27 $output->writeln('Start : '.(new \DateTime())->format('d-m-Y G:i:s').' ---');
26 28
29 if (!file_exists($input->getArgument('filepath'))) {
30 throw new Exception(sprintf('File "%s" not found', $input->getArgument('filepath')));
31 }
32
27 $em = $this->getContainer()->get('doctrine')->getManager(); 33 $em = $this->getContainer()->get('doctrine')->getManager();
28 // Turning off doctrine default logs queries for saving memory 34 // Turning off doctrine default logs queries for saving memory
29 $em->getConnection()->getConfiguration()->setSQLLogger(null); 35 $em->getConnection()->getConfiguration()->setSQLLogger(null);
@@ -35,8 +41,15 @@ class ImportCommand extends ContainerAwareCommand
35 } 41 }
36 42
37 $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import'); 43 $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import');
44
45 if ('v2' === $input->getOption('importer')) {
46 $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v2.import');
47 }
48
49 $wallabag->setMarkAsRead($input->getOption('markAsRead'));
50 $wallabag->setUser($user);
51
38 $res = $wallabag 52 $res = $wallabag
39 ->setUser($user)
40 ->setFilepath($input->getArgument('filepath')) 53 ->setFilepath($input->getArgument('filepath'))
41 ->import(); 54 ->import();
42 55