aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-06-02 20:52:49 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-06-02 20:52:49 +0200
commit645291e8feb0f3e977b9518da7d731fda8cf1f30 (patch)
treeadc3483dac1b16b9b8a1f292efc85e588612352f /src
parenta687c8d915276eee0c0494156700f7d0c0606735 (diff)
downloadwallabag-645291e8feb0f3e977b9518da7d731fda8cf1f30.tar.gz
wallabag-645291e8feb0f3e977b9518da7d731fda8cf1f30.tar.zst
wallabag-645291e8feb0f3e977b9518da7d731fda8cf1f30.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php38
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php2
2 files changed, 36 insertions, 4 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index 93c8157e..7135e616 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -374,6 +374,11 @@ class EntryRestController extends WallabagRestController
374 * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, 374 * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."},
375 * {"name"="archive", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="archived the entry."}, 375 * {"name"="archive", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="archived the entry."},
376 * {"name"="starred", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="starred the entry."}, 376 * {"name"="starred", "dataType"="integer", "required"=false, "format"="1 or 0", "description"="starred the entry."},
377 * {"name"="content", "dataType"="string", "required"=false, "description"="Content of the entry"},
378 * {"name"="language", "dataType"="string", "required"=false, "description"="Language of the entry"},
379 * {"name"="preview_picture", "dataType"="string", "required"=false, "description"="Preview picture of the entry"},
380 * {"name"="published_at", "dataType"="datetime|integer", "format"="YYYY-MM-DDTHH:II:SS+TZ or a timestamp", "required"=false, "description"="Published date of the entry"},
381 * {"name"="authors", "dataType"="string", "format"="Name Firstname,author2,author3", "required"=false, "description"="Authors of the entry"},
377 * } 382 * }
378 * ) 383 * )
379 * 384 *
@@ -385,11 +390,39 @@ class EntryRestController extends WallabagRestController
385 $this->validateUserAccess($entry->getUser()->getId()); 390 $this->validateUserAccess($entry->getUser()->getId());
386 391
387 $title = $request->request->get('title'); 392 $title = $request->request->get('title');
393 $tags = $request->request->get('tags', '');
388 $isArchived = $request->request->get('archive'); 394 $isArchived = $request->request->get('archive');
389 $isStarred = $request->request->get('starred'); 395 $isStarred = $request->request->get('starred');
396 $content = $request->request->get('content');
397 $language = $request->request->get('language');
398 $picture = $request->request->get('preview_picture');
399 $publishedAt = $request->request->get('published_at');
400 $authors = $request->request->get('authors', '');
390 401
391 if (!is_null($title)) { 402 try {
392 $entry->setTitle($title); 403 $this->get('wallabag_core.content_proxy')->updateEntry(
404 $entry,
405 $entry->getUrl(),
406 [
407 'title' => !empty($title) ? $title : $entry->getTitle(),
408 'html' => !empty($content) ? $content : $entry->getContent(),
409 'url' => $entry->getUrl(),
410 'language' => $language,
411 'date' => $publishedAt,
412 // faking the preview picture
413 'open_graph' => [
414 'og_image' => $picture,
415 ],
416 'authors' => is_string($authors) ? explode(',', $authors) : [],
417 ],
418 // we don't want the content to be update by fetching the url
419 true
420 );
421 } catch (\Exception $e) {
422 $this->get('logger')->error('Error while saving an entry', [
423 'exception' => $e,
424 'entry' => $entry,
425 ]);
393 } 426 }
394 427
395 if (!is_null($isArchived)) { 428 if (!is_null($isArchived)) {
@@ -400,7 +433,6 @@ class EntryRestController extends WallabagRestController
400 $entry->setStarred((bool) $isStarred); 433 $entry->setStarred((bool) $isStarred);
401 } 434 }
402 435
403 $tags = $request->request->get('tags', '');
404 if (!empty($tags)) { 436 if (!empty($tags)) {
405 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags); 437 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags);
406 } 438 }
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index bfaa1976..d5820e66 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -105,7 +105,7 @@ class ContentProxy
105 } 105 }
106 } 106 }
107 107
108 if (!empty($content['authors'])) { 108 if (!empty($content['authors']) && is_array($content['authors'])) {
109 $entry->setPublishedBy($content['authors']); 109 $entry->setPublishedBy($content['authors']);
110 } 110 }
111 111