Merge pull request #1545 from wallabag/v2-user-tag

v2 – Remove user reference in tag
This commit is contained in:
Nicolas Lœuillet
2016-01-02 12:46:52 +01:00
13 changed files with 159 additions and 103 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();