]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Don't add entry through API if it already exists 1797/head
authorThomas Citharel <tcit@tcit.fr>
Wed, 16 Mar 2016 20:07:01 +0000 (21:07 +0100)
committerThomas Citharel <tcit@tcit.fr>
Wed, 16 Mar 2016 20:07:01 +0000 (21:07 +0100)
src/Wallabag/ApiBundle/Controller/WallabagRestController.php
src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php

index 29cab1f4df0f6b4f465a949bda377cfb3f1e5811..2633a311773a629a96ea37f734c15d1e2fcc502b 100644 (file)
@@ -112,10 +112,14 @@ class WallabagRestController extends FOSRestController
         $isArchived = $request->request->get('archive');
         $isStarred = $request->request->get('starred');
 
-        $entry = $this->get('wallabag_core.content_proxy')->updateEntry(
-            new Entry($this->getUser()),
-            $url
-        );
+        $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($url, $this->getUser()->getId());
+
+        if (false === $entry) {
+            $entry = $this->get('wallabag_core.content_proxy')->updateEntry(
+                new Entry($this->getUser()),
+                $url
+            );
+        }
 
         $tags = $request->request->get('tags', '');
         if (!empty($tags)) {
index c264180c2cdb437771be30aa8fc8c679ca198341..2e78d8b2ca9bc6b06879082f11e118649f102d5a 100644 (file)
@@ -166,6 +166,24 @@ class WallabagRestControllerTest extends WallabagApiTestCase
         $this->assertCount(1, $content['tags']);
     }
 
+    public function testPostSameEntry()
+    {
+        $this->client->request('POST', '/api/entries.json', array(
+            'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html',
+            'archive' => '1',
+        ));
+
+        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
+
+        $content = json_decode($this->client->getResponse()->getContent(), true);
+
+        $this->assertGreaterThan(0, $content['id']);
+        $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']);
+        $this->assertEquals(true, $content['is_archived']);
+        $this->assertEquals(false, $content['is_starred']);
+        $this->assertCount(1, $content['tags']);
+    }
+
     public function testPostArchivedAndStarredEntry()
     {
         $this->client->request('POST', '/api/entries.json', array(