]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/ImportBundle/Controller/PocketController.php
Merge pull request #1524 from wallabag/sf2.8
[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;
1d76102a 6use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1f4408de 7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
1f4408de
NL
8
9class PocketController extends Controller
10{
11 /**
7019c7cf 12 * @Route("/pocket", name="import_pocket")
1f4408de 13 */
d51b38ed 14 public function indexAction()
1f4408de 15 {
7019c7cf
JB
16 return $this->render('WallabagImportBundle:Pocket:index.html.twig', [
17 'import' => $this->get('wallabag_import.pocket.import'),
18 ]);
1f4408de
NL
19 }
20
1f4408de 21 /**
7019c7cf 22 * @Route("/pocket/auth", name="import_pocket_auth")
1f4408de
NL
23 */
24 public function authAction()
25 {
252ebd60 26 $requestToken = $this->get('wallabag_import.pocket.import')
27e475a9 27 ->getRequestToken($this->generateUrl('import', array(), UrlGeneratorInterface::ABSOLUTE_URL));
252ebd60
JB
28
29 $this->get('session')->set('import.pocket.code', $requestToken);
1f4408de 30
252ebd60 31 return $this->redirect(
27e475a9 32 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', array(), UrlGeneratorInterface::ABSOLUTE_URL),
252ebd60
JB
33 301
34 );
1f4408de
NL
35 }
36
37 /**
7019c7cf 38 * @Route("/pocket/callback", name="import_pocket_callback")
1f4408de
NL
39 */
40 public function callbackAction()
41 {
252ebd60 42 $message = 'Import failed, please try again.';
0aa344dc 43 $pocket = $this->get('wallabag_import.pocket.import');
252ebd60
JB
44
45 // something bad happend on pocket side
46 if (false === $pocket->authorize($this->get('session')->get('import.pocket.code'))) {
47 $this->get('session')->getFlashBag()->add(
48 'notice',
49 $message
50 );
51
52 return $this->redirect($this->generateUrl('import_pocket'));
53 }
54
55 if (true === $pocket->import()) {
56 $summary = $pocket->getSummary();
b1d05721 57 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.';
252ebd60
JB
58 }
59
60 $this->get('session')->getFlashBag()->add(
61 'notice',
62 $message
63 );
1f4408de
NL
64
65 return $this->redirect($this->generateUrl('homepage'));
66 }
1f4408de 67}