diff options
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php')
-rw-r--r-- | src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php | 65 |
1 files changed, 18 insertions, 47 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php index 154a0769..3e748d57 100644 --- a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php +++ b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php | |||
@@ -2,61 +2,32 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\ImportBundle\Controller; | 3 | namespace Wallabag\ImportBundle\Controller; |
4 | 4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
7 | use Symfony\Component\HttpFoundation\Request; | 6 | use Symfony\Component\HttpFoundation\Request; |
8 | use Wallabag\ImportBundle\Form\Type\UploadImportType; | ||
9 | 7 | ||
10 | class WallabagV1Controller extends Controller | 8 | class WallabagV1Controller extends WallabagController |
11 | { | 9 | { |
12 | /** | 10 | /** |
13 | * @Route("/wallabag-v1", name="import_wallabag_v1") | 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_v1.import'); |
18 | $form->handleRequest($request); | 16 | } |
19 | |||
20 | $wallabag = $this->get('wallabag_import.wallabag_v1.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 = 'Import failed, please try again.'; | ||
35 | |||
36 | if (true === $res) { | ||
37 | $summary = $wallabag->getSummary(); | ||
38 | $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.'; | ||
39 | |||
40 | unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); | ||
41 | } | ||
42 | |||
43 | $this->get('session')->getFlashBag()->add( | ||
44 | 'notice', | ||
45 | $message | ||
46 | ); | ||
47 | 17 | ||
48 | return $this->redirect($this->generateUrl('homepage')); | 18 | /** |
49 | } else { | 19 | * {@inheritdoc} |
50 | $this->get('session')->getFlashBag()->add( | 20 | */ |
51 | 'notice', | 21 | protected function getImportTemplate() |
52 | 'Error while processing import. Please verify your import file.' | 22 | { |
53 | ); | 23 | return 'WallabagImportBundle:WallabagV1:index.html.twig'; |
54 | } | 24 | } |
55 | } | ||
56 | 25 | ||
57 | return $this->render('WallabagImportBundle:WallabagV1:index.html.twig', [ | 26 | /** |
58 | 'form' => $form->createView(), | 27 | * @Route("/wallabag-v1", name="import_wallabag_v1") |
59 | 'import' => $wallabag, | 28 | */ |
60 | ]); | 29 | public function indexAction(Request $request) |
30 | { | ||
31 | return parent::indexAction($request); | ||
61 | } | 32 | } |
62 | } | 33 | } |