]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/ImportBundle/Controller/InstapaperController.php
Add a real configuration for CS-Fixer
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Controller / InstapaperController.php
CommitLineData
ff1a5362
JB
1<?php
2
3namespace Wallabag\ImportBundle\Controller;
4
ff1a5362 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
f808b016 6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
ff1a5362
JB
7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\ImportBundle\Form\Type\UploadImportType;
9
10class InstapaperController extends Controller
11{
12 /**
13 * @Route("/instapaper", name="import_instapaper")
14 */
15 public function indexAction(Request $request)
16 {
17 $form = $this->createForm(UploadImportType::class);
18 $form->handleRequest($request);
19
20 $instapaper = $this->get('wallabag_import.instapaper.import');
21 $instapaper->setUser($this->getUser());
22
23 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
24 $instapaper->setProducer($this->get('old_sound_rabbit_mq.import_instapaper_producer'));
25 } elseif ($this->get('craue_config')->get('import_with_redis')) {
26 $instapaper->setProducer($this->get('wallabag_import.producer.redis.instapaper'));
27 }
28
21e7ccef 29 if ($form->isSubmitted() && $form->isValid()) {
ff1a5362
JB
30 $file = $form->get('file')->getData();
31 $markAsRead = $form->get('mark_as_read')->getData();
f808b016 32 $name = 'instapaper_' . $this->getUser()->getId() . '.csv';
ff1a5362 33
f808b016 34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
ff1a5362 35 $res = $instapaper
f808b016 36 ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
ff1a5362
JB
37 ->setMarkAsRead($markAsRead)
38 ->import();
39
40 $message = 'flashes.import.notice.failed';
41
42 if (true === $res) {
43 $summary = $instapaper->getSummary();
44 $message = $this->get('translator')->trans('flashes.import.notice.summary', [
45 '%imported%' => $summary['imported'],
46 '%skipped%' => $summary['skipped'],
47 ]);
48
49 if (0 < $summary['queued']) {
50 $message = $this->get('translator')->trans('flashes.import.notice.summary_with_queue', [
51 '%queued%' => $summary['queued'],
52 ]);
53 }
54
f808b016 55 unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
ff1a5362
JB
56 }
57
58 $this->get('session')->getFlashBag()->add(
59 'notice',
60 $message
61 );
62
63 return $this->redirect($this->generateUrl('homepage'));
ff1a5362 64 }
f808b016
JB
65
66 $this->get('session')->getFlashBag()->add(
67 'notice',
68 'flashes.import.notice.failed_on_file'
69 );
ff1a5362
JB
70 }
71
72 return $this->render('WallabagImportBundle:Instapaper:index.html.twig', [
73 'form' => $form->createView(),
74 'import' => $instapaper,
75 ]);
76 }
77}