aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas.loeuillet@smile.fr>2015-10-26 15:49:44 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-01-02 23:27:41 +0100
commit303768dfe9b85f87d043eb225c5c8c3a88d8c051 (patch)
tree8e29ed85236f012ac4a18b01e271a97800d98fa7 /src
parentdda57bb9443817e3a080d5d25343f5a7e15dd14f (diff)
downloadwallabag-303768dfe9b85f87d043eb225c5c8c3a88d8c051.tar.gz
wallabag-303768dfe9b85f87d043eb225c5c8c3a88d8c051.tar.zst
wallabag-303768dfe9b85f87d043eb225c5c8c3a88d8c051.zip
- remove importers configuration
- add check on userId for findOneByURL for entries
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php8
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php17
-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
6 files changed, 31 insertions, 37 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index de2eedcb..9097810c 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -51,15 +51,15 @@ class EntryController extends Controller
51 if ($form->isValid()) { 51 if ($form->isValid()) {
52 $existingEntry = $em 52 $existingEntry = $em
53 ->getRepository('WallabagCoreBundle:Entry') 53 ->getRepository('WallabagCoreBundle:Entry')
54 ->findOneByUrl($entry->getUrl()); 54 ->findOneByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
55 55
56 if (!is_null($existingEntry)) { 56 if (count($existingEntry) > 0) {
57 $this->get('session')->getFlashBag()->add( 57 $this->get('session')->getFlashBag()->add(
58 'notice', 58 'notice',
59 'Entry already saved on '.$existingEntry->getCreatedAt()->format('d-m-Y') 59 'Entry already saved on '.$existingEntry[0]->getCreatedAt()->format('d-m-Y')
60 ); 60 );
61 61
62 return $this->redirect($this->generateUrl('view', array('id' => $existingEntry->getId()))); 62 return $this->redirect($this->generateUrl('view', array('id' => $existingEntry[0]->getId())));
63 } 63 }
64 64
65 $this->updateEntry($entry); 65 $this->updateEntry($entry);
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index ca71970b..502e9da0 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -223,4 +223,21 @@ class EntryRepository extends EntityRepository
223 ->getQuery() 223 ->getQuery()
224 ->getResult(); 224 ->getResult();
225 } 225 }
226
227 /**
228 * Find an entry by its url and its owner.
229 *
230 * @param $url
231 * @param $userId
232 *
233 * @return array
234 */
235 public function findOneByUrlAndUserId($url, $userId)
236 {
237 return $this->createQueryBuilder('e')
238 ->where('e.url = :url')->setParameter('url', $url)
239 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
240 ->getQuery()
241 ->getResult();
242 }
226} 243}
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%