]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/EntryController.php
fix #1502 avoid duplicate entry and store pocket url in config
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / EntryController.php
index fa58013312a74169207f4795c2e8c4dd253f474f..de2eedcb75f715bcd0d5e32b2d28799ac412ecda 100644 (file)
@@ -41,6 +41,7 @@ class EntryController extends Controller
      */
     public function addEntryFormAction(Request $request)
     {
+        $em = $this->getDoctrine()->getManager();
         $entry = new Entry($this->getUser());
 
         $form = $this->createForm(new NewEntryType(), $entry);
@@ -48,6 +49,19 @@ class EntryController extends Controller
         $form->handleRequest($request);
 
         if ($form->isValid()) {
+            $existingEntry = $em
+                ->getRepository('WallabagCoreBundle:Entry')
+                ->findOneByUrl($entry->getUrl());
+
+            if (!is_null($existingEntry)) {
+                $this->get('session')->getFlashBag()->add(
+                    'notice',
+                    'Entry already saved on '.$existingEntry->getCreatedAt()->format('d-m-Y')
+                );
+
+                return $this->redirect($this->generateUrl('view', array('id' => $existingEntry->getId())));
+            }
+
             $this->updateEntry($entry);
             $this->get('session')->getFlashBag()->add(
                 'notice',