Merge pull request #6629 from wallabag/fix-6330

Fix duplicate tags creation when assigning search results to tag
This commit is contained in:
Jérémy Benoist 2023-06-19 09:22:38 +02:00 committed by GitHub
commit 633122cfb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -247,11 +247,16 @@ class TagController extends AbstractController
$filter
);
$this->entityManager->persist($entry);
// check to avoid duplicate tags creation
foreach ($this->entityManager->getUnitOfWork()->getScheduledEntityInsertions() as $entity) {
if ($entity instanceof Tag && strtolower($entity->getLabel()) === strtolower($filter)) {
continue 2;
}
$this->entityManager->persist($entry);
}
$this->entityManager->flush();
}
$this->entityManager->flush();
return $this->redirect($this->redirectHelper->to($request->headers->get('referer'), '', true));
}

View file

@ -560,5 +560,12 @@ class TagControllerTest extends WallabagCoreTestCase
$this->assertContains('title', $tags);
}
$tag = $client->getContainer()
->get(EntityManagerInterface::class)
->getRepository(Tag::class)
->findByLabelsAndUser(['title'], $this->getLoggedInUserId());
$this->assertCount(1, $tag);
}
}