]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
- remove importers configuration
authorNicolas LÅ“uillet <nicolas.loeuillet@smile.fr>
Mon, 26 Oct 2015 14:49:44 +0000 (15:49 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 2 Jan 2016 22:27:41 +0000 (23:27 +0100)
- add check on userId for findOneByURL for entries

app/config/config.yml
src/Wallabag/CoreBundle/Controller/EntryController.php
src/Wallabag/CoreBundle/Repository/EntryRepository.php
src/Wallabag/ImportBundle/DependencyInjection/Configuration.php
src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php
src/Wallabag/ImportBundle/Import/PocketImport.php
src/Wallabag/ImportBundle/Resources/config/services.yml

index 88b1a59fc910b9c30e4addc40bc17b21f77895b3..421b2db5a527c213c3fd8343350a26768516269d 100644 (file)
@@ -33,14 +33,6 @@ wallabag_core:
     import:
         allow_mimetypes: ['application/octet-stream', 'application/json', 'text/plain']
 
-wallabag_import:
-    importers:
-        pocket_urls:
-            oauth_request: https://getpocket.com/v3/oauth/request
-            auth_authorize: https://getpocket.com/auth/authorize
-            oauth_authorize: https://getpocket.com/v3/oauth/authorize
-            get: https://getpocket.com/v3/get
-
 # Twig Configuration
 twig:
     debug:            "%kernel.debug%"
index de2eedcb75f715bcd0d5e32b2d28799ac412ecda..9097810c22ff4dd3a88f3e8edba3f95d67fda4bf 100644 (file)
@@ -51,15 +51,15 @@ class EntryController extends Controller
         if ($form->isValid()) {
             $existingEntry = $em
                 ->getRepository('WallabagCoreBundle:Entry')
-                ->findOneByUrl($entry->getUrl());
+                ->findOneByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
 
-            if (!is_null($existingEntry)) {
+            if (count($existingEntry) > 0) {
                 $this->get('session')->getFlashBag()->add(
                     'notice',
-                    'Entry already saved on '.$existingEntry->getCreatedAt()->format('d-m-Y')
+                    'Entry already saved on '.$existingEntry[0]->getCreatedAt()->format('d-m-Y')
                 );
 
-                return $this->redirect($this->generateUrl('view', array('id' => $existingEntry->getId())));
+                return $this->redirect($this->generateUrl('view', array('id' => $existingEntry[0]->getId())));
             }
 
             $this->updateEntry($entry);
index ca71970bcbaf9b83936da34a93bde1694c16824a..502e9da05c0ee459dbe475630ff36bbdafeea7d1 100644 (file)
@@ -223,4 +223,21 @@ class EntryRepository extends EntityRepository
             ->getQuery()
             ->getResult();
     }
+
+    /**
+     * Find an entry by its url and its owner.
+     *
+     * @param $url
+     * @param $userId
+     *
+     * @return array
+     */
+    public function findOneByUrlAndUserId($url, $userId)
+    {
+        return $this->createQueryBuilder('e')
+            ->where('e.url = :url')->setParameter('url', $url)
+            ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
+            ->getQuery()
+            ->getResult();
+    }
 }
index 3c14104e1c8e4671f74f8ca80f1f7f194308beca..bacaff31c9d05e5b98a30e17caf061d21a09dfe4 100644 (file)
@@ -2,7 +2,6 @@
 
 namespace Wallabag\ImportBundle\DependencyInjection;
 
-use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
 use Symfony\Component\Config\Definition\Builder\TreeBuilder;
 use Symfony\Component\Config\Definition\ConfigurationInterface;
 
@@ -13,22 +12,6 @@ class Configuration implements ConfigurationInterface
         $treeBuilder = new TreeBuilder();
         $rootNode = $treeBuilder->root('wallabag_import');
 
-        $rootNode
-            ->children()
-                ->arrayNode('importers')
-                    ->append($this->getURLs())
-                ->end()
-            ->end()
-        ;
-
         return $treeBuilder;
     }
-
-    private function getURLs()
-    {
-        $node = new ArrayNodeDefinition('pocket_urls');
-        $node->prototype('scalar')->end();
-
-        return $node;
-    }
 }
