From 39133eb796996701228501f898b4ef33af8e0fdb Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sat, 4 Apr 2020 21:03:22 +0200 Subject: TagController: fix duplicated tags when renaming them The fix relies on a workaround available on TagsAssigner, see the AssignTagsToEntry() signature for detail. I replaced the findOneByLabel in the corresponding test to assert that there is no duplicate. Fixes #4216 Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Controller/TagController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index a6ad131f..c228c27a 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -152,6 +152,10 @@ class TagController extends Controller $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { + $newTagLabel = $form->get('label')->getData(); + $newTag = new Tag(); + $newTag->setLabel($newTagLabel); + $entries = $this->get('wallabag_core.entry_repository')->findAllByTagId( $this->getUser()->getId(), $tag->getId() @@ -159,7 +163,8 @@ class TagController extends Controller foreach ($entries as $entry) { $this->get('wallabag_core.tags_assigner')->assignTagsToEntry( $entry, - $form->get('label')->getData() + $newTagLabel, + [$newTag] ); $entry->removeTag($tag); } -- cgit v1.2.3 From a19caf8a37dfd59a4e270507ec08e9fc259e3e1e Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sat, 4 Apr 2020 22:08:08 +0200 Subject: TagController: prevent tag deletion when renaming a tag with the same label Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Controller/TagController.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index c228c27a..f7b78f5d 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -151,7 +151,10 @@ class TagController extends Controller $form = $this->createForm(RenameTagType::class, new Tag()); $form->handleRequest($request); - if ($form->isSubmitted() && $form->isValid()) { + if ($form->isSubmitted() + && $form->isValid() + && $form->get('label')->getData() !== $tag->getLabel() + ) { $newTagLabel = $form->get('label')->getData(); $newTag = new Tag(); $newTag->setLabel($newTagLabel); @@ -171,12 +174,12 @@ class TagController extends Controller $em = $this->getDoctrine()->getManager(); $em->flush(); - } - $this->get('session')->getFlashBag()->add( - 'notice', - 'flashes.tag.notice.tag_renamed' - ); + $this->get('session')->getFlashBag()->add( + 'notice', + 'flashes.tag.notice.tag_renamed' + ); + } $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true); -- cgit v1.2.3 From 48f9a9632d2823be38883628ddfe62344cc282b1 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Wed, 15 Apr 2020 22:41:03 +0200 Subject: TagController: support merging labels when renaming one with label of another Signed-off-by: Kevin Decherf --- .../CoreBundle/Controller/TagController.php | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index f7b78f5d..16ded948 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -151,13 +151,21 @@ class TagController extends Controller $form = $this->createForm(RenameTagType::class, new Tag()); $form->handleRequest($request); - if ($form->isSubmitted() - && $form->isValid() - && $form->get('label')->getData() !== $tag->getLabel() - ) { - $newTagLabel = $form->get('label')->getData(); + $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true); + + if ($form->isSubmitted() && $form->isValid()) { $newTag = new Tag(); - $newTag->setLabel($newTagLabel); + $newTag->setLabel($form->get('label')->getData()); + + if ($newTag->getLabel() === $tag->getLabel()) { + return $this->redirect($redirectUrl); + } + + $tagFromRepo = $this->get('wallabag_core.tag_repository')->findOneByLabel($newTag->getLabel()); + + if (null !== $tagFromRepo) { + $newTag = $tagFromRepo; + } $entries = $this->get('wallabag_core.entry_repository')->findAllByTagId( $this->getUser()->getId(), @@ -166,14 +174,13 @@ class TagController extends Controller foreach ($entries as $entry) { $this->get('wallabag_core.tags_assigner')->assignTagsToEntry( $entry, - $newTagLabel, + $newTag->getLabel(), [$newTag] ); $entry->removeTag($tag); } - $em = $this->getDoctrine()->getManager(); - $em->flush(); + $this->getDoctrine()->getManager()->flush(); $this->get('session')->getFlashBag()->add( 'notice', @@ -181,8 +188,6 @@ class TagController extends Controller ); } - $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true); - return $this->redirect($redirectUrl); } } -- cgit v1.2.3