mirror of
https://github.com/wallabag/wallabag.git
synced 2024-12-27 01:50:29 +00:00
Add ability to patch an entry with more fields
Like when we create an entry, we can now patch an entry with new fields: - content - language - preview_picture - published_at - authors
This commit is contained in:
parent
a687c8d915
commit
645291e8fe
3 changed files with 47 additions and 4 deletions
|
@ -374,6 +374,11 @@ class EntryRestController extends WallabagRestController
|
|||
* {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
|
||||
* {"name"="archive", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="archived the entry."},
|
||||
* {"name"="starred", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="starred the entry."},
|
||||
* {"name"="content", "dataType"="string", "required"=false, "description"="Content of the entry"},
|
||||
* {"name"="language", "dataType"="string", "required"=false, "description"="Language of the entry"},
|
||||
* {"name"="preview_picture", "dataType"="string", "required"=false, "description"="Preview picture of the entry"},
|
||||
* {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"},
|
||||
* {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"},
|
||||
* }
|
||||
* )
|
||||
*
|
||||
|
@ -385,11 +390,39 @@ class EntryRestController extends WallabagRestController
|
|||
$this->validateUserAccess($entry->getUser()->getId());
|
||||
|
||||
$title = $request->request->get('title');
|
||||
$tags = $request->request->get('tags', '');
|
||||
$isArchived = $request->request->get('archive');
|
||||
$isStarred = $request->request->get('starred');
|
||||
$content = $request->request->get('content');
|
||||
$language = $request->request->get('language');
|
||||
$picture = $request->request->get('preview_picture');
|
||||
$publishedAt = $request->request->get('published_at');
|
||||
$authors = $request->request->get('authors', '');
|
||||
|
||||
if (!is_null($title)) {
|
||||
$entry->setTitle($title);
|
||||
try {
|
||||
$this->get('wallabag_core.content_proxy')->updateEntry(
|
||||
$entry,
|
||||
$entry->getUrl(),
|
||||
[
|
||||
'title' => !empty($title) ? $title : $entry->getTitle(),
|
||||
'html' => !empty($content) ? $content : $entry->getContent(),
|
||||
'url' => $entry->getUrl(),
|
||||
'language' => $language,
|
||||
'date' => $publishedAt,
|
||||
// faking the preview picture
|
||||
'open_graph' => [
|
||||
'og_image' => $picture,
|
||||
],
|
||||
'authors' => is_string($authors) ? explode(',', $authors) : [],
|
||||
],
|
||||
// we don't want the content to be update by fetching the url
|
||||
true
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$this->get('logger')->error('Error while saving an entry', [
|
||||
'exception' => $e,
|
||||
'entry' => $entry,
|
||||
]);
|
||||
}
|
||||
|
||||
if (!is_null($isArchived)) {
|
||||
|
@ -400,7 +433,6 @@ class EntryRestController extends WallabagRestController
|
|||
$entry->setStarred((bool) $isStarred);
|
||||
}
|
||||
|
||||
$tags = $request->request->get('tags', '');
|
||||
if (!empty($tags)) {
|
||||
$this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags);
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ class ContentProxy
|
|||
}
|
||||
}
|
||||
|
||||
if (!empty($content['authors'])) {
|
||||
if (!empty($content['authors']) && is_array($content['authors'])) {
|
||||
$entry->setPublishedBy($content['authors']);
|
||||
}
|
||||
|
||||
|
|
|
@ -477,6 +477,10 @@ class EntryRestControllerTest extends WallabagApiTestCase
|
|||
'tags' => 'new tag '.uniqid(),
|
||||
'starred' => '1',
|
||||
'archive' => '0',
|
||||
'language' => 'de_DE',
|
||||
'preview_picture' => 'http://preview.io/picture.jpg',
|
||||
'authors' => 'bob,sponge',
|
||||
'content' => 'awesome',
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
|
||||
|
@ -488,6 +492,11 @@ class EntryRestControllerTest extends WallabagApiTestCase
|
|||
$this->assertEquals('New awesome title', $content['title']);
|
||||
$this->assertGreaterThan($nbTags, count($content['tags']));
|
||||
$this->assertEquals(1, $content['user_id']);
|
||||
$this->assertEquals('de_DE', $content['language']);
|
||||
$this->assertEquals('http://preview.io/picture.jpg', $content['preview_picture']);
|
||||
$this->assertContains('sponge', $content['published_by']);
|
||||
$this->assertContains('bob', $content['published_by']);
|
||||
$this->assertEquals('awesome', $content['content']);
|
||||
}
|
||||
|
||||
public function testPatchEntryWithoutQuotes()
|
||||
|
@ -509,6 +518,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
|
|||
'tags' => 'new tag '.uniqid(),
|
||||
'starred' => 1,
|
||||
'archive' => 0,
|
||||
'authors' => ['bob', 'sponge'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
|
||||
|
@ -519,6 +529,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
|
|||
$this->assertEquals($entry->getUrl(), $content['url']);
|
||||
$this->assertEquals('New awesome title', $content['title']);
|
||||
$this->assertGreaterThan($nbTags, count($content['tags']));
|
||||
$this->assertTrue(empty($content['published_by']), 'Authors were not saved because of an array instead of a string');
|
||||
}
|
||||
|
||||
public function testGetTagsEntry()
|
||||
|
|
Loading…
Reference in a new issue