From 6785f4aa749e381081b93e3db46424cc7475eab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 20 Jan 2016 14:37:01 +0100 Subject: [#1590] Add JSON import from wallabag v2 --- .../Controller/WallabagV2Controller.php | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php (limited to 'src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php') diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php new file mode 100644 index 00000000..2e6225f2 --- /dev/null +++ b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php @@ -0,0 +1,60 @@ +createForm(UploadImportType::class); + $form->handleRequest($request); + + $wallabag = $this->get('wallabag_import.wallabag_v2.import'); + + if ($form->isValid()) { + $file = $form->get('file')->getData(); + $name = $this->getUser()->getId().'.json'; + + if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { + $res = $wallabag + ->setUser($this->getUser()) + ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) + ->import(); + + $message = 'Import failed, please try again.'; + + if (true === $res) { + $summary = $wallabag->getSummary(); + $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.'; + + unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); + } + + $this->get('session')->getFlashBag()->add( + 'notice', + $message + ); + + return $this->redirect($this->generateUrl('homepage')); + } else { + $this->get('session')->getFlashBag()->add( + 'notice', + 'Error while processing import. Please verify your import file.' + ); + } + } + + return $this->render('WallabagImportBundle:WallabagV2:index.html.twig', [ + 'form' => $form->createView(), + 'import' => $wallabag, + ]); + } +} -- cgit v1.2.3