aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@smile.fr>2016-01-20 14:37:01 +0100
committerNicolas LÅ“uillet <nicolas.loeuillet@smile.fr>2016-01-20 14:37:01 +0100
commit6785f4aa749e381081b93e3db46424cc7475eab8 (patch)
treef8fb914c4febb93ee229c4b13f2488ee0c9fe2fc /src/Wallabag/ImportBundle/Controller
parentd481f42b7d383eb6211d1d3049d1a2c8288d9edb (diff)
downloadwallabag-6785f4aa749e381081b93e3db46424cc7475eab8.tar.gz
wallabag-6785f4aa749e381081b93e3db46424cc7475eab8.tar.zst
wallabag-6785f4aa749e381081b93e3db46424cc7475eab8.zip
[#1590] Add JSON import from wallabag v2
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller')
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php60
1 files changed, 60 insertions, 0 deletions
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 @@
1<?php
2
3namespace Wallabag\ImportBundle\Controller;
4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\ImportBundle\Form\Type\UploadImportType;
9
10class WallabagV2Controller extends Controller
11{
12 /**
13 * @Route("/wallabag-v2", name="import_wallabag_v2")
14 */
15 public function indexAction(Request $request)
16 {
17 $form = $this->createForm(UploadImportType::class);
18 $form->handleRequest($request);
19
20 $wallabag = $this->get('wallabag_import.wallabag_v2.import');
21
22 if ($form->isValid()) {
23 $file = $form->get('file')->getData();
24 $name = $this->getUser()->getId().'.json';
25
26 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
27 $res = $wallabag
28 ->setUser($this->getUser())
29 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
30 ->import();
31
32 $message = 'Import failed, please try again.';
33
34 if (true === $res) {
35 $summary = $wallabag->getSummary();
36 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.';
37
38 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
39 }
40
41 $this->get('session')->getFlashBag()->add(
42 'notice',
43 $message
44 );
45
46 return $this->redirect($this->generateUrl('homepage'));
47 } else {
48 $this->get('session')->getFlashBag()->add(
49 'notice',
50 'Error while processing import. Please verify your import file.'
51 );
52 }
53 }
54
55 return $this->render('WallabagImportBundle:WallabagV2:index.html.twig', [
56 'form' => $form->createView(),
57 'import' => $wallabag,
58 ]);
59 }
60}