+ $contentProxy = $this->get('wallabag_core.content_proxy');
+
+ $data = $this->retrieveValueFromRequest($request);
+
+ // this is a special case where user want to manually update the entry content
+ // the ContentProxy will only cleanup the html
+ // and also we force to not re-fetch the content in case of error
+ if (!empty($data['content'])) {
+ try {
+ $contentProxy->updateEntry(
+ $entry,
+ $entry->getUrl(),
+ [
+ 'html' => $data['content'],
+ ],
+ true
+ );
+ } catch (\Exception $e) {
+ $this->get('logger')->error('Error while saving an entry', [
+ 'exception' => $e,
+ 'entry' => $entry,
+ ]);
+ }
+ }
+
+ if (!empty($data['title'])) {
+ $entry->setTitle($data['title']);
+ }
+
+ if (!empty($data['language'])) {
+ $contentProxy->updateLanguage($entry, $data['language']);
+ }
+
+ if (!empty($data['authors']) && \is_string($data['authors'])) {
+ $entry->setPublishedBy(explode(',', $data['authors']));
+ }
+
+ if (!empty($data['picture'])) {
+ $contentProxy->updatePreviewPicture($entry, $data['picture']);
+ }
+
+ if (!empty($data['publishedAt'])) {
+ $contentProxy->updatePublishedAt($entry, $data['publishedAt']);
+ }
+
+ if (null !== $data['isArchived']) {
+ $entry->setArchived((bool) $data['isArchived']);
+ }
+
+ if (null !== $data['isStarred']) {
+ $entry->updateStar((bool) $data['isStarred']);
+ }
+
+ if (!empty($data['tags'])) {
+ $entry->removeAllTags();
+ $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $data['tags']);
+ }
+
+ if (null !== $data['isPublic']) {
+ if (true === (bool) $data['isPublic'] && null === $entry->getUid()) {
+ $entry->generateUid();
+ } elseif (false === (bool) $data['isPublic']) {
+ $entry->cleanUid();
+ }
+ }
+
+ if (!empty($data['origin_url'])) {
+ $entry->setOriginUrl($data['origin_url']);
+ }
+
+ if (empty($entry->getDomainName())) {
+ $this->get('wallabag_core.content_proxy')->setEntryDomainName($entry);
+ }
+
+ if (empty($entry->getTitle())) {
+ $this->get('wallabag_core.content_proxy')->setDefaultEntryTitle($entry);
+ }
+
+ $em = $this->getDoctrine()->getManager();
+ $em->persist($entry);
+ $em->flush();
+
+ // entry saved, dispatch event about it!
+ $this->get('event_dispatcher')->dispatch(EntrySavedEvent::NAME, new EntrySavedEvent($entry));