aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php')
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
new file mode 100644
index 00000000..e50a6c35
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
@@ -0,0 +1,59 @@
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 WallabagV1Controller extends Controller
11{
12 /**
13 * @Route("/wallabag-v1", name="import_wallabag_v1")
14 */
15 public function indexAction(Request $request)
16 {
17 $form = $this->createForm(new UploadImportType());
18 $form->handleRequest($request);
19
20 $wallabag = $this->get('wallabag_import.wallabag_v1.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 if (true === $res) {
34 $summary = $wallabag->getSummary();
35 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.';
36
37 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
38 }
39
40 $this->get('session')->getFlashBag()->add(
41 'notice',
42 $message
43 );
44
45 return $this->redirect($this->generateUrl('homepage'));
46 } else {
47 $this->get('session')->getFlashBag()->add(
48 'notice',
49 'Error while processing import. Please verify your import file.'
50 );
51 }
52 }
53
54 return $this->render('WallabagImportBundle:WallabagV1:index.html.twig', [
55 'form' => $form->createView(),
56 'import' => $wallabag,
57 ]);
58 }
59}