@@ -66,7 +66,7 @@ public override string Execute()
66
66
67
67
if ( content == null || ( content is PageData data && data . IsDeleted ) )
68
68
{
69
- RemoveFromAllTags ( contentGuid , tags ) ;
69
+ RemoveFromTags ( contentGuid , tags ) ;
70
70
continue ;
71
71
}
72
72
@@ -80,31 +80,23 @@ private void CheckContentProperties(IContent content, IList<Tag> tags)
80
80
{
81
81
var contentType = _contentTypeRepository . Load ( content . ContentTypeID ) ;
82
82
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 ) ;
93
85
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 ) ) ;
99
89
100
- var addedTags = ParseTags ( tagNames ) ;
90
+ var contentTags = contentTagNames
91
+ . SelectMany ( ParseTags )
92
+ . Distinct ( )
93
+ . ToList ( ) ;
101
94
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 ) ;
104
97
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 ) ) ;
108
100
}
109
101
110
102
private string GetTagNames ( IContent content , PropertyDefinition propertyDefinition )
@@ -142,12 +134,10 @@ private IEnumerable<Tag> ParseTags(string tagNames)
142
134
. ToList ( ) ;
143
135
}
144
136
145
- private void ValidateTags ( ICollection < Tag > allTags , Guid contentGuid , IEnumerable < Tag > addedTags )
137
+ private void ValidateTags ( Guid contentGuid , IEnumerable < Tag > addedTags )
146
138
{
147
139
foreach ( var addedTag in addedTags )
148
140
{
149
- allTags . Remove ( addedTag ) ;
150
-
151
141
if ( addedTag . PermanentLinks . Contains ( contentGuid ) ) continue ;
152
142
153
143
addedTag . PermanentLinks . Add ( contentGuid ) ;
@@ -156,7 +146,7 @@ private void ValidateTags(ICollection<Tag> allTags, Guid contentGuid, IEnumerabl
156
146
}
157
147
}
158
148
159
- private void RemoveFromAllTags ( Guid guid , IEnumerable < Tag > tags )
149
+ private void RemoveFromTags ( Guid guid , IEnumerable < Tag > tags )
160
150
{
161
151
foreach ( var tag in tags )
162
152
{
0 commit comments