aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/ImportController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/ImportController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ImportController.php56
1 files changed, 40 insertions, 16 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ImportController.php b/src/Wallabag/CoreBundle/Controller/ImportController.php
index 53211eec..33087710 100644
--- a/src/Wallabag/CoreBundle/Controller/ImportController.php
+++ b/src/Wallabag/CoreBundle/Controller/ImportController.php
@@ -8,6 +8,7 @@ use Symfony\Component\Console\Input\ArrayInput;
8use Symfony\Component\Console\Output\NullOutput; 8use Symfony\Component\Console\Output\NullOutput;
9use Symfony\Component\HttpFoundation\Request; 9use Symfony\Component\HttpFoundation\Request;
10use Wallabag\CoreBundle\Command\ImportCommand; 10use Wallabag\CoreBundle\Command\ImportCommand;
11use Wallabag\CoreBundle\Form\Type\UploadImportType;
11 12
12class ImportController extends Controller 13class ImportController extends Controller
13{ 14{
@@ -18,23 +19,46 @@ class ImportController extends Controller
18 */ 19 */
19 public function importAction(Request $request) 20 public function importAction(Request $request)
20 { 21 {
21 $command = new ImportCommand(); 22 $importForm = $this->createForm(new UploadImportType());
22 $command->setContainer($this->container); 23 $importForm->handleRequest($request);
23 $input = new ArrayInput(array('userId' => $this->getUser()->getId())); 24 $user = $this->getUser();
24 $return = $command->run($input, new NullOutput()); 25 $importConfig = $this->container->getParameter('wallabag_core.import');
25 26
26 if ($return == 0) { 27 if ($importForm->isValid()) {
27 $this->get('session')->getFlashBag()->add( 28 $file = $importForm->get('file')->getData();
28 'notice', 29 $name = $user->getId().'.json';
29 'Import successful' 30 $dir = __DIR__.'/../../../../web/uploads/import';
30 ); 31
31 } else { 32 if (in_array($file->getMimeType(), $importConfig['allow_mimetypes']) && $file->move($dir, $name)) {
32 $this->get('session')->getFlashBag()->add( 33 $command = new ImportCommand();
33 'warning', 34 $command->setContainer($this->container);
34 'Import failed' 35 $input = new ArrayInput(array('userId' => $user->getId()));
35 ); 36 $return = $command->run($input, new NullOutput());
37
38 if ($return == 0) {
39 $this->get('session')->getFlashBag()->add(
40 'notice',
41 'Import successful'
42 );
43 } else {
44 $this->get('session')->getFlashBag()->add(
45 'notice',
46 'Import failed'
47 );
48 }
49
50 return $this->redirect('/');
51 } else {
52 $this->get('session')->getFlashBag()->add(
53 'notice',
54 'Error while processing import. Please verify your import file.'
55 );
56 }
36 } 57 }
37 58
38 return $this->redirect('/'); 59 return $this->render('WallabagCoreBundle:Import:index.html.twig', array(
60 'form' => array(
61 'import' => $importForm->createView(), ),
62 ));
39 } 63 }
40} 64}