aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-09-27 07:57:53 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2016-09-27 20:27:08 +0200
commitff1a5362f7254d686864ea53994da6c517b3d3e8 (patch)
tree1edc0b6b46cf12bd17918355f7dbe090324e6f70 /src/Wallabag/ImportBundle/Controller
parent55345331c47ca6f389e38a842584c3062476601d (diff)
downloadwallabag-ff1a5362f7254d686864ea53994da6c517b3d3e8.tar.gz
wallabag-ff1a5362f7254d686864ea53994da6c517b3d3e8.tar.zst
wallabag-ff1a5362f7254d686864ea53994da6c517b3d3e8.zip
Add Instapaper import
Also update ImportController with latest import (chrome, firefox & instapaper).
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller')
-rw-r--r--src/Wallabag/ImportBundle/Controller/ImportController.php12
-rw-r--r--src/Wallabag/ImportBundle/Controller/InstapaperController.php77
2 files changed, 87 insertions, 2 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/ImportController.php b/src/Wallabag/ImportBundle/Controller/ImportController.php
index 36a2a399..15de75ff 100644
--- a/src/Wallabag/ImportBundle/Controller/ImportController.php
+++ b/src/Wallabag/ImportBundle/Controller/ImportController.php
@@ -38,7 +38,11 @@ class ImportController extends Controller
38 $nbRabbitMessages = $this->getTotalMessageInRabbitQueue('pocket') 38 $nbRabbitMessages = $this->getTotalMessageInRabbitQueue('pocket')
39 + $this->getTotalMessageInRabbitQueue('readability') 39 + $this->getTotalMessageInRabbitQueue('readability')
40 + $this->getTotalMessageInRabbitQueue('wallabag_v1') 40 + $this->getTotalMessageInRabbitQueue('wallabag_v1')
41 + $this->getTotalMessageInRabbitQueue('wallabag_v2'); 41 + $this->getTotalMessageInRabbitQueue('wallabag_v2')
42 + $this->getTotalMessageInRabbitQueue('firefox')
43 + $this->getTotalMessageInRabbitQueue('chrome')
44 + $this->getTotalMessageInRabbitQueue('instapaper')
45 ;
42 } catch (\Exception $e) { 46 } catch (\Exception $e) {
43 $rabbitNotInstalled = true; 47 $rabbitNotInstalled = true;
44 } 48 }
@@ -49,7 +53,11 @@ class ImportController extends Controller
49 $nbRedisMessages = $redis->llen('wallabag.import.pocket') 53 $nbRedisMessages = $redis->llen('wallabag.import.pocket')
50 + $redis->llen('wallabag.import.readability') 54 + $redis->llen('wallabag.import.readability')
51 + $redis->llen('wallabag.import.wallabag_v1') 55 + $redis->llen('wallabag.import.wallabag_v1')
52 + $redis->llen('wallabag.import.wallabag_v2'); 56 + $redis->llen('wallabag.import.wallabag_v2')
57 + $redis->llen('wallabag.import.firefox')
58 + $redis->llen('wallabag.import.chrome')
59 + $redis->llen('wallabag.import.instapaper')
60 ;
53 } catch (\Exception $e) { 61 } catch (\Exception $e) {
54 $redisNotInstalled = true; 62 $redisNotInstalled = true;
55 } 63 }
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}