]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ImportBundle/Command/ImportCommand.php
Merge pull request #2301 from wallabag/fix-rss-feeds
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Command / ImportCommand.php
index dfbfc2f792832739555918b806e016fedf42e406..20ecc6e1893a09292df62209037e6f9e9ed709a4 100644 (file)
@@ -13,10 +13,12 @@ class ImportCommand extends ContainerAwareCommand
     protected function configure()
     {
         $this
-            ->setName('wallabag:import-v1')
+            ->setName('wallabag:import')
             ->setDescription('Import entries from a JSON export from a wallabag v1 instance')
             ->addArgument('userId', InputArgument::REQUIRED, 'User ID to populate')
             ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file')
+            ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: v1 or v2', 'v1')
+            ->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false)
         ;
     }
 
@@ -24,6 +26,10 @@ class ImportCommand extends ContainerAwareCommand
     {
         $output->writeln('Start : '.(new \DateTime())->format('d-m-Y G:i:s').' ---');
 
+        if (!file_exists($input->getArgument('filepath'))) {
+            throw new Exception(sprintf('File "%s" not found', $input->getArgument('filepath')));
+        }
+
         $em = $this->getContainer()->get('doctrine')->getManager();
         // Turning off doctrine default logs queries for saving memory
         $em->getConnection()->getConfiguration()->setSQLLogger(null);
@@ -35,8 +41,15 @@ class ImportCommand extends ContainerAwareCommand
         }
 
         $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import');
+
+        if ('v2' === $input->getOption('importer')) {
+            $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v2.import');
+        }
+
+        $wallabag->setMarkAsRead($input->getOption('markAsRead'));
+        $wallabag->setUser($user);
+
         $res = $wallabag
-            ->setUser($user)
             ->setFilepath($input->getArgument('filepath'))
             ->import();