From f5ea67e4cf8e415530d8c09e1b22c66c7064b3c6 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 17 Dec 2017 21:05:25 +0100 Subject: [PATCH] api: copy entry object before sending, to keep id Workaround for https://github.com/wallabag/android-app/issues/646 Signed-off-by: Kevin Decherf --- CHANGELOG.md | 3 ++- src/Wallabag/ApiBundle/Controller/EntryRestController.php | 5 ++++- .../ApiBundle/Controller/EntryRestControllerTest.php | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a7ef3818..ef9d2131c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ ### Fixes - - Fix empty title and domain_name when exception is thrown during fetch [#3442](https://github.com/wallabag/wallabag/pull/3442) +- Fix empty title and domain_name when exception is thrown during fetch [#3442](https://github.com/wallabag/wallabag/pull/3442) +- api: copy entry object before sending, to keep id [#3516](https://github.com/wallabag/wallabag/pull/3516) ### Changes diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index acca219fe..fc47c479f 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php @@ -575,6 +575,9 @@ class EntryRestController extends WallabagRestController $this->validateAuthentication(); $this->validateUserAccess($entry->getUser()->getId()); + // We copy $entry to keep id in returned object + $e = $entry; + $em = $this->getDoctrine()->getManager(); $em->remove($entry); $em->flush(); @@ -582,7 +585,7 @@ class EntryRestController extends WallabagRestController // entry deleted, dispatch event about it! $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry)); - return $this->sendResponse($entry); + return $this->sendResponse($e); } /** diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 5c7b988c9..2e9b93050 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -408,6 +408,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame($entry->getTitle(), $content['title']); $this->assertSame($entry->getUrl(), $content['url']); + $this->assertSame($entry->getId(), $content['id']); // We'll try to delete this entry again $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json');