[COMPONENT][Tag] Ensure only one copy of each tag is inserted

This commit is contained in:
Hugo Sales 2021-12-09 22:22:31 +00:00
parent ab9dd1db77
commit 45d1ca88a6
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
1 changed files with 3 additions and 1 deletions

View File

@ -39,6 +39,7 @@ use App\Util\HTML;
use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use Functional as F;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\HttpFoundation\Request;
@ -72,8 +73,9 @@ class Tag extends Component
$matched_tags = [];
$processed_tags = false;
preg_match_all(self::TAG_REGEX, $content, $matched_tags, \PREG_SET_ORDER);
$matched_tags = array_unique(F\map($matched_tags, fn ($m) => $m[2]));
foreach ($matched_tags as $match) {
$tag = self::ensureValid($match[2]);
$tag = self::ensureValid($match);
$canonical_tag = self::canonicalTag($tag, Language::getById($note->getLanguageId())->getLocale());
DB::persist(NoteTag::create([
'tag' => $tag,