diff options
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller/PocketController.php')
-rw-r--r-- | src/Wallabag/ImportBundle/Controller/PocketController.php | 18 |
1 files changed, 16 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; | |||
5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
6 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | 6 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
8 | use Symfony\Component\HttpFoundation\Request; | ||
9 | use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | ||
8 | 10 | ||
9 | class PocketController extends Controller | 11 | class 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 | } |