aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ImportBundle')
-rw-r--r--src/Wallabag/ImportBundle/Controller/PocketController.php15
-rw-r--r--src/Wallabag/ImportBundle/Import/ImportInterface.php33
-rw-r--r--src/Wallabag/ImportBundle/Import/PocketImport.php9
-rw-r--r--src/Wallabag/ImportBundle/Resources/config/services.yml8
-rw-r--r--src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig2
-rw-r--r--src/Wallabag/ImportBundle/Resources/views/Pocket/index.html.twig2
6 files changed, 56 insertions, 13 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php
index f851c81c..2ab062e7 100644
--- a/src/Wallabag/ImportBundle/Controller/PocketController.php
+++ b/src/Wallabag/ImportBundle/Controller/PocketController.php
@@ -8,7 +8,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8class PocketController extends Controller 8class PocketController extends Controller
9{ 9{
10 /** 10 /**
11 * @Route("/import/pocket", name="pocket") 11 * @Route("/import/pocket", name="pocket_import")
12 */ 12 */
13 public function indexAction() 13 public function indexAction()
14 { 14 {
@@ -16,22 +16,25 @@ class PocketController extends Controller
16 } 16 }
17 17
18 /** 18 /**
19 * @Route("/import/pocket/auth", name="authpocket") 19 * @Route("/import/pocket/auth", name="pocket_auth")
20 */ 20 */
21 public function authAction() 21 public function authAction()
22 { 22 {
23 $pocket = $this->get('wallabag_import.import.pocket_import'); 23 $pocket = $this->get('wallabag_import.pocket.import');
24 $authUrl = $pocket->oAuthRequest($this->generateUrl('import', array(), true), $this->generateUrl('callbackpocket', array(), true)); 24 $authUrl = $pocket->oAuthRequest(
25 $this->generateUrl('import', array(), true),
26 $this->generateUrl('pocket_callback', array(), true)
27 );
25 28
26 return $this->redirect($authUrl, 301); 29 return $this->redirect($authUrl, 301);
27 } 30 }
28 31
29 /** 32 /**
30 * @Route("/import/pocket/callback", name="callbackpocket") 33 * @Route("/import/pocket/callback", name="pocket_callback")
31 */ 34 */
32 public function callbackAction() 35 public function callbackAction()
33 { 36 {
34 $pocket = $this->get('wallabag_import.import.pocket_import'); 37 $pocket = $this->get('wallabag_import.pocket.import');
35 $accessToken = $pocket->oAuthAuthorize(); 38 $accessToken = $pocket->oAuthAuthorize();
36 $pocket->import($accessToken); 39 $pocket->import($accessToken);
37 40
diff --git a/src/Wallabag/ImportBundle/Import/ImportInterface.php b/src/Wallabag/ImportBundle/Import/ImportInterface.php
index f07a120c..0f9b3256 100644
--- a/src/Wallabag/ImportBundle/Import/ImportInterface.php
+++ b/src/Wallabag/ImportBundle/Import/ImportInterface.php
@@ -4,9 +4,42 @@ namespace Wallabag\ImportBundle\Import;
4 4
5interface ImportInterface 5interface ImportInterface
6{ 6{
7 /**
8 * Name of the import.
9 *
10 * @return string
11 */
7 public function getName(); 12 public function getName();
13
14 /**
15 * Description of the import.
16 *
17 * @return string
18 */
8 public function getDescription(); 19 public function getDescription();
20
21 /**
22 * Return the oauth url to authenticate the client.
23 *
24 * @param string $redirectUri Redirect url in case of error
25 * @param string $callbackUri Url when the authentication is complete
26 *
27 * @return string
28 */
9 public function oAuthRequest($redirectUri, $callbackUri); 29 public function oAuthRequest($redirectUri, $callbackUri);
30
31 /**
32 * Usually called by the previous callback to authorize the client.
33 * Then it return a token that can be used for next requests.
34 *
35 * @return string
36 */
10 public function oAuthAuthorize(); 37 public function oAuthAuthorize();
38
39 /**
40 * Import content using the user token.
41 *
42 * @param string $accessToken User access token
43 */
11 public function import($accessToken); 44 public function import($accessToken);
12} 45}
diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php
index ef8f9eb5..85bab0db 100644
--- a/src/Wallabag/ImportBundle/Import/PocketImport.php
+++ b/src/Wallabag/ImportBundle/Import/PocketImport.php
@@ -5,6 +5,7 @@ namespace Wallabag\ImportBundle\Import;
5use Doctrine\ORM\EntityManager; 5use Doctrine\ORM\EntityManager;
6use GuzzleHttp\Client; 6use GuzzleHttp\Client;
7use Symfony\Component\HttpFoundation\Session\Session; 7use Symfony\Component\HttpFoundation\Session\Session;
8use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
8use Wallabag\CoreBundle\Entity\Entry; 9use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\CoreBundle\Entity\Tag; 10use Wallabag\CoreBundle\Entity\Tag;
10use Wallabag\CoreBundle\Tools\Utils; 11use Wallabag\CoreBundle\Tools\Utils;
@@ -18,7 +19,7 @@ class PocketImport implements ImportInterface
18 private $skippedEntries = 0; 19 private $skippedEntries = 0;
19 private $importedEntries = 0; 20 private $importedEntries = 0;
20 21
21 public function __construct($tokenStorage, Session $session, EntityManager $em, $consumerKey) 22 public function __construct(TokenStorageInterface $tokenStorage, Session $session, EntityManager $em, $consumerKey)
22 { 23 {
23 $this->user = $tokenStorage->getToken()->getUser(); 24 $this->user = $tokenStorage->getToken()->getUser();
24 $this->session = $session; 25 $this->session = $session;
@@ -26,11 +27,17 @@ class PocketImport implements ImportInterface
26 $this->consumerKey = $consumerKey; 27 $this->consumerKey = $consumerKey;
27 } 28 }
28 29
30 /**
31 * {@inheritdoc}
32 */
29 public function getName() 33 public function getName()
30 { 34 {
31 return 'Pocket'; 35 return 'Pocket';
32 } 36 }
33 37
38 /**
39 * {@inheritdoc}
40 */
34 public function getDescription() 41 public function getDescription()
35 { 42 {
36 return 'This importer will import all your <a href="https://getpocket.com">Pocket</a> data.'; 43 return 'This importer will import all your <a href="https://getpocket.com">Pocket</a> data.';
diff --git a/src/Wallabag/ImportBundle/Resources/config/services.yml b/src/Wallabag/ImportBundle/Resources/config/services.yml
index 82628f08..d77779eb 100644
--- a/src/Wallabag/ImportBundle/Resources/config/services.yml
+++ b/src/Wallabag/ImportBundle/Resources/config/services.yml
@@ -1,8 +1,8 @@
1services: 1services:
2 wallabag_import.import.pocket_import: 2 wallabag_import.pocket.import:
3 class: Wallabag\ImportBundle\Import\PocketImport 3 class: Wallabag\ImportBundle\Import\PocketImport
4 arguments: 4 arguments:
5 - @security.token_storage 5 - "@security.token_storage"
6 - @session 6 - "@session"
7 - @doctrine.orm.entity_manager 7 - "@doctrine.orm.entity_manager"
8 - %pocket_consumer_key% 8 - %pocket_consumer_key%
diff --git a/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig b/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig
index bdd57e5e..fda21f2d 100644
--- a/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig
+++ b/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig
@@ -8,7 +8,7 @@
8 <div class="card-panel settings"> 8 <div class="card-panel settings">
9 {% trans %}Welcome on wallabag importer. Please select your previous service that you want to migrate.{% endtrans %} 9 {% trans %}Welcome on wallabag importer. Please select your previous service that you want to migrate.{% endtrans %}
10 <ul> 10 <ul>
11 <li><a href="{{ path('pocket') }}">Pocket</a></li> 11 <li><a href="{{ path('pocket_import') }}">Pocket</a></li>
12 </ul> 12 </ul>
13 </div> 13 </div>
14 </div> 14 </div>
diff --git a/src/Wallabag/ImportBundle/Resources/views/Pocket/index.html.twig b/src/Wallabag/ImportBundle/Resources/views/Pocket/index.html.twig
index e6abc17b..df64e472 100644
--- a/src/Wallabag/ImportBundle/Resources/views/Pocket/index.html.twig
+++ b/src/Wallabag/ImportBundle/Resources/views/Pocket/index.html.twig
@@ -7,7 +7,7 @@
7 <div class="col s12"> 7 <div class="col s12">
8 <div class="card-panel settings"> 8 <div class="card-panel settings">
9 {% trans %}You can import your data from your Pocket account. You just have to click on the below button and authorize the application to connect to getpocket.com.{% endtrans %} 9 {% trans %}You can import your data from your Pocket account. You just have to click on the below button and authorize the application to connect to getpocket.com.{% endtrans %}
10 <form method="post" action="{{ path('authpocket') }}"> 10 <form method="post" action="{{ path('pocket_auth') }}">
11 <input type="submit" value="Connect to Pocket and import data" /> 11 <input type="submit" value="Connect to Pocket and import data" />
12 </form> 12 </form>
13 </div> 13 </div>