aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-03-28 16:43:33 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-03-28 16:43:33 +0200
commitb787a7757ea73b9d10c14cb21758feb07dfc5885 (patch)
tree13989f7a843332cdee095d456863535a2854862c /src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
parent0e49487bb0a004d526eb41e7d3fb44b566441e34 (diff)
downloadwallabag-b787a7757ea73b9d10c14cb21758feb07dfc5885.tar.gz
wallabag-b787a7757ea73b9d10c14cb21758feb07dfc5885.tar.zst
wallabag-b787a7757ea73b9d10c14cb21758feb07dfc5885.zip
Refacto wallabag import
Use an abstract class to store all common action from wallabag vX import. Move specificity in v1 & v2 import.
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php')
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php68
1 files changed, 18 insertions, 50 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
index 3e6428a0..c2a42165 100644
--- a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
+++ b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
@@ -2,64 +2,32 @@
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;
7use Symfony\Component\HttpFoundation\Request; 6use Symfony\Component\HttpFoundation\Request;
8use Wallabag\ImportBundle\Form\Type\UploadImportType;
9 7
10class WallabagV2Controller extends Controller 8class WallabagV2Controller extends WallabagController
11{ 9{
12 /** 10 /**
13 * @Route("/wallabag-v2", name="import_wallabag_v2") 11 * {@inheritdoc}
14 */ 12 */
15 public function indexAction(Request $request) 13 protected function getImportService()
16 { 14 {
17 $form = $this->createForm(UploadImportType::class); 15 return $this->get('wallabag_import.wallabag_v2.import');
18 $form->handleRequest($request); 16 }
19
20 $wallabag = $this->get('wallabag_import.wallabag_v2.import');
21
22 if ($form->isValid()) {
23 $file = $form->get('file')->getData();
24 $markAsRead = $form->get('mark_as_read')->getData();
25 $name = $this->getUser()->getId().'.json';
26
27 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
28 $res = $wallabag
29 ->setUser($this->getUser())
30 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
31 ->setMarkAsRead($markAsRead)
32 ->import();
33
34 $message = 'flashes.import.notice.failed';
35
36 if (true === $res) {
37 $summary = $wallabag->getSummary();
38 $message = $this->get('translator')->trans('flashes.import.notice.summary', array(
39 '%imported%' => $summary['imported'],
40 '%skipped%' => $summary['skipped'],
41 ));
42
43 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
44 }
45
46 $this->get('session')->getFlashBag()->add(
47 'notice',
48 $message
49 );
50 17
51 return $this->redirect($this->generateUrl('homepage')); 18 /**
52 } else { 19 * {@inheritdoc}
53 $this->get('session')->getFlashBag()->add( 20 */
54 'notice', 21 protected function getImportTemplate()
55 'flashes.import.notice.failed_on_file' 22 {
56 ); 23 return 'WallabagImportBundle:WallabagV2:index.html.twig';
57 } 24 }
58 }
59 25
60 return $this->render('WallabagImportBundle:WallabagV2:index.html.twig', [ 26 /**
61 'form' => $form->createView(), 27 * @Route("/wallabag-v2", name="import_wallabag_v2")
62 'import' => $wallabag, 28 */
63 ]); 29 public function indexAction(Request $request)
30 {
31 return parent::indexAction($request);
64 } 32 }
65} 33}