aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Command
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ImportBundle/Command')
-rw-r--r--src/Wallabag/ImportBundle/Command/ImportCommand.php26
-rw-r--r--src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php12
2 files changed, 23 insertions, 15 deletions
diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php
index 28d01715..99056c2c 100644
--- a/src/Wallabag/ImportBundle/Command/ImportCommand.php
+++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php
@@ -6,6 +6,7 @@ use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6use Symfony\Component\Config\Definition\Exception\Exception; 6use Symfony\Component\Config\Definition\Exception\Exception;
7use Symfony\Component\Console\Input\InputArgument; 7use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Input\InputInterface; 8use Symfony\Component\Console\Input\InputInterface;
9use Symfony\Component\Console\Input\InputOption;
9use Symfony\Component\Console\Output\OutputInterface; 10use Symfony\Component\Console\Output\OutputInterface;
10 11
11class ImportCommand extends ContainerAwareCommand 12class ImportCommand extends ContainerAwareCommand
@@ -15,16 +16,18 @@ class ImportCommand extends ContainerAwareCommand
15 $this 16 $this
16 ->setName('wallabag:import') 17 ->setName('wallabag:import')
17 ->setDescription('Import entries from a JSON export') 18 ->setDescription('Import entries from a JSON export')
18 ->addArgument('userId', InputArgument::REQUIRED, 'User ID to populate') 19 ->addArgument('username', InputArgument::REQUIRED, 'User to populate')
19 ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file') 20 ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file')
20 ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, readability, firefox or chrome', 'v1') 21 ->addOption('importer', null, InputOption::VALUE_OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, readability, firefox or chrome', 'v1')
21 ->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false) 22 ->addOption('markAsRead', null, InputOption::VALUE_OPTIONAL, 'Mark all entries as read', false)
23 ->addOption('useUserId', null, InputOption::VALUE_NONE, 'Use user id instead of username to find account')
24 ->addOption('disableContentUpdate', null, InputOption::VALUE_NONE, 'Disable fetching updated content from URL')
22 ; 25 ;
23 } 26 }
24 27
25 protected function execute(InputInterface $input, OutputInterface $output) 28 protected function execute(InputInterface $input, OutputInterface $output)
26 { 29 {
27 $output->writeln('Start : '.(new \DateTime())->format('d-m-Y G:i:s').' ---'); 30 $output->writeln('Start : ' . (new \DateTime())->format('d-m-Y G:i:s') . ' ---');
28 31
29 if (!file_exists($input->getArgument('filepath'))) { 32 if (!file_exists($input->getArgument('filepath'))) {
30 throw new Exception(sprintf('File "%s" not found', $input->getArgument('filepath'))); 33 throw new Exception(sprintf('File "%s" not found', $input->getArgument('filepath')));
@@ -34,10 +37,14 @@ class ImportCommand extends ContainerAwareCommand
34 // Turning off doctrine default logs queries for saving memory 37 // Turning off doctrine default logs queries for saving memory
35 $em->getConnection()->getConfiguration()->setSQLLogger(null); 38 $em->getConnection()->getConfiguration()->setSQLLogger(null);
36 39
37 $user = $em->getRepository('WallabagUserBundle:User')->findOneById($input->getArgument('userId')); 40 if ($input->getOption('useUserId')) {
41 $user = $em->getRepository('WallabagUserBundle:User')->findOneById($input->getArgument('username'));
42 } else {
43 $user = $em->getRepository('WallabagUserBundle:User')->findOneByUsername($input->getArgument('username'));
44 }
38 45
39 if (!is_object($user)) { 46 if (!is_object($user)) {
40 throw new Exception(sprintf('User with id "%s" not found', $input->getArgument('userId'))); 47 throw new Exception(sprintf('User "%s" not found', $input->getArgument('username')));
41 } 48 }
42 49
43 switch ($input->getOption('importer')) { 50 switch ($input->getOption('importer')) {
@@ -64,6 +71,7 @@ class ImportCommand extends ContainerAwareCommand
64 } 71 }
65 72
66 $import->setMarkAsRead($input->getOption('markAsRead')); 73 $import->setMarkAsRead($input->getOption('markAsRead'));
74 $import->setDisableContentUpdate($input->getOption('disableContentUpdate'));
67 $import->setUser($user); 75 $import->setUser($user);
68 76
69 $res = $import 77 $res = $import
@@ -72,12 +80,12 @@ class ImportCommand extends ContainerAwareCommand
72 80
73 if (true === $res) { 81 if (true === $res) {
74 $summary = $import->getSummary(); 82 $summary = $import->getSummary();
75 $output->writeln('<info>'.$summary['imported'].' imported</info>'); 83 $output->writeln('<info>' . $summary['imported'] . ' imported</info>');
76 $output->writeln('<comment>'.$summary['skipped'].' already saved</comment>'); 84 $output->writeln('<comment>' . $summary['skipped'] . ' already saved</comment>');
77 } 85 }
78 86
79 $em->clear(); 87 $em->clear();
80 88
81 $output->writeln('End : '.(new \DateTime())->format('d-m-Y G:i:s').' ---'); 89 $output->writeln('End : ' . (new \DateTime())->format('d-m-Y G:i:s') . ' ---');
82 } 90 }
83} 91}
diff --git a/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php b/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php
index 2d06af44..d94900ad 100644
--- a/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php
+++ b/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php
@@ -2,13 +2,13 @@
2 2
3namespace Wallabag\ImportBundle\Command; 3namespace Wallabag\ImportBundle\Command;
4 4
5use Simpleue\Worker\QueueWorker;
5use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 6use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6use Symfony\Component\Config\Definition\Exception\Exception; 7use Symfony\Component\Config\Definition\Exception\Exception;
7use Symfony\Component\Console\Input\InputArgument; 8use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Input\InputOption;
9use Symfony\Component\Console\Input\InputInterface; 9use Symfony\Component\Console\Input\InputInterface;
10use Symfony\Component\Console\Input\InputOption;
10use Symfony\Component\Console\Output\OutputInterface; 11use Symfony\Component\Console\Output\OutputInterface;
11use Simpleue\Worker\QueueWorker;
12 12
13class RedisWorkerCommand extends ContainerAwareCommand 13class RedisWorkerCommand extends ContainerAwareCommand
14{ 14{
@@ -24,18 +24,18 @@ class RedisWorkerCommand extends ContainerAwareCommand
24 24
25 protected function execute(InputInterface $input, OutputInterface $output) 25 protected function execute(InputInterface $input, OutputInterface $output)
26 { 26 {
27 $output->writeln('Worker started at: '.(new \DateTime())->format('d-m-Y G:i:s')); 27 $output->writeln('Worker started at: ' . (new \DateTime())->format('d-m-Y G:i:s'));
28 $output->writeln('Waiting for message ...'); 28 $output->writeln('Waiting for message ...');
29 29
30 $serviceName = $input->getArgument('serviceName'); 30 $serviceName = $input->getArgument('serviceName');
31 31
32 if (!$this->getContainer()->has('wallabag_import.queue.redis.'.$serviceName) || !$this->getContainer()->has('wallabag_import.consumer.redis.'.$serviceName)) { 32 if (!$this->getContainer()->has('wallabag_import.queue.redis.' . $serviceName) || !$this->getContainer()->has('wallabag_import.consumer.redis.' . $serviceName)) {
33 throw new Exception(sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName'))); 33 throw new Exception(sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName')));
34 } 34 }
35 35
36 $worker = new QueueWorker( 36 $worker = new QueueWorker(
37 $this->getContainer()->get('wallabag_import.queue.redis.'.$serviceName), 37 $this->getContainer()->get('wallabag_import.queue.redis.' . $serviceName),
38 $this->getContainer()->get('wallabag_import.consumer.redis.'.$serviceName), 38 $this->getContainer()->get('wallabag_import.consumer.redis.' . $serviceName),
39 (int) $input->getOption('maxIterations') 39 (int) $input->getOption('maxIterations')
40 ); 40 );
41 41