diff options
Diffstat (limited to 'src/Wallabag')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/TagController.php | 33 |
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 | } |