3 namespace Wallabag\ImportBundle\Controller
;
5 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
6 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
7 use Symfony\Component\Console\Input\ArrayInput
;
8 use Symfony\Component\Console\Output\NullOutput
;
9 use Symfony\Component\HttpFoundation\Request
;
10 use Wallabag\ImportBundle\Command\ImportCommand
;
11 use Wallabag\ImportBundle\Form\Type\UploadImportType
;
13 class ImportController
extends Controller
16 * @Route("/import", name="import")
18 public function importAction(Request
$request)
20 $importForm = $this->createForm(new UploadImportType());
21 $importForm->handleRequest($request);
22 $user = $this->getUser();
24 if ($importForm->isValid()) {
25 $file = $importForm->get('file')->getData();
26 $name = $user->getId().'.json';
27 $dir = __DIR__
.'/../../../../web/uploads/import';
29 if (in_array($file->getMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($dir, $name)) {
30 $command = new ImportCommand();
31 $command->setContainer($this->container
);
32 $input = new ArrayInput(array('userId' => $user->getId()));
33 $return = $command->run($input, new NullOutput());
36 $this->get('session')->getFlashBag()->add(
41 $this->get('session')->getFlashBag()->add(
47 return $this->redirect('/');
49 $this->get('session')->getFlashBag()->add(
51 'Error while processing import. Please verify your import file.'
56 return $this->render('WallabagImportBundle:Import:index.html.twig', array(
58 'import' => $importForm->createView(), ),