Avoid tag duplication when tagging all articles

Mostly when the tag doesn’t yet exist.
It was created each time it matche the rule… glups.
This commit is contained in:
Jeremy Benoist 2016-10-09 18:32:17 +02:00
parent 4d318f3755
commit b4fcd60e7f
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C

View file

@ -55,6 +55,7 @@ class RuleBasedTagger
{
$rules = $this->getRulesForUser($user);
$entries = [];
$tagsCache = [];
foreach ($rules as $rule) {
$qb = $this->entryRepository->getBuilderForAllByUser($user->getId());
@ -62,7 +63,12 @@ class RuleBasedTagger
foreach ($entries as $entry) {
foreach ($rule->getTags() as $label) {
$tag = $this->getTag($label);
// avoid new tag duplicate by manually caching them
if (!isset($tagsCache[$label])) {
$tagsCache[$label] = $this->getTag($label);
}
$tag = $tagsCache[$label];
$entry->addTag($tag);
}