diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@smile.fr> | 2015-10-22 16:57:56 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-01-02 23:24:17 +0100 |
commit | d275bdf4d36f90ff61f1e6a714c9ef64d210596f (patch) | |
tree | 1fb9cd40f2d75e1a39cec2636d3caa510045fc48 /src/Wallabag/CoreBundle/Controller | |
parent | 8c3c77c1bd5c3763c127bfea52e908e77dc751b9 (diff) | |
download | wallabag-d275bdf4d36f90ff61f1e6a714c9ef64d210596f.tar.gz wallabag-d275bdf4d36f90ff61f1e6a714c9ef64d210596f.tar.zst wallabag-d275bdf4d36f90ff61f1e6a714c9ef64d210596f.zip |
form to upload file
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/ImportController.php | 56 |
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; | |||
8 | use Symfony\Component\Console\Output\NullOutput; | 8 | use Symfony\Component\Console\Output\NullOutput; |
9 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
10 | use Wallabag\CoreBundle\Command\ImportCommand; | 10 | use Wallabag\CoreBundle\Command\ImportCommand; |
11 | use Wallabag\CoreBundle\Form\Type\UploadImportType; | ||
11 | 12 | ||
12 | class ImportController extends Controller | 13 | class 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 | } |