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