diff options
Diffstat (limited to 'src/Wallabag/ImportBundle/Command')
-rw-r--r-- | src/Wallabag/ImportBundle/Command/ImportCommand.php | 29 | ||||
-rw-r--r-- | src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php | 44 |
2 files changed, 70 insertions, 3 deletions
diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php index dfbfc2f7..1df38295 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: wallabag v1, v2, firefox or chrome', '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); |
@@ -34,9 +40,26 @@ class ImportCommand extends ContainerAwareCommand | |||
34 | throw new Exception(sprintf('User with id "%s" not found', $input->getArgument('userId'))); | 40 | throw new Exception(sprintf('User with id "%s" not found', $input->getArgument('userId'))); |
35 | } | 41 | } |
36 | 42 | ||
37 | $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import'); | 43 | switch ($input->getOption('importer')) { |
44 | case 'v2': | ||
45 | $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v2.import'); | ||
46 | break; | ||
47 | case 'firefox': | ||
48 | $wallabag = $this->getContainer()->get('wallabag_import.firefox.import'); | ||
49 | break; | ||
50 | case 'chrome': | ||
51 | $wallabag = $this->getContainer()->get('wallabag_import.chrome.import'); | ||
52 | break; | ||
53 | case 'v1': | ||
54 | default: | ||
55 | $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import'); | ||
56 | break; | ||
57 | } | ||
58 | |||
59 | $wallabag->setMarkAsRead($input->getOption('markAsRead')); | ||
60 | $wallabag->setUser($user); | ||
61 | |||
38 | $res = $wallabag | 62 | $res = $wallabag |
39 | ->setUser($user) | ||
40 | ->setFilepath($input->getArgument('filepath')) | 63 | ->setFilepath($input->getArgument('filepath')) |
41 | ->import(); | 64 | ->import(); |
42 | 65 | ||
diff --git a/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php b/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php new file mode 100644 index 00000000..c2c11f11 --- /dev/null +++ b/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php | |||
@@ -0,0 +1,44 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ImportBundle\Command; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
6 | use Symfony\Component\Config\Definition\Exception\Exception; | ||
7 | use Symfony\Component\Console\Input\InputArgument; | ||
8 | use Symfony\Component\Console\Input\InputOption; | ||
9 | use Symfony\Component\Console\Input\InputInterface; | ||
10 | use Symfony\Component\Console\Output\OutputInterface; | ||
11 | use Simpleue\Worker\QueueWorker; | ||
12 | |||
13 | class RedisWorkerCommand extends ContainerAwareCommand | ||
14 | { | ||
15 | protected function configure() | ||
16 | { | ||
17 | $this | ||
18 | ->setName('wallabag:import:redis-worker') | ||
19 | ->setDescription('Launch Redis worker') | ||
20 | ->addArgument('serviceName', InputArgument::REQUIRED, 'Service to use: wallabag_v1, wallabag_v2, pocket, readability, firefox, chrome or instapaper') | ||
21 | ->addOption('maxIterations', '', InputOption::VALUE_OPTIONAL, 'Number of iterations before stoping', false) | ||
22 | ; | ||
23 | } | ||
24 | |||
25 | protected function execute(InputInterface $input, OutputInterface $output) | ||
26 | { | ||
27 | $output->writeln('Worker started at: '.(new \DateTime())->format('d-m-Y G:i:s')); | ||
28 | $output->writeln('Waiting for message ...'); | ||
29 | |||
30 | $serviceName = $input->getArgument('serviceName'); | ||
31 | |||
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'))); | ||
34 | } | ||
35 | |||
36 | $worker = new QueueWorker( | ||
37 | $this->getContainer()->get('wallabag_import.queue.redis.'.$serviceName), | ||
38 | $this->getContainer()->get('wallabag_import.consumer.redis.'.$serviceName), | ||
39 | $input->getOption('maxIterations') | ||
40 | ); | ||
41 | |||
42 | $worker->start(); | ||
43 | } | ||
44 | } | ||