aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller
diff options
context:
space:
mode:
authorJeremy Benoist <j0k3r@users.noreply.github.com>2016-02-01 14:17:20 +0100
committerJeremy Benoist <j0k3r@users.noreply.github.com>2016-02-01 14:17:20 +0100
commit85ad629a3ca209907effd75f5fd7f384f42361bc (patch)
tree6fde1374b404567153478373f3e65e63af9c1120 /src/Wallabag/ImportBundle/Controller
parente43d27f8450dcdf79850e935b762ac390a19dd63 (diff)
parent6785f4aa749e381081b93e3db46424cc7475eab8 (diff)
downloadwallabag-85ad629a3ca209907effd75f5fd7f384f42361bc.tar.gz
wallabag-85ad629a3ca209907effd75f5fd7f384f42361bc.tar.zst
wallabag-85ad629a3ca209907effd75f5fd7f384f42361bc.zip
Merge pull request #1601 from wallabag/v2-import-from-v2
[#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}