aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2020-04-15 22:41:03 +0200
committerKevin Decherf <kevin@kdecherf.com>2020-04-18 18:12:33 +0200
commit48f9a9632d2823be38883628ddfe62344cc282b1 (patch)
treef1b2ae4caaaaed72e1a739b0712518d2728bb7c5 /src/Wallabag/CoreBundle
parenta19caf8a37dfd59a4e270507ec08e9fc259e3e1e (diff)
downloadwallabag-48f9a9632d2823be38883628ddfe62344cc282b1.tar.gz
wallabag-48f9a9632d2823be38883628ddfe62344cc282b1.tar.zst
wallabag-48f9a9632d2823be38883628ddfe62344cc282b1.zip
TagController: support merging labels when renaming one with label of another
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
Diffstat (limited to 'src/Wallabag/CoreBundle')
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php27
1 files changed, 16 insertions, 11 deletions
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
151 $form = $this->createForm(RenameTagType::class, new Tag()); 151 $form = $this->createForm(RenameTagType::class, new Tag());
152 $form->handleRequest($request); 152 $form->handleRequest($request);
153 153
154 if ($form->isSubmitted() 154 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true);
155 && $form->isValid() 155
156 && $form->get('label')->getData() !== $tag->getLabel() 156 if ($form->isSubmitted() && $form->isValid()) {
157 ) {
158 $newTagLabel = $form->get('label')->getData();
159 $newTag = new Tag(); 157 $newTag = new Tag();
160 $newTag->setLabel($newTagLabel); 158 $newTag->setLabel($form->get('label')->getData());
159
160 if ($newTag->getLabel() === $tag->getLabel()) {
161 return $this->redirect($redirectUrl);
162 }
163
164 $tagFromRepo = $this->get('wallabag_core.tag_repository')->findOneByLabel($newTag->getLabel());
165
166 if (null !== $tagFromRepo) {
167 $newTag = $tagFromRepo;
168 }
161 169
162 $entries = $this->get('wallabag_core.entry_repository')->findAllByTagId( 170 $entries = $this->get('wallabag_core.entry_repository')->findAllByTagId(
163 $this->getUser()->getId(), 171 $this->getUser()->getId(),
@@ -166,14 +174,13 @@ class TagController extends Controller
166 foreach ($entries as $entry) { 174 foreach ($entries as $entry) {
167 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry( 175 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry(
168 $entry, 176 $entry,
169 $newTagLabel, 177 $newTag->getLabel(),
170 [$newTag] 178 [$newTag]
171 ); 179 );
172 $entry->removeTag($tag); 180 $entry->removeTag($tag);
173 } 181 }
174 182
175 $em = $this->getDoctrine()->getManager(); 183 $this->getDoctrine()->getManager()->flush();
176 $em->flush();
177 184
178 $this->get('session')->getFlashBag()->add( 185 $this->get('session')->getFlashBag()->add(
179 'notice', 186 'notice',
@@ -181,8 +188,6 @@ class TagController extends Controller
181 ); 188 );
182 } 189 }
183 190
184 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true);
185
186 return $this->redirect($redirectUrl); 191 return $this->redirect($redirectUrl);
187 } 192 }
188} 193}