aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/EntryController.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-12-24 15:19:50 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-01-02 23:27:41 +0100
commit5a4bbcc9a76fcdf54a6af25fcf7b26c9053a0ba3 (patch)
treeae181b75a7a9305b9d12774e4e451059acce5bce /src/Wallabag/CoreBundle/Controller/EntryController.php
parent27a8708b673bb0a28a520131d94ce17c7d3b9f96 (diff)
downloadwallabag-5a4bbcc9a76fcdf54a6af25fcf7b26c9053a0ba3.tar.gz
wallabag-5a4bbcc9a76fcdf54a6af25fcf7b26c9053a0ba3.tar.zst
wallabag-5a4bbcc9a76fcdf54a6af25fcf7b26c9053a0ba3.zip
Change the way to check for an existing entry
The repository method return the entry found or false if nothing exists.
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/EntryController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index 9097810c..37f7ab60 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -41,7 +41,6 @@ class EntryController extends Controller
41 */ 41 */
42 public function addEntryFormAction(Request $request) 42 public function addEntryFormAction(Request $request)
43 { 43 {
44 $em = $this->getDoctrine()->getManager();
45 $entry = new Entry($this->getUser()); 44 $entry = new Entry($this->getUser());
46 45
47 $form = $this->createForm(new NewEntryType(), $entry); 46 $form = $this->createForm(new NewEntryType(), $entry);
@@ -49,17 +48,17 @@ class EntryController extends Controller
49 $form->handleRequest($request); 48 $form->handleRequest($request);
50 49
51 if ($form->isValid()) { 50 if ($form->isValid()) {
52 $existingEntry = $em 51 // check for existing entry, if it exists, redirect to it with a message
53 ->getRepository('WallabagCoreBundle:Entry') 52 $existingEntry = $this->get('wallabag_core.entry_repository')
54 ->findOneByUrlAndUserId($entry->getUrl(), $this->getUser()->getId()); 53 ->existByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
55 54
56 if (count($existingEntry) > 0) { 55 if (false !== $existingEntry) {
57 $this->get('session')->getFlashBag()->add( 56 $this->get('session')->getFlashBag()->add(
58 'notice', 57 'notice',
59 'Entry already saved on '.$existingEntry[0]->getCreatedAt()->format('d-m-Y') 58 'Entry already saved on '.$existingEntry['createdAt']->format('d-m-Y')
60 ); 59 );
61 60
62 return $this->redirect($this->generateUrl('view', array('id' => $existingEntry[0]->getId()))); 61 return $this->redirect($this->generateUrl('view', array('id' => $existingEntry['id'])));
63 } 62 }
64 63
65 $this->updateEntry($entry); 64 $this->updateEntry($entry);