aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller/TagController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/TagController.php')
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php
index fd2069e0..64d53f0c 100644
--- a/src/Wallabag/CoreBundle/Controller/TagController.php
+++ b/src/Wallabag/CoreBundle/Controller/TagController.php
@@ -20,25 +20,23 @@ class TagController extends Controller
20 */ 20 */
21 public function addTagFormAction(Request $request, Entry $entry) 21 public function addTagFormAction(Request $request, Entry $entry)
22 { 22 {
23 $tag = new Tag($this->getUser()); 23 $tag = new Tag();
24 $form = $this->createForm(new NewTagType(), $tag); 24 $form = $this->createForm(new NewTagType(), $tag);
25 $form->handleRequest($request); 25 $form->handleRequest($request);
26 26
27 if ($form->isValid()) { 27 if ($form->isValid()) {
28 $existingTag = $this->getDoctrine() 28 $existingTag = $this->getDoctrine()
29 ->getRepository('WallabagCoreBundle:Tag') 29 ->getRepository('WallabagCoreBundle:Tag')
30 ->findOneByLabelAndUserId($tag->getLabel(), $this->getUser()->getId()); 30 ->findOneByLabel($tag->getLabel());
31 31
32 $em = $this->getDoctrine()->getManager(); 32 $em = $this->getDoctrine()->getManager();
33 33
34 if (is_null($existingTag)) { 34 if (is_null($existingTag)) {
35 $entry->addTag($tag); 35 $entry->addTag($tag);
36 $em->persist($tag); 36 $em->persist($tag);
37 } else { 37 } elseif (!$existingTag->hasEntry($entry)) {
38 if (!$existingTag->hasEntry($entry)) { 38 $entry->addTag($existingTag);
39 $entry->addTag($existingTag); 39 $em->persist($existingTag);
40 $em->persist($existingTag);
41 }
42 } 40 }
43 41
44 $em->flush(); 42 $em->flush();