class PocketController extends Controller
{
/**
- * @Route("/import/pocket", name="pocket")
+ * @Route("/import/pocket", name="pocket_import")
*/
public function indexAction()
{
}
/**
- * @Route("/import/pocket/auth", name="authpocket")
+ * @Route("/import/pocket/auth", name="pocket_auth")
*/
public function authAction()
{
- $pocket = $this->get('wallabag_import.import.pocket_import');
- $authUrl = $pocket->oAuthRequest($this->generateUrl('import', array(), true), $this->generateUrl('callbackpocket', array(), true));
+ $pocket = $this->get('wallabag_import.pocket.import');
+ $authUrl = $pocket->oAuthRequest(
+ $this->generateUrl('import', array(), true),
+ $this->generateUrl('pocket_callback', array(), true)
+ );
return $this->redirect($authUrl, 301);
}
/**
- * @Route("/import/pocket/callback", name="callbackpocket")
+ * @Route("/import/pocket/callback", name="pocket_callback")
*/
public function callbackAction()
{
- $pocket = $this->get('wallabag_import.import.pocket_import');
+ $pocket = $this->get('wallabag_import.pocket.import');
$accessToken = $pocket->oAuthAuthorize();
$pocket->import($accessToken);
interface ImportInterface
{
+ /**
+ * Name of the import.
+ *
+ * @return string
+ */
public function getName();
+
+ /**
+ * Description of the import.
+ *
+ * @return string
+ */
public function getDescription();
+
+ /**
+ * Return the oauth url to authenticate the client.
+ *
+ * @param string $redirectUri Redirect url in case of error
+ * @param string $callbackUri Url when the authentication is complete
+ *
+ * @return string
+ */
public function oAuthRequest($redirectUri, $callbackUri);
+
+ /**
+ * Usually called by the previous callback to authorize the client.
+ * Then it return a token that can be used for next requests.
+ *
+ * @return string
+ */
public function oAuthAuthorize();
+
+ /**
+ * Import content using the user token.
+ *
+ * @param string $accessToken User access token
+ */
public function import($accessToken);
}
use Doctrine\ORM\EntityManager;
use GuzzleHttp\Client;
use Symfony\Component\HttpFoundation\Session\Session;
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag;
use Wallabag\CoreBundle\Tools\Utils;
private $skippedEntries = 0;
private $importedEntries = 0;
- public function __construct($tokenStorage, Session $session, EntityManager $em, $consumerKey)
+ public function __construct(TokenStorageInterface $tokenStorage, Session $session, EntityManager $em, $consumerKey)
{
$this->user = $tokenStorage->getToken()->getUser();
$this->session = $session;
$this->consumerKey = $consumerKey;
}
+ /**
+ * {@inheritdoc}
+ */
public function getName()
{
return 'Pocket';
}
+ /**
+ * {@inheritdoc}
+ */
public function getDescription()
{
return 'This importer will import all your <a href="https://getpocket.com">Pocket</a> data.';
services:
- wallabag_import.import.pocket_import:
+ wallabag_import.pocket.import:
class: Wallabag\ImportBundle\Import\PocketImport
arguments:
- - @security.token_storage
- - @session
- - @doctrine.orm.entity_manager
+ - "@security.token_storage"
+ - "@session"
+ - "@doctrine.orm.entity_manager"
- %pocket_consumer_key%
<div class="card-panel settings">
{% trans %}Welcome on wallabag importer. Please select your previous service that you want to migrate.{% endtrans %}
<ul>
- <li><a href="{{ path('pocket') }}">Pocket</a></li>
+ <li><a href="{{ path('pocket_import') }}">Pocket</a></li>
</ul>
</div>
</div>
<div class="col s12">
<div class="card-panel settings">
{% 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 %}
- <form method="post" action="{{ path('authpocket') }}">
+ <form method="post" action="{{ path('pocket_auth') }}">
<input type="submit" value="Connect to Pocket and import data" />
</form>
</div>