mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 17:44:44 +08:00
Updated PersistenceShortUrlRelationResolver to prevent duplicated tags
This commit is contained in:
@@ -11,6 +11,7 @@ use Shlinkio\Shlink\Core\Entity\Domain;
|
||||
use Shlinkio\Shlink\Core\Entity\Tag;
|
||||
|
||||
use function Functional\map;
|
||||
use function Functional\unique;
|
||||
|
||||
class PersistenceShortUrlRelationResolver implements ShortUrlRelationResolverInterface
|
||||
{
|
||||
@@ -42,7 +43,9 @@ class PersistenceShortUrlRelationResolver implements ShortUrlRelationResolverInt
|
||||
return new Collections\ArrayCollection();
|
||||
}
|
||||
|
||||
$tags = unique($tags);
|
||||
$repo = $this->em->getRepository(Tag::class);
|
||||
|
||||
return new Collections\ArrayCollection(map($tags, function (string $tagName) use ($repo): Tag {
|
||||
$tag = $repo->findOneBy(['name' => $tagName]) ?? new Tag($tagName);
|
||||
$this->em->persist($tag);
|
||||
|
||||
Reference in New Issue
Block a user