X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FController%2FEntryController.php;h=c1b5a71ba046dde16e5adc67057ffd6ecdbc1c89;hb=619cc45359ead519b64129181a07e14160fbbfcb;hp=041fe71ca77af8166e7787d1202c157af4af340d;hpb=831b02aaf2709d632453a03ab8eb2663fb947497;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 041fe71c..c1b5a71b 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -2,16 +2,16 @@ namespace Wallabag\CoreBundle\Controller; +use Pagerfanta\Adapter\DoctrineORMAdapter; +use Pagerfanta\Pagerfanta; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\CoreBundle\Form\Type\NewEntryType; -use Wallabag\CoreBundle\Form\Type\EditEntryType; use Wallabag\CoreBundle\Filter\EntryFilterType; -use Pagerfanta\Adapter\DoctrineORMAdapter; -use Pagerfanta\Pagerfanta; +use Wallabag\CoreBundle\Form\Type\EditEntryType; +use Wallabag\CoreBundle\Form\Type\NewEntryType; class EntryController extends Controller { @@ -48,6 +48,19 @@ class EntryController extends Controller $form->handleRequest($request); if ($form->isValid()) { + // check for existing entry, if it exists, redirect to it with a message + $existingEntry = $this->get('wallabag_core.entry_repository') + ->existByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); + + if (false !== $existingEntry) { + $this->get('session')->getFlashBag()->add( + 'notice', + 'Entry already saved on '.$existingEntry['createdAt']->format('d-m-Y') + ); + + return $this->redirect($this->generateUrl('view', array('id' => $existingEntry['id']))); + } + $this->updateEntry($entry); $this->get('session')->getFlashBag()->add( 'notice', @@ -374,7 +387,7 @@ class EntryController extends Controller ); // don't redirect user to the deleted entry - return $this->redirect($url !== $request->headers->get('referer') ?: $this->generateUrl('homepage')); + return $this->redirect($url !== $request->headers->get('referer') ? $request->headers->get('referer') : $this->generateUrl('homepage')); } /**