X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FImportBundle%2FCommand%2FImportCommand.php;h=20ecc6e1893a09292df62209037e6f9e9ed709a4;hb=637aa17e6b52dd8021854a809053560a27caca72;hp=dfbfc2f792832739555918b806e016fedf42e406;hpb=39643c6b76d92d509b1af0228b6379d7fdce8a1c;p=github%2Fwallabag%2Fwallabag.git 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 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();