aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller')
-rw-r--r--src/Wallabag/ImportBundle/Controller/PocketController.php18
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php3
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php2
3 files changed, 21 insertions, 2 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php
index 1c1b4fa8..c88e115e 100644
--- a/src/Wallabag/ImportBundle/Controller/PocketController.php
+++ b/src/Wallabag/ImportBundle/Controller/PocketController.php
@@ -5,6 +5,8 @@ namespace Wallabag\ImportBundle\Controller;
5use Symfony\Bundle\FrameworkBundle\Controller\Controller; 5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 6use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8use Symfony\Component\HttpFoundation\Request;
9use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
8 10
9class PocketController extends Controller 11class PocketController extends Controller
10{ 12{
@@ -13,21 +15,31 @@ class PocketController extends Controller
13 */ 15 */
14 public function indexAction() 16 public function indexAction()
15 { 17 {
18 $pocket = $this->get('wallabag_import.pocket.import');
19 $form = $this->createFormBuilder($pocket)
20 ->add('read', CheckboxType::class, array(
21 'label' => 'Mark all as read',
22 'required' => false,
23 ))
24 ->getForm();
25
16 return $this->render('WallabagImportBundle:Pocket:index.html.twig', [ 26 return $this->render('WallabagImportBundle:Pocket:index.html.twig', [
17 'import' => $this->get('wallabag_import.pocket.import'), 27 'import' => $this->get('wallabag_import.pocket.import'),
18 'has_consumer_key' => '' == trim($this->get('craue_config')->get('pocket_consumer_key')) ? false : true, 28 'has_consumer_key' => '' == trim($this->get('craue_config')->get('pocket_consumer_key')) ? false : true,
29 'form' => $form->createView(),
19 ]); 30 ]);
20 } 31 }
21 32
22 /** 33 /**
23 * @Route("/pocket/auth", name="import_pocket_auth") 34 * @Route("/pocket/auth", name="import_pocket_auth")
24 */ 35 */
25 public function authAction() 36 public function authAction(Request $request)
26 { 37 {
27 $requestToken = $this->get('wallabag_import.pocket.import') 38 $requestToken = $this->get('wallabag_import.pocket.import')
28 ->getRequestToken($this->generateUrl('import', array(), UrlGeneratorInterface::ABSOLUTE_URL)); 39 ->getRequestToken($this->generateUrl('import', array(), UrlGeneratorInterface::ABSOLUTE_URL));
29 40
30 $this->get('session')->set('import.pocket.code', $requestToken); 41 $this->get('session')->set('import.pocket.code', $requestToken);
42 $this->get('session')->set('read', $request->request->get('form')['read']);
31 43
32 return $this->redirect( 44 return $this->redirect(
33 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', array(), UrlGeneratorInterface::ABSOLUTE_URL), 45 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', array(), UrlGeneratorInterface::ABSOLUTE_URL),
@@ -42,6 +54,8 @@ class PocketController extends Controller
42 { 54 {
43 $message = 'Import failed, please try again.'; 55 $message = 'Import failed, please try again.';
44 $pocket = $this->get('wallabag_import.pocket.import'); 56 $pocket = $this->get('wallabag_import.pocket.import');
57 $markAsRead = $this->get('session')->get('read');
58 $this->get('session')->remove('read');
45 59
46 // something bad happend on pocket side 60 // something bad happend on pocket side
47 if (false === $pocket->authorize($this->get('session')->get('import.pocket.code'))) { 61 if (false === $pocket->authorize($this->get('session')->get('import.pocket.code'))) {
@@ -53,7 +67,7 @@ class PocketController extends Controller
53 return $this->redirect($this->generateUrl('import_pocket')); 67 return $this->redirect($this->generateUrl('import_pocket'));
54 } 68 }
55 69
56 if (true === $pocket->import()) { 70 if (true === $pocket->setMarkAsRead($markAsRead)->import()) {
57 $summary = $pocket->getSummary(); 71 $summary = $pocket->getSummary();
58 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.'; 72 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.';
59 } 73 }
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
index 35fe620f..154a0769 100644
--- a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
+++ b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
@@ -21,15 +21,18 @@ class WallabagV1Controller extends Controller
21 21
22 if ($form->isValid()) { 22 if ($form->isValid()) {
23 $file = $form->get('file')->getData(); 23 $file = $form->get('file')->getData();
24 $markAsRead = $form->get('mark_as_read')->getData();
24 $name = $this->getUser()->getId().'.json'; 25 $name = $this->getUser()->getId().'.json';
25 26
26 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 27 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
27 $res = $wallabag 28 $res = $wallabag
28 ->setUser($this->getUser()) 29 ->setUser($this->getUser())
29 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 30 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
31 ->setMarkAsRead($markAsRead)
30 ->import(); 32 ->import();
31 33
32 $message = 'Import failed, please try again.'; 34 $message = 'Import failed, please try again.';
35
33 if (true === $res) { 36 if (true === $res) {
34 $summary = $wallabag->getSummary(); 37 $summary = $wallabag->getSummary();
35 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.'; 38 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.';
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
index 2e6225f2..6dcd204a 100644
--- a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
+++ b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
@@ -21,12 +21,14 @@ class WallabagV2Controller extends Controller
21 21
22 if ($form->isValid()) { 22 if ($form->isValid()) {
23 $file = $form->get('file')->getData(); 23 $file = $form->get('file')->getData();
24 $markAsRead = $form->get('mark_as_read')->getData();
24 $name = $this->getUser()->getId().'.json'; 25 $name = $this->getUser()->getId().'.json';
25 26
26 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 27 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
27 $res = $wallabag 28 $res = $wallabag
28 ->setUser($this->getUser()) 29 ->setUser($this->getUser())
29 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 30 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
31 ->setMarkAsRead($markAsRead)
30 ->import(); 32 ->import();
31 33
32 $message = 'Import failed, please try again.'; 34 $message = 'Import failed, please try again.';