]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Controller/ImportController.php
First test on PocketImport
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / ImportController.php
CommitLineData
8c3c77c1
NL
1<?php
2
3namespace Wallabag\CoreBundle\Controller;
4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\Console\Input\ArrayInput;
8use Symfony\Component\Console\Output\NullOutput;
9use Symfony\Component\HttpFoundation\Request;
10use Wallabag\CoreBundle\Command\ImportCommand;
d275bdf4 11use Wallabag\CoreBundle\Form\Type\UploadImportType;
8c3c77c1
NL
12
13class ImportController extends Controller
14{
15 /**
16 * @param Request $request
17 *
18 * @Route("/import", name="import")
19 */
20 public function importAction(Request $request)
21 {
d275bdf4
NL
22 $importForm = $this->createForm(new UploadImportType());
23 $importForm->handleRequest($request);
24 $user = $this->getUser();
25 $importConfig = $this->container->getParameter('wallabag_core.import');
26
27 if ($importForm->isValid()) {
28 $file = $importForm->get('file')->getData();
29 $name = $user->getId().'.json';
30 $dir = __DIR__.'/../../../../web/uploads/import';
31
32 if (in_array($file->getMimeType(), $importConfig['allow_mimetypes']) && $file->move($dir, $name)) {
33 $command = new ImportCommand();
34 $command->setContainer($this->container);
35 $input = new ArrayInput(array('userId' => $user->getId()));
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 }
8c3c77c1
NL
57 }
58
d275bdf4
NL
59 return $this->render('WallabagCoreBundle:Import:index.html.twig', array(
60 'form' => array(
61 'import' => $importForm->createView(), ),
62 ));
8c3c77c1
NL
63 }
64}