api: copy entry object before sending, to keep id

Workaround for https://github.com/wallabag/android-app/issues/646

Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
This commit is contained in:
Kevin Decherf 2017-12-17 21:05:25 +01:00
parent d1f260e2d7
commit f5ea67e4cf
3 changed files with 7 additions and 2 deletions

View File

@ -5,7 +5,8 @@
### Fixes ### 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 ### Changes

View File

@ -575,6 +575,9 @@ class EntryRestController extends WallabagRestController
$this->validateAuthentication(); $this->validateAuthentication();
$this->validateUserAccess($entry->getUser()->getId()); $this->validateUserAccess($entry->getUser()->getId());
// We copy $entry to keep id in returned object
$e = $entry;
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$em->remove($entry); $em->remove($entry);
$em->flush(); $em->flush();
@ -582,7 +585,7 @@ class EntryRestController extends WallabagRestController
// entry deleted, dispatch event about it! // entry deleted, dispatch event about it!
$this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry)); $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
return $this->sendResponse($entry); return $this->sendResponse($e);
} }
/** /**

View File

@ -408,6 +408,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
$this->assertSame($entry->getTitle(), $content['title']); $this->assertSame($entry->getTitle(), $content['title']);
$this->assertSame($entry->getUrl(), $content['url']); $this->assertSame($entry->getUrl(), $content['url']);
$this->assertSame($entry->getId(), $content['id']);
// We'll try to delete this entry again // We'll try to delete this entry again
$this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json'); $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json');