aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller/PocketController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller/PocketController.php')
-rw-r--r--src/Wallabag/ImportBundle/Controller/PocketController.php27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php
index c88e115e..11ce649d 100644
--- a/src/Wallabag/ImportBundle/Controller/PocketController.php
+++ b/src/Wallabag/ImportBundle/Controller/PocketController.php
@@ -17,8 +17,8 @@ class PocketController extends Controller
17 { 17 {
18 $pocket = $this->get('wallabag_import.pocket.import'); 18 $pocket = $this->get('wallabag_import.pocket.import');
19 $form = $this->createFormBuilder($pocket) 19 $form = $this->createFormBuilder($pocket)
20 ->add('read', CheckboxType::class, array( 20 ->add('mark_as_read', CheckboxType::class, array(
21 'label' => 'Mark all as read', 21 'label' => 'import.form.mark_as_read_label',
22 'required' => false, 22 'required' => false,
23 )) 23 ))
24 ->getForm(); 24 ->getForm();
@@ -38,8 +38,17 @@ class PocketController extends Controller
38 $requestToken = $this->get('wallabag_import.pocket.import') 38 $requestToken = $this->get('wallabag_import.pocket.import')
39 ->getRequestToken($this->generateUrl('import', array(), UrlGeneratorInterface::ABSOLUTE_URL)); 39 ->getRequestToken($this->generateUrl('import', array(), UrlGeneratorInterface::ABSOLUTE_URL));
40 40
41 if (false === $requestToken) {
42 $this->get('session')->getFlashBag()->add(
43 'notice',
44 'flashes.import.notice.failed'
45 );
46
47 return $this->redirect($this->generateUrl('import_pocket'));
48 }
49
41 $this->get('session')->set('import.pocket.code', $requestToken); 50 $this->get('session')->set('import.pocket.code', $requestToken);
42 $this->get('session')->set('read', $request->request->get('form')['read']); 51 $this->get('session')->set('mark_as_read', $request->request->get('form')['mark_as_read']);
43 52
44 return $this->redirect( 53 return $this->redirect(
45 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', array(), UrlGeneratorInterface::ABSOLUTE_URL), 54 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', array(), UrlGeneratorInterface::ABSOLUTE_URL),
@@ -52,10 +61,11 @@ class PocketController extends Controller
52 */ 61 */
53 public function callbackAction() 62 public function callbackAction()
54 { 63 {
55 $message = 'Import failed, please try again.'; 64 $message = 'flashes.import.notice.failed';
56 $pocket = $this->get('wallabag_import.pocket.import'); 65 $pocket = $this->get('wallabag_import.pocket.import');
57 $markAsRead = $this->get('session')->get('read'); 66
58 $this->get('session')->remove('read'); 67 $markAsRead = $this->get('session')->get('mark_as_read');
68 $this->get('session')->remove('mark_as_read');
59 69
60 // something bad happend on pocket side 70 // something bad happend on pocket side
61 if (false === $pocket->authorize($this->get('session')->get('import.pocket.code'))) { 71 if (false === $pocket->authorize($this->get('session')->get('import.pocket.code'))) {
@@ -69,7 +79,10 @@ class PocketController extends Controller
69 79
70 if (true === $pocket->setMarkAsRead($markAsRead)->import()) { 80 if (true === $pocket->setMarkAsRead($markAsRead)->import()) {
71 $summary = $pocket->getSummary(); 81 $summary = $pocket->getSummary();
72 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.'; 82 $message = $this->get('translator')->trans('flashes.import.notice.summary', array(
83 '%imported%' => $summary['imported'],
84 '%skipped%' => $summary['skipped'],
85 ));
73 } 86 }
74 87
75 $this->get('session')->getFlashBag()->add( 88 $this->get('session')->getFlashBag()->add(