aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller/WallabagController.php
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2017-10-23 11:09:17 +0200
committerGitHub <noreply@github.com>2017-10-23 11:09:17 +0200
commit1953a872932a63792293b4aec087880265ba89f7 (patch)
treefd16599e737fcdaf193c933ef3ec4a4ee248b117 /src/Wallabag/ImportBundle/Controller/WallabagController.php
parentd83d25dadec2c38460a32d96f5d2903426fec9d3 (diff)
parent702f2d67d60ca963492b90dad74cb5f8dcc84e51 (diff)
downloadwallabag-1953a872932a63792293b4aec087880265ba89f7.tar.gz
wallabag-1953a872932a63792293b4aec087880265ba89f7.tar.zst
wallabag-1953a872932a63792293b4aec087880265ba89f7.zip
Merge pull request #3011 from wallabag/2.3
wallabag 2.3.0
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller/WallabagController.php')
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagController.php48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagController.php b/src/Wallabag/ImportBundle/Controller/WallabagController.php
index e81c1ca9..6e6524b4 100644
--- a/src/Wallabag/ImportBundle/Controller/WallabagController.php
+++ b/src/Wallabag/ImportBundle/Controller/WallabagController.php
@@ -3,7 +3,9 @@
3namespace Wallabag\ImportBundle\Controller; 3namespace Wallabag\ImportBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller; 5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Symfony\Component\HttpFoundation\RedirectResponse;
6use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
8use Symfony\Component\HttpFoundation\Response;
7use Wallabag\ImportBundle\Form\Type\UploadImportType; 9use Wallabag\ImportBundle\Form\Type\UploadImportType;
8 10
9/** 11/**
@@ -12,20 +14,6 @@ use Wallabag\ImportBundle\Form\Type\UploadImportType;
12abstract class WallabagController extends Controller 14abstract class WallabagController extends Controller
13{ 15{
14 /** 16 /**
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. 17 * Handle import request.
30 * 18 *
31 * @param Request $request 19 * @param Request $request
@@ -43,11 +31,11 @@ abstract class WallabagController extends Controller
43 if ($form->isSubmitted() && $form->isValid()) { 31 if ($form->isSubmitted() && $form->isValid()) {
44 $file = $form->get('file')->getData(); 32 $file = $form->get('file')->getData();
45 $markAsRead = $form->get('mark_as_read')->getData(); 33 $markAsRead = $form->get('mark_as_read')->getData();
46 $name = $this->getUser()->getId().'.json'; 34 $name = $this->getUser()->getId() . '.json';
47 35
48 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 36 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 37 $res = $wallabag
50 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 38 ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
51 ->setMarkAsRead($markAsRead) 39 ->setMarkAsRead($markAsRead)
52 ->import(); 40 ->import();
53 41
@@ -66,7 +54,7 @@ abstract class WallabagController extends Controller
66 ]); 54 ]);
67 } 55 }
68 56
69 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 57 unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
70 } 58 }
71 59
72 $this->get('session')->getFlashBag()->add( 60 $this->get('session')->getFlashBag()->add(
@@ -75,12 +63,12 @@ abstract class WallabagController extends Controller
75 ); 63 );
76 64
77 return $this->redirect($this->generateUrl('homepage')); 65 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 } 66 }
67
68 $this->get('session')->getFlashBag()->add(
69 'notice',
70 'flashes.import.notice.failed_on_file'
71 );
84 } 72 }
85 73
86 return $this->render($this->getImportTemplate(), [ 74 return $this->render($this->getImportTemplate(), [
@@ -88,4 +76,18 @@ abstract class WallabagController extends Controller
88 'import' => $wallabag, 76 'import' => $wallabag,
89 ]); 77 ]);
90 } 78 }
79
80 /**
81 * Return the service to handle the import.
82 *
83 * @return \Wallabag\ImportBundle\Import\ImportInterface
84 */
85 abstract protected function getImportService();
86
87 /**
88 * Return the template used for the form.
89 *
90 * @return string
91 */
92 abstract protected function getImportTemplate();
91} 93}