aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2016-07-12 13:51:05 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-09-25 12:28:54 +0200
commitae669126e718ede5dbf76929215d8514cd960976 (patch)
treef7da9fa833014eaec0cc2cfade514df2cc117188 /src/Wallabag/ImportBundle/Controller
parent9d7dd6b0d2480d3efff5b0ab1461f2ef99bfd57a (diff)
downloadwallabag-ae669126e718ede5dbf76929215d8514cd960976.tar.gz
wallabag-ae669126e718ede5dbf76929215d8514cd960976.tar.zst
wallabag-ae669126e718ede5dbf76929215d8514cd960976.zip
Import Firefox & Chrome bookmarks into wallabag
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller')
-rw-r--r--src/Wallabag/ImportBundle/Controller/BrowserController.php91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/BrowserController.php b/src/Wallabag/ImportBundle/Controller/BrowserController.php
new file mode 100644
index 00000000..3b54a72e
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Controller/BrowserController.php
@@ -0,0 +1,91 @@
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 Symfony\Component\HttpFoundation\Response;
9use Wallabag\ImportBundle\Form\Type\UploadImportType;
10
11class BrowserController extends Controller
12{
13 /**
14 * Return the service to handle the import.
15 *
16 * @return \Wallabag\ImportBundle\Import\ImportInterface
17 */
18 protected function getImportService()
19 {
20 return $this->get('wallabag_import.browser.import');
21 }
22
23 /**
24 * Return the template used for the form.
25 *
26 * @return string
27 */
28 protected function getImportTemplate()
29 {
30 return 'WallabagImportBundle:Browser:index.html.twig';
31 }
32
33 /**
34 * @Route("/browser", name="import_browser")
35 *
36 * @param Request $request
37 *
38 * @return Response
39 */
40 public function indexAction(Request $request)
41 {
42 $form = $this->createForm(UploadImportType::class);
43 $form->handleRequest($request);
44
45 $wallabag = $this->getImportService();
46
47 if ($form->isValid()) {
48 $file = $form->get('file')->getData();
49 $markAsRead = $form->get('mark_as_read')->getData();
50 $name = $this->getUser()->getId().'.json';
51
52 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
53 $res = $wallabag
54 ->setUser($this->getUser())
55 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
56 ->setMarkAsRead($markAsRead)
57 ->import();
58
59 $message = 'flashes.import.notice.failed';
60
61 if (true === $res) {
62 $summary = $wallabag->getSummary();
63 // TODO : Pluralize these messages
64 $message = $this->get('translator')->trans('flashes.import.notice.summary', [
65 '%imported%' => $summary['imported'],
66 '%skipped%' => $summary['skipped'],
67 ]);
68
69 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
70 }
71
72 $this->get('session')->getFlashBag()->add(
73 'notice',
74 $message
75 );
76
77 return $this->redirect($this->generateUrl('homepage'));
78 } else {
79 $this->get('session')->getFlashBag()->add(
80 'notice',
81 'flashes.import.notice.failed_on_file'
82 );
83 }
84 }
85
86 return $this->render($this->getImportTemplate(), [
87 'form' => $form->createView(),
88 'import' => $wallabag,
89 ]);
90 }
91}