aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller/InstapaperController.php
diff options
context:
space:
mode:
authorPaulino Michelazzo <paulino@michelazzo.com.br>2016-10-18 22:48:23 +0200
committerPaulino Michelazzo <paulino@michelazzo.com.br>2016-10-18 22:48:23 +0200
commit99731f0bb1f6fd2815eeb9af504ce86df927657b (patch)
treeb080efc608d2bbd52b77a4a0067402007f50c5a8 /src/Wallabag/ImportBundle/Controller/InstapaperController.php
parent3a3c6b866b52721431bed22426d9abfcd0d2dfe0 (diff)
parent7180aaed45dce62e40620a9e4b202526ebd6a3bb (diff)
downloadwallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.tar.gz
wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.tar.zst
wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.zip
Merge remote-tracking branch 'wallabag/master'
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller/InstapaperController.php')
-rw-r--r--src/Wallabag/ImportBundle/Controller/InstapaperController.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/InstapaperController.php b/src/Wallabag/ImportBundle/Controller/InstapaperController.php
new file mode 100644
index 00000000..c3fc8a39
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Controller/InstapaperController.php
@@ -0,0 +1,77 @@
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 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
29 if ($form->isValid()) {
30 $file = $form->get('file')->getData();
31 $markAsRead = $form->get('mark_as_read')->getData();
32 $name = 'instapaper_'.$this->getUser()->getId().'.csv';
33
34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
35 $res = $instapaper
36 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
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
55 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
56 }
57
58 $this->get('session')->getFlashBag()->add(
59 'notice',
60 $message
61 );
62
63 return $this->redirect($this->generateUrl('homepage'));
64 } else {
65 $this->get('session')->getFlashBag()->add(
66 'notice',
67 'flashes.import.notice.failed_on_file'
68 );
69 }
70 }
71
72 return $this->render('WallabagImportBundle:Instapaper:index.html.twig', [
73 'form' => $form->createView(),
74 'import' => $instapaper,
75 ]);
76 }
77}