3 namespace Wallabag\ImportBundle\Controller
;
5 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
6 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
7 use Symfony\Component\HttpFoundation\Request
;
8 use Wallabag\ImportBundle\Form\Type\UploadImportType
;
10 class WallabagV1Controller
extends Controller
13 * @Route("/wallabag-v1", name="import_wallabag_v1")
15 public function indexAction(Request
$request)
17 $form = $this->createForm(UploadImportType
::class);
18 $form->handleRequest($request);
20 $wallabag = $this->get('wallabag_import.wallabag_v1.import');
22 if ($form->isValid()) {
23 $file = $form->get('file')->getData();
24 $name = $this->getUser()->getId().'.json';
26 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
28 ->setUser($this->getUser())
29 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
32 $message = 'Import failed, please try again.';
34 $summary = $wallabag->getSummary();
35 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.';
37 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
40 $this->get('session')->getFlashBag()->add(
45 return $this->redirect($this->generateUrl('homepage'));
47 $this->get('session')->getFlashBag()->add(
49 'Error while processing import. Please verify your import file.'
54 return $this->render('WallabagImportBundle:WallabagV1:index.html.twig', [
55 'form' => $form->createView(),
56 'import' => $wallabag,