mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 08:56:42 -06:00
Trying to automatically persist tags
This commit is contained in:
parent
f4e9d0c8fe
commit
1937f3ea22
@ -60,6 +60,7 @@ $builder->createManyToMany('tags', Entity\Tag::class)
|
||||
->setJoinTable('short_urls_in_tags')
|
||||
->addInverseJoinColumn('tag_id', 'id', true, false, 'CASCADE')
|
||||
->addJoinColumn('short_url_id', 'id', true, false, 'CASCADE')
|
||||
->cascadePersist()
|
||||
->build();
|
||||
|
||||
$builder->createManyToOne('domain', Entity\Domain::class)
|
||||
|
@ -24,21 +24,20 @@ trait TagManagerTrait
|
||||
$entities = [];
|
||||
foreach ($tags as $tagName) {
|
||||
$tagName = $this->normalizeTagName($tagName);
|
||||
$tag = $em->getRepository(Tag::class)->findOneBy(['name' => $tagName]) ?: new Tag($tagName);
|
||||
$em->persist($tag);
|
||||
$tag = $em->getRepository(Tag::class)->findOneBy(['name' => $tagName]) ?? new Tag($tagName);
|
||||
|
||||
// if (! $tag) {
|
||||
// $tag = ;
|
||||
// $em->persist($tag);
|
||||
// }
|
||||
|
||||
$entities[] = $tag;
|
||||
}
|
||||
|
||||
return new Collections\ArrayCollection($entities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag names are trimmed, lower cased and spaces are replaced by dashes
|
||||
*
|
||||
* @param string $tagName
|
||||
* @return string
|
||||
*/
|
||||
private function normalizeTagName($tagName): string
|
||||
private function normalizeTagName(string $tagName): string
|
||||
{
|
||||
return str_replace(' ', '-', strtolower(trim($tagName)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user