aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller/BrowserController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller/BrowserController.php')
-rw-r--r--src/Wallabag/ImportBundle/Controller/BrowserController.php43
1 files changed, 21 insertions, 22 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}