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