aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2016-09-21 17:47:47 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-09-25 12:29:18 +0200
commit59201088b4fc13fd361238396f630dabd9bd1990 (patch)
tree2d4d5c2fbe7f007214c41f0c4ccba2f8d3d7ec8b /src/Wallabag/ImportBundle/Controller
parentf7c55b38122cc593c2b58bb6425fca9d243b055e (diff)
downloadwallabag-59201088b4fc13fd361238396f630dabd9bd1990.tar.gz
wallabag-59201088b4fc13fd361238396f630dabd9bd1990.tar.zst
wallabag-59201088b4fc13fd361238396f630dabd9bd1990.zip
bring chrome and firefox as separate imports
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller')
-rw-r--r--src/Wallabag/ImportBundle/Controller/BrowserController.php23
-rw-r--r--src/Wallabag/ImportBundle/Controller/ChromeController.php41
-rw-r--r--src/Wallabag/ImportBundle/Controller/FirefoxController.php41
3 files changed, 93 insertions, 12 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/BrowserController.php b/src/Wallabag/ImportBundle/Controller/BrowserController.php
index 3b54a72e..144a4880 100644
--- a/src/Wallabag/ImportBundle/Controller/BrowserController.php
+++ b/src/Wallabag/ImportBundle/Controller/BrowserController.php
@@ -8,27 +8,21 @@ use Symfony\Component\HttpFoundation\Request;
8use Symfony\Component\HttpFoundation\Response; 8use Symfony\Component\HttpFoundation\Response;
9use Wallabag\ImportBundle\Form\Type\UploadImportType; 9use Wallabag\ImportBundle\Form\Type\UploadImportType;
10 10
11class BrowserController extends Controller 11abstract class BrowserController extends Controller
12{ 12{
13 /** 13 /**
14 * Return the service to handle the import. 14 * Return the service to handle the import.
15 * 15 *
16 * @return \Wallabag\ImportBundle\Import\ImportInterface 16 * @return \Wallabag\ImportBundle\Import\ImportInterface
17 */ 17 */
18 protected function getImportService() 18 abstract protected function getImportService();
19 {
20 return $this->get('wallabag_import.browser.import');
21 }
22 19
23 /** 20 /**
24 * Return the template used for the form. 21 * Return the template used for the form.
25 * 22 *
26 * @return string 23 * @return string
27 */ 24 */
28 protected function getImportTemplate() 25 abstract protected function getImportTemplate();
29 {
30 return 'WallabagImportBundle:Browser:index.html.twig';
31 }
32 26
33 /** 27 /**
34 * @Route("/browser", name="import_browser") 28 * @Route("/browser", name="import_browser")
@@ -43,15 +37,15 @@ class BrowserController extends Controller
43 $form->handleRequest($request); 37 $form->handleRequest($request);
44 38
45 $wallabag = $this->getImportService(); 39 $wallabag = $this->getImportService();
40 $wallabag->setUser($this->getUser());
46 41
47 if ($form->isValid()) { 42 if ($form->isValid()) {
48 $file = $form->get('file')->getData(); 43 $file = $form->get('file')->getData();
49 $markAsRead = $form->get('mark_as_read')->getData(); 44 $markAsRead = $form->get('mark_as_read')->getData();
50 $name = $this->getUser()->getId().'.json'; 45 $name = $this->getUser()->getId().'.json';
51 46
52 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 47 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
53 $res = $wallabag 48 $res = $wallabag
54 ->setUser($this->getUser())
55 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 49 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
56 ->setMarkAsRead($markAsRead) 50 ->setMarkAsRead($markAsRead)
57 ->import(); 51 ->import();
@@ -60,12 +54,17 @@ class BrowserController extends Controller
60 54
61 if (true === $res) { 55 if (true === $res) {
62 $summary = $wallabag->getSummary(); 56 $summary = $wallabag->getSummary();
63 // TODO : Pluralize these messages
64 $message = $this->get('translator')->trans('flashes.import.notice.summary', [ 57 $message = $this->get('translator')->trans('flashes.import.notice.summary', [
65 '%imported%' => $summary['imported'], 58 '%imported%' => $summary['imported'],
66 '%skipped%' => $summary['skipped'], 59 '%skipped%' => $summary['skipped'],
67 ]); 60 ]);
68 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
69 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 68 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
70 } 69 }
71 70
diff --git a/src/Wallabag/ImportBundle/Controller/ChromeController.php b/src/Wallabag/ImportBundle/Controller/ChromeController.php
new file mode 100644
index 00000000..e4cc322a
--- /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_wallabag_v1_producer'));
19 } elseif ($this->get('craue_config')->get('import_with_redis')) {
20 $service->setProducer($this->get('wallabag_import.producer.redis.wallabag_v1'));
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..e0dd8214
--- /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_wallabag_v1_producer'));
19 } elseif ($this->get('craue_config')->get('import_with_redis')) {
20 $service->setProducer($this->get('wallabag_import.producer.redis.wallabag_v1'));
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}