]>
Commit | Line | Data |
---|---|---|
03e3753f JB |
1 | <?php |
2 | ||
3 | namespace Wallabag\ImportBundle\Controller; | |
4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
7 | use Symfony\Component\HttpFoundation\Request; | |
8 | use Wallabag\ImportBundle\Form\Type\UploadImportType; | |
9 | ||
10 | class ReadabilityController extends Controller | |
11 | { | |
12 | /** | |
13 | * @Route("/readability", name="import_readability") | |
14 | */ | |
15 | public function indexAction(Request $request) | |
16 | { | |
17 | $form = $this->createForm(UploadImportType::class); | |
18 | $form->handleRequest($request); | |
19 | ||
20 | $readability = $this->get('wallabag_import.readability.import'); | |
c98db1b6 JB |
21 | $readability->setUser($this->getUser()); |
22 | ||
23 | if ($this->get('craue_config')->get('rabbitmq')) { | |
24 | $readability->setRabbitmqProducer($this->get('old_sound_rabbit_mq.import_readability_producer')); | |
25 | } | |
03e3753f JB |
26 | |
27 | if ($form->isValid()) { | |
28 | $file = $form->get('file')->getData(); | |
29 | $markAsRead = $form->get('mark_as_read')->getData(); | |
30 | $name = 'readability_'.$this->getUser()->getId().'.json'; | |
31 | ||
32 | if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { | |
33 | $res = $readability | |
03e3753f JB |
34 | ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) |
35 | ->setMarkAsRead($markAsRead) | |
36 | ->import(); | |
37 | ||
38 | $message = 'flashes.import.notice.failed'; | |
39 | ||
40 | if (true === $res) { | |
41 | $summary = $readability->getSummary(); | |
42 | $message = $this->get('translator')->trans('flashes.import.notice.summary', [ | |
43 | '%imported%' => $summary['imported'], | |
44 | '%skipped%' => $summary['skipped'], | |
45 | ]); | |
46 | ||
47 | unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); | |
48 | } | |
49 | ||
50 | $this->get('session')->getFlashBag()->add( | |
51 | 'notice', | |
52 | $message | |
53 | ); | |
54 | ||
55 | return $this->redirect($this->generateUrl('homepage')); | |
56 | } else { | |
57 | $this->get('session')->getFlashBag()->add( | |
58 | 'notice', | |
59 | 'flashes.import.notice.failed_on_file' | |
60 | ); | |
61 | } | |
62 | } | |
63 | ||
64 | return $this->render('WallabagImportBundle:Readability:index.html.twig', [ | |
65 | 'form' => $form->createView(), | |
66 | 'import' => $readability, | |
67 | ]); | |
68 | } | |
69 | } |