mirror of
https://github.com/wallabag/wallabag.git
synced 2025-07-22 17:18:37 +00:00
Add ability to reload entry from API
This commit is contained in:
parent
5ae8788583
commit
0a6f4568b5
2 changed files with 85 additions and 0 deletions
|
@ -285,6 +285,54 @@ 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());
|
||||
|
||||
// put default title in case of fetching content failed
|
||||
$entry->setTitle('No title found');
|
||||
|
||||
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.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue