Skip to content

Commit 7d80d25

Browse files
authored
Merge pull request #27 from rbottema/job_tag_processing
Fix tag processing to not skip tags and in cases where a content item has multiple tag properties
2 parents b88526e + d87be23 commit 7d80d25

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

src/Geta.Optimizely.Tags/TagsScheduledJob.cs

+16-26
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public override string Execute()
6666

6767
if (content == null || (content is PageData data && data.IsDeleted))
6868
{
69-
RemoveFromAllTags(contentGuid, tags);
69+
RemoveFromTags(contentGuid, tags);
7070
continue;
7171
}
7272

@@ -80,31 +80,23 @@ private void CheckContentProperties(IContent content, IList<Tag> tags)
8080
{
8181
var contentType = _contentTypeRepository.Load(content.ContentTypeID);
8282

83-
foreach (var propertyDefinition in contentType.PropertyDefinitions)
84-
{
85-
if (!TagsHelper.IsTagProperty(propertyDefinition))
86-
{
87-
continue;
88-
}
89-
90-
var tagNames = GetTagNames(content, propertyDefinition);
91-
92-
var allTags = tags;
83+
var tagProperties = contentType.PropertyDefinitions
84+
.Where(TagsHelper.IsTagProperty);
9385

94-
if (tagNames == null)
95-
{
96-
RemoveFromAllTags(content.ContentGuid, allTags);
97-
continue;
98-
}
86+
var contentTagNames = tagProperties
87+
.Select(propertyDefinition => GetTagNames(content, propertyDefinition))
88+
.Where(tagNames => !string.IsNullOrEmpty(tagNames));
9989

100-
var addedTags = ParseTags(tagNames);
90+
var contentTags = contentTagNames
91+
.SelectMany(ParseTags)
92+
.Distinct()
93+
.ToList();
10194

102-
// make sure the tags it has added has the ContentReference
103-
ValidateTags(allTags, content.ContentGuid, addedTags);
95+
// make sure the tags it has added has the ContentReference
96+
ValidateTags(content.ContentGuid, contentTags);
10497

105-
// make sure there's no ContentReference to this ContentReference in the rest of the tags
106-
RemoveFromAllTags(content.ContentGuid, allTags);
107-
}
98+
// make sure there's no ContentReference to this ContentReference in the rest of the tags
99+
RemoveFromTags(content.ContentGuid, tags.Except(contentTags));
108100
}
109101

110102
private string GetTagNames(IContent content, PropertyDefinition propertyDefinition)
@@ -142,12 +134,10 @@ private IEnumerable<Tag> ParseTags(string tagNames)
142134
.ToList();
143135
}
144136

145-
private void ValidateTags(ICollection<Tag> allTags, Guid contentGuid, IEnumerable<Tag> addedTags)
137+
private void ValidateTags(Guid contentGuid, IEnumerable<Tag> addedTags)
146138
{
147139
foreach (var addedTag in addedTags)
148140
{
149-
allTags.Remove(addedTag);
150-
151141
if (addedTag.PermanentLinks.Contains(contentGuid)) continue;
152142

153143
addedTag.PermanentLinks.Add(contentGuid);
@@ -156,7 +146,7 @@ private void ValidateTags(ICollection<Tag> allTags, Guid contentGuid, IEnumerabl
156146
}
157147
}
158148

159-
private void RemoveFromAllTags(Guid guid, IEnumerable<Tag> tags)
149+
private void RemoveFromTags(Guid guid, IEnumerable<Tag> tags)
160150
{
161151
foreach (var tag in tags)
162152
{

0 commit comments

Comments
 (0)