aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller/PocketController.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-12-30 12:23:51 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-01-02 23:27:41 +0100
commit252ebd60719d32ec954d0519c9edf2b52b03310c (patch)
tree044c97abeda75c33901d8bfcd33fa107279b1778 /src/Wallabag/ImportBundle/Controller/PocketController.php
parentb4b592a0c0ee356e81775baf8f9976288d7b686c (diff)
downloadwallabag-252ebd60719d32ec954d0519c9edf2b52b03310c.tar.gz
wallabag-252ebd60719d32ec954d0519c9edf2b52b03310c.tar.zst
wallabag-252ebd60719d32ec954d0519c9edf2b52b03310c.zip
Rewrote Pocket Import
For the moment, we won't do a queue system, just a plain synchronous import. We also use ContentProxy to grab content for each article from Pocket. Error from Pocket are now logged using the logger. The ImportInterface need to be simple and not related to oAuth (not all import will use that method).
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller/PocketController.php')
-rw-r--r--src/Wallabag/ImportBundle/Controller/PocketController.php45
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;
8class PocketController extends Controller 8class 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 }