]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
Remove some complexicity in InstallCommand
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Controller / WallabagV2Controller.php
CommitLineData
6785f4aa
NL
1<?php
2
3namespace Wallabag\ImportBundle\Controller;
4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\ImportBundle\Form\Type\UploadImportType;
9
10class WallabagV2Controller extends Controller
11{
12 /**
13 * @Route("/wallabag-v2", name="import_wallabag_v2")
14 */
15 public function indexAction(Request $request)
16 {
17 $form = $this->createForm(UploadImportType::class);
18 $form->handleRequest($request);
19
20 $wallabag = $this->get('wallabag_import.wallabag_v2.import');
21
22 if ($form->isValid()) {
23 $file = $form->get('file')->getData();
fe8b37c1 24 $markAsRead = $form->get('mark_as_read')->getData();
6785f4aa
NL
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)
fe8b37c1 31 ->setMarkAsRead($markAsRead)
6785f4aa
NL
32 ->import();
33
4204a06b 34 $message = 'flashes.import.notice.failed';
6785f4aa
NL
35
36 if (true === $res) {
37 $summary = $wallabag->getSummary();
4204a06b
JB
38 $message = $this->get('translator')->trans('flashes.import.notice.summary', array(
39 '%imported%' => $summary['imported'],
40 '%skipped%' => $summary['skipped'],
41 ));
6785f4aa
NL
42
43 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
44 }
45
46 $this->get('session')->getFlashBag()->add(
47 'notice',
48 $message
49 );
50
51 return $this->redirect($this->generateUrl('homepage'));
52 } else {
53 $this->get('session')->getFlashBag()->add(
54 'notice',
4204a06b 55 'flashes.import.notice.failed_on_file'
6785f4aa
NL
56 );
57 }
58 }
59
60 return $this->render('WallabagImportBundle:WallabagV2:index.html.twig', [
61 'form' => $form->createView(),
62 'import' => $wallabag,
63 ]);
64 }
65}