X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FApiBundle%2FController%2FEntryRestController.php;h=2c2ec0c106ac1d72073649907f45a634ff7ad2ba;hb=68cb89a5161351dd730871fc834bf147204a2a07;hp=b3622c62ce6382d496d9c383ac595553125f9d48;hpb=5a619812ca3eb05a82a023ccdaee13501eb8d45f;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index b3622c62..2c2ec0c1 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php @@ -150,6 +150,28 @@ class EntryRestController extends WallabagRestController return (new JsonResponse())->setJson($json); } + /** + * Retrieve a single entry as a predefined format. + * + * @ApiDoc( + * requirements={ + * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} + * } + * ) + * + * @return Response + */ + public function getEntryExportAction(Entry $entry, Request $request) + { + $this->validateAuthentication(); + $this->validateUserAccess($entry->getUser()->getId()); + + return $this->get('wallabag_core.helper.entries_export') + ->setEntries($entry) + ->updateTitle('entry') + ->exportAs($request->attributes->get('_format')); + } + /** * Create an entry. * @@ -263,6 +285,51 @@ class EntryRestController extends WallabagRestController return (new JsonResponse())->setJson($json); } + /** + * Reload an entry. + * An empty response with HTTP Status 304 will be send if we weren't able to update the content (because it hasn't changed or we got an error). + * + * @ApiDoc( + * requirements={ + * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} + * } + * ) + * + * @return JsonResponse + */ + public function patchEntriesReloadAction(Entry $entry) + { + $this->validateAuthentication(); + $this->validateUserAccess($entry->getUser()->getId()); + + try { + $entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl()); + } catch (\Exception $e) { + $this->get('logger')->error('Error while saving an entry', [ + 'exception' => $e, + 'entry' => $entry, + ]); + + return new JsonResponse([], 304); + } + + // if refreshing entry failed, don't save it + if ($this->getParameter('wallabag_core.fetching_error_message') === $entry->getContent()) { + return new JsonResponse([], 304); + } + + $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)); + + $json = $this->get('serializer')->serialize($entry, 'json'); + + return (new JsonResponse())->setJson($json); + } + /** * Delete **permanently** an entry. *