aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php38
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php2
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php11
3 files changed, 47 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
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 0968cfaf..74ec34b1 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -477,6 +477,10 @@ class EntryRestControllerTest extends WallabagApiTestCase
477 'tags' => 'new tag '.uniqid(), 477 'tags' => 'new tag '.uniqid(),
478 'starred' => '1', 478 'starred' => '1',
479 'archive' => '0', 479 'archive' => '0',
480 'language' => 'de_DE',
481 'preview_picture' => 'http://preview.io/picture.jpg',
482 'authors' => 'bob,sponge',
483 'content' => 'awesome',
480 ]); 484 ]);
481 485
482 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 486 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -488,6 +492,11 @@ class EntryRestControllerTest extends WallabagApiTestCase
488 $this->assertEquals('New awesome title', $content['title']); 492 $this->assertEquals('New awesome title', $content['title']);
489 $this->assertGreaterThan($nbTags, count($content['tags'])); 493 $this->assertGreaterThan($nbTags, count($content['tags']));
490 $this->assertEquals(1, $content['user_id']); 494 $this->assertEquals(1, $content['user_id']);
495 $this->assertEquals('de_DE', $content['language']);
496 $this->assertEquals('http://preview.io/picture.jpg', $content['preview_picture']);
497 $this->assertContains('sponge', $content['published_by']);
498 $this->assertContains('bob', $content['published_by']);
499 $this->assertEquals('awesome', $content['content']);
491 } 500 }
492 501
493 public function testPatchEntryWithoutQuotes() 502 public function testPatchEntryWithoutQuotes()
@@ -509,6 +518,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
509 'tags' => 'new tag '.uniqid(), 518 'tags' => 'new tag '.uniqid(),
510 'starred' => 1, 519 'starred' => 1,
511 'archive' => 0, 520 'archive' => 0,
521 'authors' => ['bob', 'sponge'],
512 ]); 522 ]);
513 523
514 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 524 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -519,6 +529,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
519 $this->assertEquals($entry->getUrl(), $content['url']); 529 $this->assertEquals($entry->getUrl(), $content['url']);
520 $this->assertEquals('New awesome title', $content['title']); 530 $this->assertEquals('New awesome title', $content['title']);
521 $this->assertGreaterThan($nbTags, count($content['tags'])); 531 $this->assertGreaterThan($nbTags, count($content['tags']));
532 $this->assertTrue(empty($content['published_by']), 'Authors were not saved because of an array instead of a string');
522 } 533 }
523 534
524 public function testGetTagsEntry() 535 public function testGetTagsEntry()