Skip to content

Conversation

@hakksor
Copy link
Contributor

@hakksor hakksor commented Sep 22, 2022

This happens when using a combination of culture specific and explicit group key.

The issue can be reproduced by creating property using the following configuration:

[TagsGroupKey("articles:")]
[GetaTags(AllowSpaces = true, CaseSensitive = false)]
[UIHint("Tags")]
[CultureSpecific]
[Display(Name = "Tags", Order = 100)]
public virtual string Tags { get; set; }

Adding tags works fine, and also removing tags work fine in the editor view.
However, when using ITagEngine.GetContentReferencesByTags the returned results includes the IContent where the tags were removed. Upon further investigation I found that the tags won't get deleted in TagService.RemoveOldContentTags() since the tag GroupKey doesn't match the IContents languagebranch.
In the previous case the tag's GroupKey will be articles:sv or articles:en, but TagService.RemoveOldContentTags() will skip since it looks for sv or en specifically.
Changing tag.GroupKey != language to !tag.GroupKey.EndsWith(language) fixes this problem since the language be appended to the groupkey in TagsHelper.GetGroupKeyFromAttributes():

public static string GetGroupKeyFromAttributes(
            TagsGroupKeyAttribute groupKeyAttribute,
            CultureSpecificAttribute cultureSpecificAttribute,
            IContent content)
        {
            var groupKey = string.Empty;

            if (groupKeyAttribute == null && cultureSpecificAttribute == null && content is ILocalizable localizableContent)
            {
                groupKey += localizableContent.MasterLanguage;
            }

            if (groupKeyAttribute != null)
            {
                groupKey += groupKeyAttribute.Key;
            }

            if (cultureSpecificAttribute != null && cultureSpecificAttribute.IsCultureSpecific)
            {
                groupKey += ContentLanguage.PreferredCulture ?? CultureInfo.CurrentCulture;
            }

            return groupKey;
        }

… explicit group key wouldn't get cleared when removed from content
@marisks marisks merged commit 3d52d22 into Geta:master Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants