aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-07-01 09:52:38 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-07-01 09:52:38 +0200
commitf808b01692a835673f328d7221ba8c212caa9b61 (patch)
tree0c3b1fc5b1ddbd7af72227303503177689e1d403 /src/Wallabag/ImportBundle/Controller
parent822c877949aff8ae57677671115f8f4fc69588d5 (diff)
downloadwallabag-f808b01692a835673f328d7221ba8c212caa9b61.tar.gz
wallabag-f808b01692a835673f328d7221ba8c212caa9b61.tar.zst
wallabag-f808b01692a835673f328d7221ba8c212caa9b61.zip
Add a real configuration for CS-Fixer
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller')
-rw-r--r--src/Wallabag/ImportBundle/Controller/BrowserController.php43
-rw-r--r--src/Wallabag/ImportBundle/Controller/ChromeController.php16
-rw-r--r--src/Wallabag/ImportBundle/Controller/FirefoxController.php16
-rw-r--r--src/Wallabag/ImportBundle/Controller/ImportController.php6
-rw-r--r--src/Wallabag/ImportBundle/Controller/InstapaperController.php20
-rw-r--r--src/Wallabag/ImportBundle/Controller/PinboardController.php20
-rw-r--r--src/Wallabag/ImportBundle/Controller/PocketController.php46
-rw-r--r--src/Wallabag/ImportBundle/Controller/ReadabilityController.php20
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagController.php46
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php16
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php16
11 files changed, 132 insertions, 133 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/BrowserController.php b/src/Wallabag/ImportBundle/Controller/BrowserController.php
index e119098f..0753e318 100644
--- a/src/Wallabag/ImportBundle/Controller/BrowserController.php
+++ b/src/Wallabag/ImportBundle/Controller/BrowserController.php
@@ -2,8 +2,8 @@
2 2
3namespace Wallabag\ImportBundle\Controller; 3namespace Wallabag\ImportBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 7use 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;
@@ -11,20 +11,6 @@ use Wallabag\ImportBundle\Form\Type\UploadImportType;
11abstract class BrowserController extends Controller 11abstract class BrowserController extends Controller
12{ 12{
13 /** 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") 14 * @Route("/browser", name="import_browser")
29 * 15 *
30 * @param Request $request 16 * @param Request $request
@@ -42,11 +28,11 @@ abstract class BrowserController extends Controller
42 if ($form->isSubmitted() && $form->isValid()) { 28 if ($form->isSubmitted() && $form->isValid()) {
43 $file = $form->get('file')->getData(); 29 $file = $form->get('file')->getData();
44 $markAsRead = $form->get('mark_as_read')->getData(); 30 $markAsRead = $form->get('mark_as_read')->getData();
45 $name = $this->getUser()->getId().'.json'; 31 $name = $this->getUser()->getId() . '.json';
46 32
47 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 33 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
48 $res = $wallabag 34 $res = $wallabag
49 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 35 ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
50 ->setMarkAsRead($markAsRead) 36 ->setMarkAsRead($markAsRead)
51 ->import(); 37 ->import();
52 38
@@ -65,7 +51,7 @@ abstract class BrowserController extends Controller
65 ]); 51 ]);
66 } 52 }
67 53
68 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 54 unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
69 } 55 }
70 56
71 $this->get('session')->getFlashBag()->add( 57 $this->get('session')->getFlashBag()->add(
@@ -74,12 +60,11 @@ abstract class BrowserController extends Controller
74 ); 60 );
75 61
76 return $this->redirect($this->generateUrl('homepage')); 62 return $this->redirect($this->generateUrl('homepage'));
77 } else { 63 }
78 $this->get('session')->getFlashBag()->add( 64 $this->get('session')->getFlashBag()->add(
79 'notice', 65 'notice',
80 'flashes.import.notice.failed_on_file' 66 'flashes.import.notice.failed_on_file'
81 ); 67 );
82 }
83 } 68 }
84 69
85 return $this->render($this->getImportTemplate(), [ 70 return $this->render($this->getImportTemplate(), [
@@ -87,4 +72,18 @@ abstract class BrowserController extends Controller
87 'import' => $wallabag, 72 'import' => $wallabag,
88 ]); 73 ]);
89 } 74 }
75
76 /**
77 * Return the service to handle the import.
78 *
79 * @return \Wallabag\ImportBundle\Import\ImportInterface
80 */
81 abstract protected function getImportService();
82
83 /**
84 * Return the template used for the form.
85 *
86 * @return string
87 */
88 abstract protected function getImportTemplate();
90} 89}
diff --git a/src/Wallabag/ImportBundle/Controller/ChromeController.php b/src/Wallabag/ImportBundle/Controller/ChromeController.php
index 454f3347..0cb418a1 100644
--- a/src/Wallabag/ImportBundle/Controller/ChromeController.php
+++ b/src/Wallabag/ImportBundle/Controller/ChromeController.php
@@ -8,6 +8,14 @@ use Symfony\Component\HttpFoundation\Request;
8class ChromeController extends BrowserController 8class ChromeController extends BrowserController
9{ 9{
10 /** 10 /**
11 * @Route("/chrome", name="import_chrome")
12 */
13 public function indexAction(Request $request)
14 {
15 return parent::indexAction($request);
16 }
17
18 /**
11 * {@inheritdoc} 19 * {@inheritdoc}
12 */ 20 */
13 protected function getImportService() 21 protected function getImportService()
@@ -30,12 +38,4 @@ class ChromeController extends BrowserController
30 { 38 {
31 return 'WallabagImportBundle:Chrome:index.html.twig'; 39 return 'WallabagImportBundle:Chrome:index.html.twig';
32 } 40 }
33
34 /**
35 * @Route("/chrome", name="import_chrome")
36 */
37 public function indexAction(Request $request)
38 {
39 return parent::indexAction($request);
40 }
41} 41}
diff --git a/src/Wallabag/ImportBundle/Controller/FirefoxController.php b/src/Wallabag/ImportBundle/Controller/FirefoxController.php
index c329b9c4..88697f9d 100644
--- a/src/Wallabag/ImportBundle/Controller/FirefoxController.php
+++ b/src/Wallabag/ImportBundle/Controller/FirefoxController.php
@@ -8,6 +8,14 @@ use Symfony\Component\HttpFoundation\Request;
8class FirefoxController extends BrowserController 8class FirefoxController extends BrowserController
9{ 9{
10 /** 10 /**
11 * @Route("/firefox", name="import_firefox")
12 */
13 public function indexAction(Request $request)
14 {
15 return parent::indexAction($request);
16 }
17
18 /**
11 * {@inheritdoc} 19 * {@inheritdoc}
12 */ 20 */
13 protected function getImportService() 21 protected function getImportService()
@@ -30,12 +38,4 @@ class FirefoxController extends BrowserController
30 { 38 {
31 return 'WallabagImportBundle:Firefox:index.html.twig'; 39 return 'WallabagImportBundle:Firefox:index.html.twig';
32 } 40 }
33
34 /**
35 * @Route("/firefox", name="import_firefox")
36 */
37 public function indexAction(Request $request)
38 {
39 return parent::indexAction($request);
40 }
41} 41}
diff --git a/src/Wallabag/ImportBundle/Controller/ImportController.php b/src/Wallabag/ImportBundle/Controller/ImportController.php
index 237c748e..7e4fd174 100644
--- a/src/Wallabag/ImportBundle/Controller/ImportController.php
+++ b/src/Wallabag/ImportBundle/Controller/ImportController.php
@@ -2,8 +2,8 @@
2 2
3namespace Wallabag\ImportBundle\Controller; 3namespace Wallabag\ImportBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7 7
8class ImportController extends Controller 8class ImportController extends Controller
9{ 9{
@@ -86,9 +86,9 @@ class ImportController extends Controller
86 private function getTotalMessageInRabbitQueue($importService) 86 private function getTotalMessageInRabbitQueue($importService)
87 { 87 {
88 $message = $this 88 $message = $this
89 ->get('old_sound_rabbit_mq.import_'.$importService.'_consumer') 89 ->get('old_sound_rabbit_mq.import_' . $importService . '_consumer')
90 ->getChannel() 90 ->getChannel()
91 ->basic_get('wallabag.import.'.$importService); 91 ->basic_get('wallabag.import.' . $importService);
92 92
93 if (null === $message) { 93 if (null === $message) {
94 return 0; 94 return 0;
diff --git a/src/Wallabag/ImportBundle/Controller/InstapaperController.php b/src/Wallabag/ImportBundle/Controller/InstapaperController.php
index 0251acb9..550679c3 100644
--- a/src/Wallabag/ImportBundle/Controller/InstapaperController.php
+++ b/src/Wallabag/ImportBundle/Controller/InstapaperController.php
@@ -2,8 +2,8 @@
2 2
3namespace Wallabag\ImportBundle\Controller; 3namespace Wallabag\ImportBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\ImportBundle\Form\Type\UploadImportType; 8use Wallabag\ImportBundle\Form\Type\UploadImportType;
9 9
@@ -29,11 +29,11 @@ class InstapaperController extends Controller
29 if ($form->isSubmitted() && $form->isValid()) { 29 if ($form->isSubmitted() && $form->isValid()) {
30 $file = $form->get('file')->getData(); 30 $file = $form->get('file')->getData();
31 $markAsRead = $form->get('mark_as_read')->getData(); 31 $markAsRead = $form->get('mark_as_read')->getData();
32 $name = 'instapaper_'.$this->getUser()->getId().'.csv'; 32 $name = 'instapaper_' . $this->getUser()->getId() . '.csv';
33 33
34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
35 $res = $instapaper 35 $res = $instapaper
36 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 36 ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
37 ->setMarkAsRead($markAsRead) 37 ->setMarkAsRead($markAsRead)
38 ->import(); 38 ->import();
39 39
@@ -52,7 +52,7 @@ class InstapaperController extends Controller
52 ]); 52 ]);
53 } 53 }
54 54
55 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 55 unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
56 } 56 }
57 57
58 $this->get('session')->getFlashBag()->add( 58 $this->get('session')->getFlashBag()->add(
@@ -61,12 +61,12 @@ class InstapaperController extends Controller
61 ); 61 );
62 62
63 return $this->redirect($this->generateUrl('homepage')); 63 return $this->redirect($this->generateUrl('homepage'));
64 } else {
65 $this->get('session')->getFlashBag()->add(
66 'notice',
67 'flashes.import.notice.failed_on_file'
68 );
69 } 64 }
65
66 $this->get('session')->getFlashBag()->add(
67 'notice',
68 'flashes.import.notice.failed_on_file'
69 );
70 } 70 }
71 71
72 return $this->render('WallabagImportBundle:Instapaper:index.html.twig', [ 72 return $this->render('WallabagImportBundle:Instapaper:index.html.twig', [
diff --git a/src/Wallabag/ImportBundle/Controller/PinboardController.php b/src/Wallabag/ImportBundle/Controller/PinboardController.php
index d0ad8aa8..0e57fd41 100644
--- a/src/Wallabag/ImportBundle/Controller/PinboardController.php
+++ b/src/Wallabag/ImportBundle/Controller/PinboardController.php
@@ -2,8 +2,8 @@
2 2
3namespace Wallabag\ImportBundle\Controller; 3namespace Wallabag\ImportBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\ImportBundle\Form\Type\UploadImportType; 8use Wallabag\ImportBundle\Form\Type\UploadImportType;
9 9
@@ -29,11 +29,11 @@ class PinboardController extends Controller
29 if ($form->isSubmitted() && $form->isValid()) { 29 if ($form->isSubmitted() && $form->isValid()) {
30 $file = $form->get('file')->getData(); 30 $file = $form->get('file')->getData();
31 $markAsRead = $form->get('mark_as_read')->getData(); 31 $markAsRead = $form->get('mark_as_read')->getData();
32 $name = 'pinboard_'.$this->getUser()->getId().'.json'; 32 $name = 'pinboard_' . $this->getUser()->getId() . '.json';
33 33
34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
35 $res = $pinboard 35 $res = $pinboard
36 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 36 ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
37 ->setMarkAsRead($markAsRead) 37 ->setMarkAsRead($markAsRead)
38 ->import(); 38 ->import();
39 39
@@ -52,7 +52,7 @@ class PinboardController extends Controller
52 ]); 52 ]);
53 } 53 }
54 54
55 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 55 unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
56 } 56 }
57 57
58 $this->get('session')->getFlashBag()->add( 58 $this->get('session')->getFlashBag()->add(
@@ -61,12 +61,12 @@ class PinboardController extends Controller
61 ); 61 );
62 62
63 return $this->redirect($this->generateUrl('homepage')); 63 return $this->redirect($this->generateUrl('homepage'));
64 } else {
65 $this->get('session')->getFlashBag()->add(
66 'notice',
67 'flashes.import.notice.failed_on_file'
68 );
69 } 64 }
65
66 $this->get('session')->getFlashBag()->add(
67 'notice',
68 'flashes.import.notice.failed_on_file'
69 );
70 } 70 }
71 71
72 return $this->render('WallabagImportBundle:Pinboard:index.html.twig', [ 72 return $this->render('WallabagImportBundle:Pinboard:index.html.twig', [
diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php
index 56be5cbf..9f28819a 100644
--- a/src/Wallabag/ImportBundle/Controller/PocketController.php
+++ b/src/Wallabag/ImportBundle/Controller/PocketController.php
@@ -2,34 +2,15 @@
2 2
3namespace Wallabag\ImportBundle\Controller; 3namespace Wallabag\ImportBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8use Symfony\Component\HttpFoundation\Request; 6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9use Symfony\Component\Form\Extension\Core\Type\CheckboxType; 7use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
8use Symfony\Component\HttpFoundation\Request;
9use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
10 10
11class PocketController extends Controller 11class PocketController extends Controller
12{ 12{
13 /** 13 /**
14 * Return Pocket Import Service with or without RabbitMQ enabled.
15 *
16 * @return \Wallabag\ImportBundle\Import\PocketImport
17 */
18 private function getPocketImportService()
19 {
20 $pocket = $this->get('wallabag_import.pocket.import');
21 $pocket->setUser($this->getUser());
22
23 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
24 $pocket->setProducer($this->get('old_sound_rabbit_mq.import_pocket_producer'));
25 } elseif ($this->get('craue_config')->get('import_with_redis')) {
26 $pocket->setProducer($this->get('wallabag_import.producer.redis.pocket'));
27 }
28
29 return $pocket;
30 }
31
32 /**
33 * @Route("/pocket", name="import_pocket") 14 * @Route("/pocket", name="import_pocket")
34 */ 15 */
35 public function indexAction() 16 public function indexAction()
@@ -70,7 +51,7 @@ class PocketController extends Controller
70 $this->get('session')->set('mark_as_read', $request->request->get('form')['mark_as_read']); 51 $this->get('session')->set('mark_as_read', $request->request->get('form')['mark_as_read']);
71 52
72 return $this->redirect( 53 return $this->redirect(
73 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', [], UrlGeneratorInterface::ABSOLUTE_URL), 54 'https://getpocket.com/auth/authorize?request_token=' . $requestToken . '&redirect_uri=' . $this->generateUrl('import_pocket_callback', [], UrlGeneratorInterface::ABSOLUTE_URL),
74 301 55 301
75 ); 56 );
76 } 57 }
@@ -117,4 +98,23 @@ class PocketController extends Controller
117 98
118 return $this->redirect($this->generateUrl('homepage')); 99 return $this->redirect($this->generateUrl('homepage'));
119 } 100 }
101
102 /**
103 * Return Pocket Import Service with or without RabbitMQ enabled.
104 *
105 * @return \Wallabag\ImportBundle\Import\PocketImport
106 */
107 private function getPocketImportService()
108 {
109 $pocket = $this->get('wallabag_import.pocket.import');
110 $pocket->setUser($this->getUser());
111
112 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
113 $pocket->setProducer($this->get('old_sound_rabbit_mq.import_pocket_producer'));
114 } elseif ($this->get('craue_config')->get('import_with_redis')) {
115 $pocket->setProducer($this->get('wallabag_import.producer.redis.pocket'));
116 }
117
118 return $pocket;
119 }
120} 120}
diff --git a/src/Wallabag/ImportBundle/Controller/ReadabilityController.php b/src/Wallabag/ImportBundle/Controller/ReadabilityController.php
index aa732ddd..59de24cb 100644
--- a/src/Wallabag/ImportBundle/Controller/ReadabilityController.php
+++ b/src/Wallabag/ImportBundle/Controller/ReadabilityController.php
@@ -2,8 +2,8 @@
2 2
3namespace Wallabag\ImportBundle\Controller; 3namespace Wallabag\ImportBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\ImportBundle\Form\Type\UploadImportType; 8use Wallabag\ImportBundle\Form\Type\UploadImportType;
9 9
@@ -29,11 +29,11 @@ class ReadabilityController extends Controller
29 if ($form->isSubmitted() && $form->isValid()) { 29 if ($form->isSubmitted() && $form->isValid()) {
30 $file = $form->get('file')->getData(); 30 $file = $form->get('file')->getData();
31 $markAsRead = $form->get('mark_as_read')->getData(); 31 $markAsRead = $form->get('mark_as_read')->getData();
32 $name = 'readability_'.$this->getUser()->getId().'.json'; 32 $name = 'readability_' . $this->getUser()->getId() . '.json';
33 33
34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
35 $res = $readability 35 $res = $readability
36 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 36 ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
37 ->setMarkAsRead($markAsRead) 37 ->setMarkAsRead($markAsRead)
38 ->import(); 38 ->import();
39 39
@@ -52,7 +52,7 @@ class ReadabilityController extends Controller
52 ]); 52 ]);
53 } 53 }
54 54
55 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 55 unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
56 } 56 }
57 57
58 $this->get('session')->getFlashBag()->add( 58 $this->get('session')->getFlashBag()->add(
@@ -61,12 +61,12 @@ class ReadabilityController extends Controller
61 ); 61 );
62 62
63 return $this->redirect($this->generateUrl('homepage')); 63 return $this->redirect($this->generateUrl('homepage'));
64 } else {
65 $this->get('session')->getFlashBag()->add(
66 'notice',
67 'flashes.import.notice.failed_on_file'
68 );
69 } 64 }
65
66 $this->get('session')->getFlashBag()->add(
67 'notice',
68 'flashes.import.notice.failed_on_file'
69 );
70 } 70 }
71 71
72 return $this->render('WallabagImportBundle:Readability:index.html.twig', [ 72 return $this->render('WallabagImportBundle:Readability:index.html.twig', [
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagController.php b/src/Wallabag/ImportBundle/Controller/WallabagController.php
index e81c1ca9..7b61805b 100644
--- a/src/Wallabag/ImportBundle/Controller/WallabagController.php
+++ b/src/Wallabag/ImportBundle/Controller/WallabagController.php
@@ -12,20 +12,6 @@ use Wallabag\ImportBundle\Form\Type\UploadImportType;
12abstract class WallabagController extends Controller 12abstract class WallabagController extends Controller
13{ 13{
14 /** 14 /**
15 * Return the service to handle the import.
16 *
17 * @return \Wallabag\ImportBundle\Import\ImportInterface
18 */
19 abstract protected function getImportService();
20
21 /**
22 * Return the template used for the form.
23 *
24 * @return string
25 */
26 abstract protected function getImportTemplate();
27
28 /**
29 * Handle import request. 15 * Handle import request.
30 * 16 *
31 * @param Request $request 17 * @param Request $request
@@ -43,11 +29,11 @@ abstract class WallabagController extends Controller
43 if ($form->isSubmitted() && $form->isValid()) { 29 if ($form->isSubmitted() && $form->isValid()) {
44 $file = $form->get('file')->getData(); 30 $file = $form->get('file')->getData();
45 $markAsRead = $form->get('mark_as_read')->getData(); 31 $markAsRead = $form->get('mark_as_read')->getData();
46 $name = $this->getUser()->getId().'.json'; 32 $name = $this->getUser()->getId() . '.json';
47 33
48 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
49 $res = $wallabag 35 $res = $wallabag
50 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 36 ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
51 ->setMarkAsRead($markAsRead) 37 ->setMarkAsRead($markAsRead)
52 ->import(); 38 ->import();
53 39
@@ -66,7 +52,7 @@ abstract class WallabagController extends Controller
66 ]); 52 ]);
67 } 53 }
68 54
69 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 55 unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
70 } 56 }
71 57
72 $this->get('session')->getFlashBag()->add( 58 $this->get('session')->getFlashBag()->add(
@@ -75,12 +61,12 @@ abstract class WallabagController extends Controller
75 ); 61 );
76 62
77 return $this->redirect($this->generateUrl('homepage')); 63 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 } 64 }
65
66 $this->get('session')->getFlashBag()->add(
67 'notice',
68 'flashes.import.notice.failed_on_file'
69 );
84 } 70 }
85 71
86 return $this->render($this->getImportTemplate(), [ 72 return $this->render($this->getImportTemplate(), [
@@ -88,4 +74,18 @@ abstract class WallabagController extends Controller
88 'import' => $wallabag, 74 'import' => $wallabag,
89 ]); 75 ]);
90 } 76 }
77
78 /**
79 * Return the service to handle the import.
80 *
81 * @return \Wallabag\ImportBundle\Import\ImportInterface
82 */
83 abstract protected function getImportService();
84
85 /**
86 * Return the template used for the form.
87 *
88 * @return string
89 */
90 abstract protected function getImportTemplate();
91} 91}
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
index 312c7a35..d700d8a8 100644
--- a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
+++ b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
@@ -8,6 +8,14 @@ use Symfony\Component\HttpFoundation\Request;
8class WallabagV1Controller extends WallabagController 8class WallabagV1Controller extends WallabagController
9{ 9{
10 /** 10 /**
11 * @Route("/wallabag-v1", name="import_wallabag_v1")
12 */
13 public function indexAction(Request $request)
14 {
15 return parent::indexAction($request);
16 }
17
18 /**
11 * {@inheritdoc} 19 * {@inheritdoc}
12 */ 20 */
13 protected function getImportService() 21 protected function getImportService()
@@ -30,12 +38,4 @@ class WallabagV1Controller extends WallabagController
30 { 38 {
31 return 'WallabagImportBundle:WallabagV1:index.html.twig'; 39 return 'WallabagImportBundle:WallabagV1:index.html.twig';
32 } 40 }
33
34 /**
35 * @Route("/wallabag-v1", name="import_wallabag_v1")
36 */
37 public function indexAction(Request $request)
38 {
39 return parent::indexAction($request);
40 }
41} 41}
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
index 45211fe6..ab26400c 100644
--- a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
+++ b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
@@ -8,6 +8,14 @@ use Symfony\Component\HttpFoundation\Request;
8class WallabagV2Controller extends WallabagController 8class WallabagV2Controller extends WallabagController
9{ 9{
10 /** 10 /**
11 * @Route("/wallabag-v2", name="import_wallabag_v2")
12 */
13 public function indexAction(Request $request)
14 {
15 return parent::indexAction($request);
16 }
17
18 /**
11 * {@inheritdoc} 19 * {@inheritdoc}
12 */ 20 */
13 protected function getImportService() 21 protected function getImportService()
@@ -30,12 +38,4 @@ class WallabagV2Controller extends WallabagController
30 { 38 {
31 return 'WallabagImportBundle:WallabagV2:index.html.twig'; 39 return 'WallabagImportBundle:WallabagV2:index.html.twig';
32 } 40 }
33
34 /**
35 * @Route("/wallabag-v2", name="import_wallabag_v2")
36 */
37 public function indexAction(Request $request)
38 {
39 return parent::indexAction($request);
40 }
41} 41}