diff options
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller/PocketController.php')
-rw-r--r-- | src/Wallabag/ImportBundle/Controller/PocketController.php | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php index 2ab062e7..61eeba43 100644 --- a/src/Wallabag/ImportBundle/Controller/PocketController.php +++ b/src/Wallabag/ImportBundle/Controller/PocketController.php | |||
@@ -8,35 +8,56 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |||
8 | class PocketController extends Controller | 8 | class PocketController extends Controller |
9 | { | 9 | { |
10 | /** | 10 | /** |
11 | * @Route("/import/pocket", name="pocket_import") | 11 | * @Route("/import/pocket", name="import_pocket") |
12 | */ | 12 | */ |
13 | public function indexAction() | 13 | public function indexAction() |
14 | { | 14 | { |
15 | return $this->render('WallabagImportBundle:Pocket:index.html.twig', array()); | 15 | return $this->render('WallabagImportBundle:Pocket:index.html.twig', []); |
16 | } | 16 | } |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * @Route("/import/pocket/auth", name="pocket_auth") | 19 | * @Route("/import/pocket/auth", name="import_pocket_auth") |
20 | */ | 20 | */ |
21 | public function authAction() | 21 | public function authAction() |
22 | { | 22 | { |
23 | $pocket = $this->get('wallabag_import.pocket.import'); | 23 | $requestToken = $this->get('wallabag_import.pocket.import') |
24 | $authUrl = $pocket->oAuthRequest( | 24 | ->getRequestToken($this->generateUrl('import', [], true)); |
25 | $this->generateUrl('import', array(), true), | 25 | |
26 | $this->generateUrl('pocket_callback', array(), true) | 26 | $this->get('session')->set('import.pocket.code', $requestToken); |
27 | ); | ||
28 | 27 | ||
29 | return $this->redirect($authUrl, 301); | 28 | return $this->redirect( |
29 | 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', [], true), | ||
30 | 301 | ||
31 | ); | ||
30 | } | 32 | } |
31 | 33 | ||
32 | /** | 34 | /** |
33 | * @Route("/import/pocket/callback", name="pocket_callback") | 35 | * @Route("/import/pocket/callback", name="import_pocket_callback") |
34 | */ | 36 | */ |
35 | public function callbackAction() | 37 | public function callbackAction() |
36 | { | 38 | { |
39 | $message = 'Import failed, please try again.'; | ||
37 | $pocket = $this->get('wallabag_import.pocket.import'); | 40 | $pocket = $this->get('wallabag_import.pocket.import'); |
38 | $accessToken = $pocket->oAuthAuthorize(); | 41 | |
39 | $pocket->import($accessToken); | 42 | // something bad happend on pocket side |
43 | if (false === $pocket->authorize($this->get('session')->get('import.pocket.code'))) { | ||
44 | $this->get('session')->getFlashBag()->add( | ||
45 | 'notice', | ||
46 | $message | ||
47 | ); | ||
48 | |||
49 | return $this->redirect($this->generateUrl('import_pocket')); | ||
50 | } | ||
51 | |||
52 | if (true === $pocket->import()) { | ||
53 | $summary = $pocket->getSummary(); | ||
54 | $message = $summary['imported'].' entrie(s) imported, '.$summary['skipped'].' already saved.'; | ||
55 | } | ||
56 | |||
57 | $this->get('session')->getFlashBag()->add( | ||
58 | 'notice', | ||
59 | $message | ||
60 | ); | ||
40 | 61 | ||
41 | return $this->redirect($this->generateUrl('homepage')); | 62 | return $this->redirect($this->generateUrl('homepage')); |
42 | } | 63 | } |