index 07dc378dba0568b1c28d195402e438ace6e47495..4efcaace929d5dce0ddbf774ff1cccf32726ed35 100644 (file)
@@ -13,7 +13,6 @@ class WallabagImportExtension extends Extension
     {
         $configuration = new Configuration();
         $config = $this->processConfiguration($configuration, $configs);
-        $container->setParameter('wallabag_import.pocket', $config['importers']['pocket_urls']);
 
         $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
         $loader->load('services.yml');
index 51f73f4ca5739f9b045f2ec8d4535e86746ae946..dd1c34abcba9179486c5e55e811289df00a326a8 100644 (file)
@@ -15,19 +15,15 @@ class PocketImport implements ImportInterface
     private $session;
     private $em;
     private $consumerKey;
-    private $skippedEntries;
-    private $importedEntries;
-    private $pocketURL;
+    private $skippedEntries = 0;
+    private $importedEntries = 0;
 
-    public function __construct($tokenStorage, Session $session, EntityManager $em, $consumerKey, $pocketURL)
+    public function __construct($tokenStorage, Session $session, EntityManager $em, $consumerKey)
     {
         $this->user = $tokenStorage->getToken()->getUser();
         $this->session = $session;
         $this->em = $em;
         $this->consumerKey = $consumerKey;
-        $this->skippedEntries = 0;
-        $this->importedEntries = 0;
-        $this->pocketURL = $pocketURL;
     }
 
     public function getName()
@@ -121,9 +117,9 @@ class PocketImport implements ImportInterface
 
             $existingEntry = $this->em
                 ->getRepository('WallabagCoreBundle:Entry')
-                ->findOneByUrl($url);
+                ->findOneByUrlAndUserId($url, $this->user->getId());
 
-            if (!is_null($existingEntry)) {
+            if (count($existingEntry) > 0) {
                 ++$this->skippedEntries;
                 continue;
             }
@@ -153,7 +149,7 @@ class PocketImport implements ImportInterface
             }
 
             if (!empty($pocketEntry['tags'])) {
-                //   $this->assignTagsToEntry($entry, $pocketEntry['tags']);
+                $this->assignTagsToEntry($entry, $pocketEntry['tags']);
             }
 
             $this->em->persist($entry);
@@ -166,7 +162,7 @@ class PocketImport implements ImportInterface
     public function oAuthRequest($redirectUri, $callbackUri)
     {
         $client = $this->createClient();
-        $request = $client->createRequest('POST', $this->pocketURL['oauth_request'],
+        $request = $client->createRequest('POST', 'https://getpocket.com/v3/oauth/request',
             [
                 'body' => json_encode([
                     'consumer_key' => $this->consumerKey,
@@ -181,14 +177,14 @@ class PocketImport implements ImportInterface
         // store code in session for callback method
         $this->session->set('pocketCode', $values['code']);
 
-        return $this->pocketURL['auth_authorize'].'?request_token='.$values['code'].'&redirect_uri='.$callbackUri;
+        return 'https://getpocket.com/auth/authorize?request_token='.$values['code'].'&redirect_uri='.$callbackUri;
     }
 
     public function oAuthAuthorize()
     {
         $client = $this->createClient();
 
-        $request = $client->createRequest('POST', $this->pocketURL['oauth_authorize'],
+        $request = $client->createRequest('POST', 'https://getpocket.com/v3/oauth/authorize',
             [
                 'body' => json_encode([
                     'consumer_key' => $this->consumerKey,
@@ -206,7 +202,7 @@ class PocketImport implements ImportInterface
     {
         $client = $this->createClient();
 
-        $request = $client->createRequest('POST', $this->pocketURL['get'],
+        $request = $client->createRequest('POST', 'https://getpocket.com/v3/get',
             [
                 'body' => json_encode([
                     'consumer_key' => $this->consumerKey,
index 8f224d887e48eaa0e230ea59ac4788b3625f203d..82628f082ca42ede9b4c5510b1f428dc5ece04d3 100644 (file)
@@ -6,4 +6,3 @@ services:
             - @session
             - @doctrine.orm.entity_manager
             - %pocket_consumer_key%
-            - %wallabag_import.pocket%