class EntryController extends Controller
{
/**
- * @param Entry $entry
+ * Fetch content and update entry.
+ * In case it fails, entry will return to avod loosing the data.
+ *
+ * @param Entry $entry
+ * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded
+ *
+ * @return Entry
*/
- private function updateEntry(Entry $entry)
+ private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved')
{
+ // put default title in case of fetching content failed
+ $entry->setTitle('No title found');
+
+ $message = 'flashes.entry.notice.'.$prefixMessage;
+
try {
$entry = $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
-
- $em = $this->getDoctrine()->getManager();
- $em->persist($entry);
- $em->flush();
} catch (\Exception $e) {
$this->get('logger')->error('Error while saving an entry', [
'exception' => $e,
'entry' => $entry,
]);
- return false;
+ $message = 'flashes.entry.notice.'.$prefixMessage.'_failed';
}
- return true;
+ $this->get('session')->getFlashBag()->add('notice', $message);
+
+ return $entry;
}
/**
return $this->redirect($this->generateUrl('view', ['id' => $existingEntry->getId()]));
}
- $message = 'flashes.entry.notice.entry_saved';
- if (false === $this->updateEntry($entry)) {
- $message = 'flashes.entry.notice.entry_saved_failed';
- }
+ $this->updateEntry($entry);
- $this->get('session')->getFlashBag()->add('notice', $message);
+ $em = $this->getDoctrine()->getManager();
+ $em->persist($entry);
+ $em->flush();
return $this->redirect($this->generateUrl('homepage'));
}
if (false === $this->checkIfEntryAlreadyExists($entry)) {
$this->updateEntry($entry);
+
+ $em = $this->getDoctrine()->getManager();
+ $em->persist($entry);
+ $em->flush();
}
return $this->redirect($this->generateUrl('homepage'));
$repository = $this->get('wallabag_core.entry_repository');
switch ($type) {
+ case 'untagged':
+ $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId());
+
+ break;
case 'starred':
$qb = $repository->getBuilderForStarredByUser($this->getUser()->getId());
break;
{
$this->checkUserAction($entry);
- $message = 'flashes.entry.notice.entry_reloaded';
- if (false === $this->updateEntry($entry)) {
- $message = 'flashes.entry.notice.entry_reload_failed';
- }
+ $this->updateEntry($entry, 'entry_reloaded');
- $this->get('session')->getFlashBag()->add(
- 'notice',
- $message
- );
+ $em = $this->getDoctrine()->getManager();
+ $em->persist($entry);
+ $em->flush();
return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
}
{
$this->checkUserAction($entry);
- if ('' === $entry->getUuid() || null === $entry->getUuid()) {
- $this->generateEntryUuid($entry);
+ if (null === $entry->getUuid()) {
+ $entry->generateUuid();
+
+ $em = $this->getDoctrine()->getManager();
+ $em->persist($entry);
+ $em->flush();
}
return $this->redirect($this->generateUrl('share_entry', [
$this->checkUserAction($entry);
$entry->cleanUuid();
+
$em = $this->getDoctrine()->getManager();
$em->persist($entry);
$em->flush();
}
/**
- * Share entry content.
+ * Ability to view a content publicly.
*
* @param Entry $entry
*
* @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry")
- * @Cache(maxage="25200", public=true)
+ * @Cache(maxage="25200", smaxage="25200", public=true)
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function shareEntryAction(Entry $entry)
{
+ if (!$this->get('craue_config')->get('share_public')) {
+ throw $this->createAccessDeniedException('Sharing an entry is disabled for this user.');
+ }
+
return $this->render(
- '@WallabagCore/themes/share.html.twig',
- array('entry' => $entry)
+ '@WallabagCore/themes/common/Entry/share.html.twig',
+ ['entry' => $entry]
);
}
/**
- * @param Entry $entry
+ * Shows untagged articles for current user.
+ *
+ * @param Request $request
+ * @param int $page
+ *
+ * @Route("/untagged/list/{page}", name="untagged", defaults={"page" = "1"})
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
*/
- private function generateEntryUuid(Entry $entry)
+ public function showUntaggedEntriesAction(Request $request, $page)
{
- $entry->generateUuid();
- $em = $this->getDoctrine()->getManager();
- $em->persist($entry);
- $em->flush();
+ return $this->showEntries('untagged', $request, $page);
}
}