aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2020-04-20 18:02:31 +0200
committerGitHub <noreply@github.com>2020-04-20 18:02:31 +0200
commit2ca2ed39fd9bcaa212185ce4434cea44f3d2f4ba (patch)
tree5750b751e51313e95d433a4cc3c8a873e48a1227 /src/Wallabag/CoreBundle
parent7443da479f5289c2ceebb96c0cd4273f6445ca37 (diff)
parent48f9a9632d2823be38883628ddfe62344cc282b1 (diff)
downloadwallabag-2ca2ed39fd9bcaa212185ce4434cea44f3d2f4ba.tar.gz
wallabag-2ca2ed39fd9bcaa212185ce4434cea44f3d2f4ba.tar.zst
wallabag-2ca2ed39fd9bcaa212185ce4434cea44f3d2f4ba.zip
Merge pull request #4310 from wallabag/fix/4216
TagController: fix duplicated tags when renaming them
Diffstat (limited to 'src/Wallabag/CoreBundle')
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php
index a6ad131f..16ded948 100644
--- a/src/Wallabag/CoreBundle/Controller/TagController.php
+++ b/src/Wallabag/CoreBundle/Controller/TagController.php
@@ -151,7 +151,22 @@ 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 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true);
155
154 if ($form->isSubmitted() && $form->isValid()) { 156 if ($form->isSubmitted() && $form->isValid()) {
157 $newTag = new Tag();
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 }
169
155 $entries = $this->get('wallabag_core.entry_repository')->findAllByTagId( 170 $entries = $this->get('wallabag_core.entry_repository')->findAllByTagId(
156 $this->getUser()->getId(), 171 $this->getUser()->getId(),
157 $tag->getId() 172 $tag->getId()
@@ -159,21 +174,19 @@ class TagController extends Controller
159 foreach ($entries as $entry) { 174 foreach ($entries as $entry) {
160 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry( 175 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry(
161 $entry, 176 $entry,
162 $form->get('label')->getData() 177 $newTag->getLabel(),
178 [$newTag]
163 ); 179 );
164 $entry->removeTag($tag); 180 $entry->removeTag($tag);
165 } 181 }
166 182
167 $em = $this->getDoctrine()->getManager(); 183 $this->getDoctrine()->getManager()->flush();
168 $em->flush();
169 }
170
171 $this->get('session')->getFlashBag()->add(
172 'notice',
173 'flashes.tag.notice.tag_renamed'
174 );
175 184
176 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true); 185 $this->get('session')->getFlashBag()->add(
186 'notice',
187 'flashes.tag.notice.tag_renamed'
188 );
189 }
177 190
178 return $this->redirect($redirectUrl); 191 return $this->redirect($redirectUrl);
179 } 192 }