aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Command
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2015-09-30 15:10:46 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-01-02 23:24:17 +0100
commit8c3c77c1bd5c3763c127bfea52e908e77dc751b9 (patch)
treeb2e4dc1d22969748660da0fd7bd5fe0727081897 /src/Wallabag/CoreBundle/Command
parenta1bb1b3c2a0631ad41262ef92f6cce02c3d376bf (diff)
downloadwallabag-8c3c77c1bd5c3763c127bfea52e908e77dc751b9.tar.gz
wallabag-8c3c77c1bd5c3763c127bfea52e908e77dc751b9.tar.zst
wallabag-8c3c77c1bd5c3763c127bfea52e908e77dc751b9.zip
create controller to launch import command
Diffstat (limited to 'src/Wallabag/CoreBundle/Command')
-rw-r--r--src/Wallabag/CoreBundle/Command/ImportCommand.php19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/Wallabag/CoreBundle/Command/ImportCommand.php b/src/Wallabag/CoreBundle/Command/ImportCommand.php
index 4a174202..16c84229 100644
--- a/src/Wallabag/CoreBundle/Command/ImportCommand.php
+++ b/src/Wallabag/CoreBundle/Command/ImportCommand.php
@@ -3,6 +3,7 @@
3namespace Wallabag\CoreBundle\Command; 3namespace Wallabag\CoreBundle\Command;
4 4
5use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 5use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6use Symfony\Component\Config\Definition\Exception\Exception;
6use Symfony\Component\Console\Input\InputArgument; 7use Symfony\Component\Console\Input\InputArgument;
7use Symfony\Component\Console\Input\InputInterface; 8use Symfony\Component\Console\Input\InputInterface;
8use Symfony\Component\Console\Output\OutputInterface; 9use Symfony\Component\Console\Output\OutputInterface;
@@ -15,7 +16,7 @@ class ImportCommand extends ContainerAwareCommand
15 protected function configure() 16 protected function configure()
16 { 17 {
17 $this 18 $this
18 ->setName('import:json') 19 ->setName('wallabag:import')
19 ->setDescription('Import entries from JSON file') 20 ->setDescription('Import entries from JSON file')
20 ->addArgument( 21 ->addArgument(
21 'userId', 22 'userId',
@@ -38,8 +39,6 @@ class ImportCommand extends ContainerAwareCommand
38 39
39 protected function import(InputInterface $input, OutputInterface $output) 40 protected function import(InputInterface $input, OutputInterface $output)
40 { 41 {
41 $userId = $input->getArgument('userId');
42
43 // Getting php array of data from CSV 42 // Getting php array of data from CSV
44 $data = $this->get($input, $output); 43 $data = $this->get($input, $output);
45 44
@@ -52,12 +51,16 @@ class ImportCommand extends ContainerAwareCommand
52 $batchSize = 20; 51 $batchSize = 20;
53 $i = 1; 52 $i = 1;
54 53
54 $user = $em->getRepository('WallabagCoreBundle:User')
55 ->findOneById($input->getArgument('userId'));
56
57 if (!is_object($user)) {
58 throw new Exception('User not found');
59 }
60
55 $progress = new ProgressBar($output, $size); 61 $progress = new ProgressBar($output, $size);
56 $progress->start(); 62 $progress->start();
57 63
58 $user = $em->getRepository('WallabagCoreBundle:User')
59 ->findOneById($userId);
60
61 foreach ($data as $object) { 64 foreach ($data as $object) {
62 $array = (array) $object; 65 $array = (array) $object;
63 $entry = $em->getRepository('WallabagCoreBundle:Entry') 66 $entry = $em->getRepository('WallabagCoreBundle:Entry')
@@ -112,8 +115,8 @@ class ImportCommand extends ContainerAwareCommand
112 115
113 protected function get(InputInterface $input, OutputInterface $output) 116 protected function get(InputInterface $input, OutputInterface $output)
114 { 117 {
115 $fileName = 'web/uploads/import/import.json'; 118 $filename = __DIR__.'/../../../../web/uploads/import/'.$input->getArgument('userId').'.json';
116 $data = $this->convert($fileName); 119 $data = $this->convert($filename);
117 120
118 return $data; 121 return $data;
119 } 122 }