aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ImportBundle')
-rw-r--r--src/Wallabag/ImportBundle/DependencyInjection/Configuration.php17
-rw-r--r--src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php1
-rw-r--r--src/Wallabag/ImportBundle/Import/PocketImport.php24
-rw-r--r--src/Wallabag/ImportBundle/Resources/config/services.yml1
4 files changed, 10 insertions, 33 deletions
diff --git a/src/Wallabag/ImportBundle/DependencyInjection/Configuration.php b/src/Wallabag/ImportBundle/DependencyInjection/Configuration.php
index 3c14104e..bacaff31 100644
--- a/src/Wallabag/ImportBundle/DependencyInjection/Configuration.php
+++ b/src/Wallabag/ImportBundle/DependencyInjection/Configuration.php
@@ -2,7 +2,6 @@
2 2
3namespace Wallabag\ImportBundle\DependencyInjection; 3namespace Wallabag\ImportBundle\DependencyInjection;
4 4
5use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
6use Symfony\Component\Config\Definition\Builder\TreeBuilder; 5use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7use Symfony\Component\Config\Definition\ConfigurationInterface; 6use Symfony\Component\Config\Definition\ConfigurationInterface;
8 7
@@ -13,22 +12,6 @@ class Configuration implements ConfigurationInterface
13 $treeBuilder = new TreeBuilder(); 12 $treeBuilder = new TreeBuilder();
14 $rootNode = $treeBuilder->root('wallabag_import'); 13 $rootNode = $treeBuilder->root('wallabag_import');
15 14
16 $rootNode
17 ->children()
18 ->arrayNode('importers')
19 ->append($this->getURLs())
20 ->end()
21 ->end()
22 ;
23
24 return $treeBuilder; 15 return $treeBuilder;
25 } 16 }
26
27 private function getURLs()
28 {
29 $node = new ArrayNodeDefinition('pocket_urls');
30 $node->prototype('scalar')->end();
31
32 return $node;
33 }
34} 17}
diff --git a/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php b/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php
index 07dc378d..4efcaace 100644
--- a/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php
+++ b/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php
@@ -13,7 +13,6 @@ class WallabagImportExtension extends Extension
13 { 13 {
14 $configuration = new Configuration(); 14 $configuration = new Configuration();
15 $config = $this->processConfiguration($configuration, $configs); 15 $config = $this->processConfiguration($configuration, $configs);
16 $container->setParameter('wallabag_import.pocket', $config['importers']['pocket_urls']);
17 16
18 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 17 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
19 $loader->load('services.yml'); 18 $loader->load('services.yml');
diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php
index 51f73f4c..dd1c34ab 100644
--- a/src/Wallabag/ImportBundle/Import/PocketImport.php
+++ b/src/Wallabag/ImportBundle/Import/PocketImport.php
@@ -15,19 +15,15 @@ class PocketImport implements ImportInterface
15 private $session; 15 private $session;
16 private $em; 16 private $em;
17 private $consumerKey; 17 private $consumerKey;
18 private $skippedEntries; 18 private $skippedEntries = 0;
19 private $importedEntries; 19 private $importedEntries = 0;
20 private $pocketURL;
21 20
22 public function __construct($tokenStorage, Session $session, EntityManager $em, $consumerKey, $pocketURL) 21 public function __construct($tokenStorage, Session $session, EntityManager $em, $consumerKey)
23 { 22 {
24 $this->user = $tokenStorage->getToken()->getUser(); 23 $this->user = $tokenStorage->getToken()->getUser();
25 $this->session = $session; 24 $this->session = $session;
26 $this->em = $em; 25 $this->em = $em;
27 $this->consumerKey = $consumerKey; 26 $this->consumerKey = $consumerKey;
28 $this->skippedEntries = 0;
29 $this->importedEntries = 0;
30 $this->pocketURL = $pocketURL;
31 } 27 }
32 28
33 public function getName() 29 public function getName()
@@ -121,9 +117,9 @@ class PocketImport implements ImportInterface
121 117
122 $existingEntry = $this->em 118 $existingEntry = $this->em
123 ->getRepository('WallabagCoreBundle:Entry') 119 ->getRepository('WallabagCoreBundle:Entry')
124 ->findOneByUrl($url); 120 ->findOneByUrlAndUserId($url, $this->user->getId());
125 121
126 if (!is_null($existingEntry)) { 122 if (count($existingEntry) > 0) {
127 ++$this->skippedEntries; 123 ++$this->skippedEntries;
128 continue; 124 continue;
129 } 125 }
@@ -153,7 +149,7 @@ class PocketImport implements ImportInterface
153 } 149 }
154 150
155 if (!empty($pocketEntry['tags'])) { 151 if (!empty($pocketEntry['tags'])) {
156 // $this->assignTagsToEntry($entry, $pocketEntry['tags']); 152 $this->assignTagsToEntry($entry, $pocketEntry['tags']);
157 } 153 }
158 154
159 $this->em->persist($entry); 155 $this->em->persist($entry);
@@ -166,7 +162,7 @@ class PocketImport implements ImportInterface
166 public function oAuthRequest($redirectUri, $callbackUri) 162 public function oAuthRequest($redirectUri, $callbackUri)
167 { 163 {
168 $client = $this->createClient(); 164 $client = $this->createClient();
169 $request = $client->createRequest('POST', $this->pocketURL['oauth_request'], 165 $request = $client->createRequest('POST', 'https://getpocket.com/v3/oauth/request',
170 [ 166 [
171 'body' => json_encode([ 167 'body' => json_encode([
172 'consumer_key' => $this->consumerKey, 168 'consumer_key' => $this->consumerKey,
@@ -181,14 +177,14 @@ class PocketImport implements ImportInterface
181 // store code in session for callback method 177 // store code in session for callback method
182 $this->session->set('pocketCode', $values['code']); 178 $this->session->set('pocketCode', $values['code']);
183 179
184 return $this->pocketURL['auth_authorize'].'?request_token='.$values['code'].'&redirect_uri='.$callbackUri; 180 return 'https://getpocket.com/auth/authorize?request_token='.$values['code'].'&redirect_uri='.$callbackUri;
185 } 181 }
186 182
187 public function oAuthAuthorize() 183 public function oAuthAuthorize()
188 { 184 {
189 $client = $this->createClient(); 185 $client = $this->createClient();
190 186
191 $request = $client->createRequest('POST', $this->pocketURL['oauth_authorize'], 187 $request = $client->createRequest('POST', 'https://getpocket.com/v3/oauth/authorize',
192 [ 188 [
193 'body' => json_encode([ 189 'body' => json_encode([
194 'consumer_key' => $this->consumerKey, 190 'consumer_key' => $this->consumerKey,
@@ -206,7 +202,7 @@ class PocketImport implements ImportInterface
206 { 202 {
207 $client = $this->createClient(); 203 $client = $this->createClient();
208 204
209 $request = $client->createRequest('POST', $this->pocketURL['get'], 205 $request = $client->createRequest('POST', 'https://getpocket.com/v3/get',
210 [ 206 [
211 'body' => json_encode([ 207 'body' => json_encode([
212 'consumer_key' => $this->consumerKey, 208 'consumer_key' => $this->consumerKey,
diff --git a/src/Wallabag/ImportBundle/Resources/config/services.yml b/src/Wallabag/ImportBundle/Resources/config/services.yml
index 8f224d88..82628f08 100644
--- a/src/Wallabag/ImportBundle/Resources/config/services.yml
+++ b/src/Wallabag/ImportBundle/Resources/config/services.yml
@@ -6,4 +6,3 @@ services:
6 - @session 6 - @session
7 - @doctrine.orm.entity_manager 7 - @doctrine.orm.entity_manager
8 - %pocket_consumer_key% 8 - %pocket_consumer_key%
9 - %wallabag_import.pocket%