aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller
diff options
context:
space:
mode:
authorJeremy Benoist <j0k3r@users.noreply.github.com>2016-09-26 14:47:02 +0200
committerGitHub <noreply@github.com>2016-09-26 14:47:02 +0200
commitd6de23a100221ae1afaa92a58af17a17d0c6614e (patch)
treebd105198c75ea6b8e5d37a80a9f0135942a1c5eb /src/Wallabag/ImportBundle/Controller
parent7e98ad962680fac17b3b90ae34b9c6e5afe7636f (diff)
parentfefef9d41b4d1bd9efbd49011159bae70bf67528 (diff)
downloadwallabag-d6de23a100221ae1afaa92a58af17a17d0c6614e.tar.gz
wallabag-d6de23a100221ae1afaa92a58af17a17d0c6614e.tar.zst
wallabag-d6de23a100221ae1afaa92a58af17a17d0c6614e.zip
Merge pull request #2192 from wallabag/import-browser-bookmarks
Import Firefox & Chrome bookmarks into wallabag
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller')
-rw-r--r--src/Wallabag/ImportBundle/Controller/BrowserController.php90
-rw-r--r--src/Wallabag/ImportBundle/Controller/ChromeController.php41
-rw-r--r--src/Wallabag/ImportBundle/Controller/FirefoxController.php41
3 files changed, 172 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..144a4880
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Controller/BrowserController.php
@@ -0,0 +1,90 @@
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
11abstract class BrowserController extends Controller
12{
13 /**
14 * Return the service to handle the import.
15 *
16 * @return \Wallabag\ImportBundle\Import\ImportInterface
17 */
18 abstract protected function getImportService();
19
20 /**
21 * Return the template used for the form.
22 *
23 * @return string
24 */
25 abstract protected function getImportTemplate();
26
27 /**
28 * @Route("/browser", name="import_browser")
29 *
30 * @param Request $request
31 *
32 * @return Response
33 */
34 public function indexAction(Request $request)
35 {
36 $form = $this->createForm(UploadImportType::class);
37 $form->handleRequest($request);
38
39 $wallabag = $this->getImportService();
40 $wallabag->setUser($this->getUser());
41
42 if ($form->isValid()) {
43 $file = $form->get('file')->getData();
44 $markAsRead = $form->get('mark_as_read')->getData();
45 $name = $this->getUser()->getId().'.json';
46
47 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
48 $res = $wallabag
49 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
50 ->setMarkAsRead($markAsRead)
51 ->import();
52
53 $message = 'flashes.import.notice.failed';
54
55 if (true === $res) {
56 $summary = $wallabag->getSummary();
57 $message = $this->get('translator')->trans('flashes.import.notice.summary', [
58 '%imported%' => $summary['imported'],
59 '%skipped%' => $summary['skipped'],
60 ]);
61
62 if (0 < $summary['queued']) {
63 $message = $this->get('translator')->trans('flashes.import.notice.summary_with_queue', [
64 '%queued%' => $summary['queued'],
65 ]);
66 }
67
68 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
69 }
70
71 $this->get('session')->getFlashBag()->add(
72 'notice',
73 $message
74 );
75
76 return $this->redirect($this->generateUrl('homepage'));
77 } else {
78 $this->get('session')->getFlashBag()->add(
79 'notice',
80 'flashes.import.notice.failed_on_file'
81 );
82 }
83 }
84
85 return $this->render($this->getImportTemplate(), [
86 'form' => $form->createView(),
87 'import' => $wallabag,
88 ]);
89 }
90}
diff --git a/src/Wallabag/ImportBundle/Controller/ChromeController.php b/src/Wallabag/ImportBundle/Controller/ChromeController.php
new file mode 100644
index 00000000..454f3347
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Controller/ChromeController.php
@@ -0,0 +1,41 @@
1<?php
2
3namespace Wallabag\ImportBundle\Controller;
4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Component\HttpFoundation\Request;
7
8class ChromeController extends BrowserController
9{
10 /**
11 * {@inheritdoc}
12 */
13 protected function getImportService()
14 {
15 $service = $this->get('wallabag_import.chrome.import');
16
17 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
18 $service->setProducer($this->get('old_sound_rabbit_mq.import_chrome_producer'));
19 } elseif ($this->get('craue_config')->get('import_with_redis')) {
20 $service->setProducer($this->get('wallabag_import.producer.redis.chrome'));
21 }
22
23 return $service;
24 }
25
26 /**
27 * {@inheritdoc}
28 */
29 protected function getImportTemplate()
30 {
31 return 'WallabagImportBundle:Chrome:index.html.twig';
32 }
33
34 /**
35 * @Route("/chrome", name="import_chrome")
36 */
37 public function indexAction(Request $request)
38 {
39 return parent::indexAction($request);
40 }
41}
diff --git a/src/Wallabag/ImportBundle/Controller/FirefoxController.php b/src/Wallabag/ImportBundle/Controller/FirefoxController.php
new file mode 100644
index 00000000..c329b9c4
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Controller/FirefoxController.php
@@ -0,0 +1,41 @@
1<?php
2
3namespace Wallabag\ImportBundle\Controller;
4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Component\HttpFoundation\Request;
7
8class FirefoxController extends BrowserController
9{
10 /**
11 * {@inheritdoc}
12 */
13 protected function getImportService()
14 {
15 $service = $this->get('wallabag_import.firefox.import');
16
17 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
18 $service->setProducer($this->get('old_sound_rabbit_mq.import_firefox_producer'));
19 } elseif ($this->get('craue_config')->get('import_with_redis')) {
20 $service->setProducer($this->get('wallabag_import.producer.redis.firefox'));
21 }
22
23 return $service;
24 }
25
26 /**
27 * {@inheritdoc}
28 */
29 protected function getImportTemplate()
30 {
31 return 'WallabagImportBundle:Firefox:index.html.twig';
32 }
33
34 /**
35 * @Route("/firefox", name="import_firefox")
36 */
37 public function indexAction(Request $request)
38 {
39 return parent::indexAction($request);
40 }
41}