Remove user reference in tag

Fix #1543
This commit is contained in:
Jeremy Benoist
2015-12-29 14:50:52 +01:00
parent c997cfcc9c
commit fc73222723
13 changed files with 123 additions and 99 deletions

View File

@ -20,25 +20,23 @@ class TagController extends Controller
*/
public function addTagFormAction(Request $request, Entry $entry)
{
$tag = new Tag($this->getUser());
$tag = new Tag();
$form = $this->createForm(new NewTagType(), $tag);
$form->handleRequest($request);
if ($form->isValid()) {
$existingTag = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Tag')
->findOneByLabelAndUserId($tag->getLabel(), $this->getUser()->getId());
->findOneByLabel($tag->getLabel());
$em = $this->getDoctrine()->getManager();
if (is_null($existingTag)) {
$entry->addTag($tag);
$em->persist($tag);
} else {
if (!$existingTag->hasEntry($entry)) {
$entry->addTag($existingTag);
$em->persist($existingTag);
}
} elseif (!$existingTag->hasEntry($entry)) {
$entry->addTag($existingTag);
$em->persist($existingTag);
}
$em->flush();