From 6334f2cac16158a0ea4a8e540ace17550085942b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 30 May 2016 14:32:41 +0200 Subject: Display a message when saving an entry failed When saving an entry fail because of database error we previously just returned `false`. Now we got an error in the log and the displayed notice to the user is updated too. --- src/Wallabag/CoreBundle/Controller/EntryController.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 69dfd4b1..33b5e2ad 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -23,10 +23,16 @@ class EntryController extends Controller { 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; } @@ -60,11 +66,12 @@ class EntryController extends Controller return $this->redirect($this->generateUrl('view', ['id' => $existingEntry->getId()])); } - $this->updateEntry($entry); - $this->get('session')->getFlashBag()->add( - 'notice', - 'flashes.entry.notice.entry_saved' - ); + $message = 'flashes.entry.notice.entry_saved'; + if (false === $this->updateEntry($entry)) { + $message = 'flashes.entry.notice.entry_saved_failed'; + } + + $this->get('session')->getFlashBag()->add('notice', $message); return $this->redirect($this->generateUrl('homepage')); } -- cgit v1.2.3 From 4e411208ccdbbb503ec430ef2b3c748a02abbbcd Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 17 Jun 2016 22:18:48 +0200 Subject: Try to find bad redirection after delete Instead of checking for the whole absolute url, we just check with the relative url. If the referer ends with the relative url of the deleted entry, don't redirect to the referer. --- src/Wallabag/CoreBundle/Controller/EntryController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 33b5e2ad..4eb314f7 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -406,7 +406,7 @@ class EntryController extends Controller $url = $this->generateUrl( 'view', ['id' => $entry->getId()], - UrlGeneratorInterface::ABSOLUTE_URL + UrlGeneratorInterface::ABSOLUTE_PATH ); $em = $this->getDoctrine()->getManager(); @@ -418,8 +418,9 @@ class EntryController extends Controller 'flashes.entry.notice.entry_deleted' ); - // don't redirect user to the deleted entry - $to = ($url !== $request->headers->get('referer') ? $request->headers->get('referer') : null); + // don't redirect user to the deleted entry (check that the referer doesn't end with the same url) + $referer = $request->headers->get('referer'); + $to = (1 !== preg_match('#'.$url.'$#i', $referer) ? $referer : null); $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($to); -- cgit v1.2.3 From 891456ba9a592a200d8b23029e8f4514d9803080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 14 Apr 2016 15:03:22 +0200 Subject: Links on each tag in Tags view --- src/Wallabag/CoreBundle/Controller/EntryController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index ccdf9406..93db0d6c 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -4,7 +4,6 @@ namespace Wallabag\CoreBundle\Controller; use Pagerfanta\Adapter\DoctrineORMAdapter; use Pagerfanta\Exception\OutOfRangeCurrentPageException; -use Pagerfanta\Pagerfanta; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; @@ -257,9 +256,10 @@ class EntryController extends Controller } $pagerAdapter = new DoctrineORMAdapter($qb->getQuery()); - $entries = new Pagerfanta($pagerAdapter); - $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); + $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries') + ->prepare($pagerAdapter, $page); + try { $entries->setCurrentPage($page); } catch (OutOfRangeCurrentPageException $e) { -- cgit v1.2.3 From f3d0cb91063840f2b05c63954d3fef3e5b8943fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 10 Apr 2016 17:33:15 +0200 Subject: Share entry with a public URL --- .../CoreBundle/Controller/EntryController.php | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 93db0d6c..a78dd00c 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -291,6 +291,8 @@ class EntryController extends Controller { $this->checkUserAction($entry); + $this->generateEntryUuid($entry); + return $this->render( 'WallabagCoreBundle:Entry:entry.html.twig', ['entry' => $entry] @@ -449,5 +451,34 @@ class EntryController extends Controller private function checkIfEntryAlreadyExists(Entry $entry) { return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); + + } + + /* + * Share entry content. + * + * @param Entry $entry + * + * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function shareEntry(Entry $entry) + { + return $this->render( + '@WallabagCore/themes/share.html.twig', + array('entry' => $entry) + ); + } + + /** + * @param Entry $entry + */ + private function generateEntryUuid(Entry $entry) + { + $entry->generateUuid(); + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); } } -- cgit v1.2.3 From d0545b6bd6edc38bf06604900b1e20a60e7c8583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 10 Apr 2016 21:48:11 +0200 Subject: Add migration --- src/Wallabag/CoreBundle/Controller/EntryController.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index a78dd00c..e3b4b1eb 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -451,10 +451,9 @@ class EntryController extends Controller private function checkIfEntryAlreadyExists(Entry $entry) { return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); - } - /* + /** * Share entry content. * * @param Entry $entry @@ -463,7 +462,7 @@ class EntryController extends Controller * * @return \Symfony\Component\HttpFoundation\Response */ - public function shareEntry(Entry $entry) + public function shareEntryAction(Entry $entry) { return $this->render( '@WallabagCore/themes/share.html.twig', -- cgit v1.2.3 From 222e09f140099f3b1b8f6db1846d35e6810d43a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 13 Apr 2016 22:26:02 +0200 Subject: Add Cache on Share Action --- src/Wallabag/CoreBundle/Controller/EntryController.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index e3b4b1eb..c94b47f0 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -12,6 +12,7 @@ use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Form\Type\EntryFilterType; use Wallabag\CoreBundle\Form\Type\EditEntryType; use Wallabag\CoreBundle\Form\Type\NewEntryType; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; class EntryController extends Controller { @@ -459,6 +460,7 @@ class EntryController extends Controller * @param Entry $entry * * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share") + * @Cache(maxage="25200", public=true) * * @return \Symfony\Component\HttpFoundation\Response */ -- cgit v1.2.3 From f1be7af446052c6fed7033664c6c6350f558961b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 23 Aug 2016 16:49:12 +0200 Subject: Change share entry behavior --- .../CoreBundle/Controller/EntryController.php | 51 ++++++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index c94b47f0..e500ad75 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -292,8 +292,6 @@ class EntryController extends Controller { $this->checkUserAction($entry); - $this->generateEntryUuid($entry); - return $this->render( 'WallabagCoreBundle:Entry:entry.html.twig', ['entry' => $entry] @@ -437,7 +435,7 @@ class EntryController extends Controller */ private function checkUserAction(Entry $entry) { - if ($this->getUser()->getId() != $entry->getUser()->getId()) { + if (null === $this->getUser() || $this->getUser()->getId() != $entry->getUser()->getId()) { throw $this->createAccessDeniedException('You can not access this entry.'); } } @@ -454,12 +452,57 @@ class EntryController extends Controller return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); } + /** + * Get public URL for entry (and generate it if necessary). + * + * @param Entry $entry + * + * @Route("/share/{id}", requirements={"id" = "\d+"}, name="share") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function shareAction(Entry $entry) + { + $this->checkUserAction($entry); + + if ('' === $entry->getUuid() || null === $entry->getUuid()) { + $this->generateEntryUuid($entry); + } + + return $this->redirect($this->generateUrl('share_entry', [ + 'uuid' => $entry->getUuid(), + ])); + } + + /** + * Disable public sharing for an entry. + * + * @param Entry $entry + * + * @Route("/share/delete/{id}", requirements={"id" = "\d+"}, name="delete_share") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function deleteShareAction(Entry $entry) + { + $this->checkUserAction($entry); + + $entry->cleanUuid(); + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); + + return $this->redirect($this->generateUrl('view', [ + 'id' => $entry->getId(), + ])); + } + /** * Share entry content. * * @param Entry $entry * - * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share") + * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry") * @Cache(maxage="25200", public=true) * * @return \Symfony\Component\HttpFoundation\Response -- cgit v1.2.3 From eddda878a0ec375fa738e3228a72dd01b23e0fab Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 24 Aug 2016 22:29:36 +0200 Subject: Update test and some cleanup --- .../CoreBundle/Controller/EntryController.php | 30 ++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index e500ad75..d71ba6cd 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -465,8 +465,12 @@ class EntryController extends Controller { $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', [ @@ -488,6 +492,7 @@ class EntryController extends Controller $this->checkUserAction($entry); $entry->cleanUuid(); + $em = $this->getDoctrine()->getManager(); $em->persist($entry); $em->flush(); @@ -498,31 +503,24 @@ class EntryController extends Controller } /** - * 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) + ['entry' => $entry] ); } - - /** - * @param Entry $entry - */ - private function generateEntryUuid(Entry $entry) - { - $entry->generateUuid(); - $em = $this->getDoctrine()->getManager(); - $em->persist($entry); - $em->flush(); - } } -- cgit v1.2.3 From b6520f0b15ac35215e2d94d16a31ea971874dce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 26 Aug 2016 16:55:41 +0200 Subject: Add untagged entries Fix #1631 --- .../CoreBundle/Controller/EntryController.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index d71ba6cd..624576b5 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -226,6 +226,10 @@ class EntryController extends Controller $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; @@ -523,4 +527,19 @@ class EntryController extends Controller ['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 + */ + public function showUntaggedEntriesAction(Request $request, $page) + { + return $this->showEntries('untagged', $request, $page); + } } -- cgit v1.2.3 From 59b97fae996d8307b9d957d210d46200f6d206bf Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 17 Sep 2016 07:40:56 +0200 Subject: Avoid losing entry when fetching fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of just say “Failed to save entry” we’ll save the entry at all cost and try to fetch content. If fetching content failed, the entry will still be saved at least, but without content. --- .../CoreBundle/Controller/EntryController.php | 50 +++++++++++++--------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 624576b5..40111af0 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -17,26 +17,35 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; 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; } /** @@ -66,12 +75,11 @@ class EntryController extends Controller 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')); } @@ -95,6 +103,10 @@ class EntryController extends Controller if (false === $this->checkIfEntryAlreadyExists($entry)) { $this->updateEntry($entry); + + $em = $this->getDoctrine()->getManager(); + $em->persist($entry); + $em->flush(); } return $this->redirect($this->generateUrl('homepage')); @@ -316,15 +328,11 @@ class EntryController extends Controller { $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()])); } -- cgit v1.2.3 From 2ff9991a1dfac0d3463662b96f529aac70c66f76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 30 Sep 2016 09:38:08 +0200 Subject: Removed duplicated templates files --- src/Wallabag/CoreBundle/Controller/EntryController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 40111af0..3b28e635 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -531,7 +531,7 @@ class EntryController extends Controller } return $this->render( - '@WallabagCore/themes/share.html.twig', + '@WallabagCore/themes/common/Entry/share.html.twig', ['entry' => $entry] ); } -- cgit v1.2.3