]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/ImportBundle/Controller/PocketController.php
Rewrote Wallabag v1 import
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Controller / PocketController.php
CommitLineData
1f4408de
NL
1<?php
2
3namespace Wallabag\ImportBundle\Controller;
4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
1f4408de
NL
7
8class PocketController extends Controller
9{
10 /**
252ebd60 11 * @Route("/import/pocket", name="import_pocket")
1f4408de 12 */
d51b38ed 13 public function indexAction()
1f4408de 14 {
252ebd60 15 return $this->render('WallabagImportBundle:Pocket:index.html.twig', []);
1f4408de
NL
16 }
17
1f4408de 18 /**
252ebd60 19 * @Route("/import/pocket/auth", name="import_pocket_auth")
1f4408de
NL
20 */
21 public function authAction()
22 {
252ebd60
JB
23 $requestToken = $this->get('wallabag_import.pocket.import')
24 ->getRequestToken($this->generateUrl('import', [], true));
25
26 $this->get('session')->set('import.pocket.code', $requestToken);
1f4408de 27
252ebd60
JB
28 return $this->redirect(
29 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', [], true),
30 301
31 );
1f4408de
NL
32 }
33
34 /**
252ebd60 35 * @Route("/import/pocket/callback", name="import_pocket_callback")
1f4408de
NL
36 */
37 public function callbackAction()
38 {
252ebd60 39 $message = 'Import failed, please try again.';
0aa344dc 40 $pocket = $this->get('wallabag_import.pocket.import');
252ebd60
JB
41
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();
b1d05721 54 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.';
252ebd60
JB
55 }
56
57 $this->get('session')->getFlashBag()->add(
58 'notice',
59 $message
60 );
1f4408de
NL
61
62 return $this->redirect($this->generateUrl('homepage'));
63 }
1f4408de 64}