3 namespace Wallabag\CoreBundle\Controller
;
5 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
6 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
7 use Symfony\Component\Console\Input\ArrayInput
;
8 use Symfony\Component\Console\Output\NullOutput
;
9 use Symfony\Component\HttpFoundation\Request
;
10 use Wallabag\CoreBundle\Command\ImportCommand
;
11 use Wallabag\CoreBundle\Form\Type\UploadImportType
;
13 class ImportController
extends Controller
16 * @param Request $request
18 * @Route("/import", name="import")
20 public function importAction(Request
$request)
22 $importForm = $this->createForm(new UploadImportType());
23 $importForm->handleRequest($request);
24 $user = $this->getUser();
25 $importConfig = $this->container
->getParameter('wallabag_core.import');
27 if ($importForm->isValid()) {
28 $file = $importForm->get('file')->getData();
29 $name = $user->getId().'.json';
30 $dir = __DIR__
.'/../../../../web/uploads/import';
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());
39 $this->get('session')->getFlashBag()->add(
44 $this->get('session')->getFlashBag()->add(
50 return $this->redirect('/');
52 $this->get('session')->getFlashBag()->add(
54 'Error while processing import. Please verify your import file.'
59 return $this->render('WallabagCoreBundle:Import:index.html.twig', array(
61 'import' => $importForm->createView(), ),