Skip to content

Commit fd76c4b

Browse files
committed
change innerContentConnector to either lookup contenttypes by guids or aliases
1 parent b901b1a commit fd76c4b

File tree

1 file changed

+24
-39
lines changed

1 file changed

+24
-39
lines changed

src/Umbraco.Deploy.Contrib.Connectors/ValueConnectors/InnerContentConnector.cs

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,15 @@ public string GetValue(Property property, ICollection<ArtifactDependency> depend
6060
if (innerContent == null)
6161
return null;
6262

63-
var allContentTypes = innerContent.Select(x => x.IcContentTypeAlias)
64-
.Distinct()
65-
.ToDictionary(a => a, a => _contentTypeService.GetContentType(a));
66-
67-
//Ensure all of these content types are found
68-
if (allContentTypes.Values.Any(contentType => contentType == null))
69-
{
70-
throw new InvalidOperationException($"Could not resolve these content types for the Inner Content property: {string.Join(",", allContentTypes.Where(x => x.Value == null).Select(x => x.Key))}");
71-
}
72-
73-
//Ensure that these content types have dependencies added
74-
foreach (var contentType in allContentTypes.Values)
75-
{
76-
dependencies.Add(new ArtifactDependency(contentType.GetUdi(), false, ArtifactDependencyMode.Match));
77-
}
78-
79-
foreach (var row in innerContent)
63+
foreach (var innerContentItem in innerContent)
8064
{
81-
var contentType = allContentTypes[row.IcContentTypeAlias];
65+
var contentType = _contentTypeService.GetContentType(innerContentItem.IcContentTypeGuid);
66+
if (contentType == null)
67+
contentType = _contentTypeService.GetContentType(innerContentItem.IcContentTypeAlias);
68+
if (contentType == null)
69+
throw new InvalidOperationException($"Could not resolve these content types for the Inner Content property with key: {innerContentItem.Key}, and name: {innerContentItem.Name}");
8270

83-
foreach (var key in row.PropertyValues.Keys.ToArray())
71+
foreach (var key in innerContentItem.PropertyValues.Keys.ToArray())
8472
{
8573
var propertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
8674

@@ -95,7 +83,7 @@ public string GetValue(Property property, ICollection<ArtifactDependency> depend
9583

9684
// this should be enough for all other value connectors to work with
9785
// as all they should need is the value, and the property type infos
98-
var mockProperty = new Property(propertyType, row.PropertyValues[key]);
86+
var mockProperty = new Property(propertyType, innerContentItem.PropertyValues[key]);
9987

10088
object parsedValue = propValueConnector.GetValue(mockProperty, dependencies);
10189

@@ -111,7 +99,7 @@ public string GetValue(Property property, ICollection<ArtifactDependency> depend
11199
parsedValue = parsedValue.ToString();
112100
}
113101

114-
row.PropertyValues[key] = parsedValue;
102+
innerContentItem.PropertyValues[key] = parsedValue;
115103
}
116104
}
117105

@@ -147,21 +135,16 @@ public void SetValue(IContentBase content, string alias, string value)
147135
if (innerContent == null)
148136
return;
149137

150-
var allContentTypes = innerContent.Select(x => x.IcContentTypeAlias)
151-
.Distinct()
152-
.ToDictionary(a => a, a => _contentTypeService.GetContentType(a));
153-
154-
//Ensure all of these content types are found
155-
if (allContentTypes.Values.Any(contentType => contentType == null))
138+
foreach (var innerContentItem in innerContent)
156139
{
157-
throw new InvalidOperationException($"Could not resolve these content types for the Inner Content property: {string.Join(",", allContentTypes.Where(x => x.Value == null).Select(x => x.Key))}");
158-
}
140+
var contentType = _contentTypeService.GetContentType(innerContentItem.IcContentTypeGuid);
141+
if (contentType == null)
142+
contentType = _contentTypeService.GetContentType(innerContentItem.IcContentTypeAlias);
143+
if (contentType == null)
144+
throw new InvalidOperationException($"Could not resolve these content types for the Inner Content property with key: {innerContentItem.Key}, and name: {innerContentItem.Name}");
159145

160-
var mocks = new Dictionary<IContentType, IContent>();
161146

162-
foreach (var row in innerContent)
163-
{
164-
var contentType = allContentTypes[row.IcContentTypeAlias];
147+
var mocks = new Dictionary<IContentType, IContent>();
165148

166149
// note
167150
// the way we do it here, doing content.SetValue() several time on the same content, reduces
@@ -176,7 +159,7 @@ public void SetValue(IContentBase content, string alias, string value)
176159
if (!mocks.TryGetValue(contentType, out mockContent))
177160
mockContent = mocks[contentType] = new Content("IC_" + Guid.NewGuid(), -1, contentType);
178161

179-
foreach (var key in row.PropertyValues.Keys.ToArray())
162+
foreach (var key in innerContentItem.PropertyValues.Keys.ToArray())
180163
{
181164
var propertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
182165

@@ -189,7 +172,7 @@ public void SetValue(IContentBase content, string alias, string value)
189172
// throws if not found - no need for a null check
190173
var propValueConnector = ValueConnectors.Get(propertyType);
191174

192-
var rowValue = row.PropertyValues[key];
175+
var rowValue = innerContentItem.PropertyValues[key];
193176

194177
if (rowValue != null)
195178
{
@@ -198,7 +181,7 @@ public void SetValue(IContentBase content, string alias, string value)
198181
// integers needs to be converted into strings
199182
if (convertedValue is int)
200183
{
201-
row.PropertyValues[key] = convertedValue.ToString();
184+
innerContentItem.PropertyValues[key] = convertedValue.ToString();
202185
}
203186
else
204187
{
@@ -207,17 +190,17 @@ public void SetValue(IContentBase content, string alias, string value)
207190
var jtokenValue = convertedValue.ToString().DetectIsJson() ? JToken.Parse(convertedValue.ToString()) : null;
208191
if (jtokenValue != null)
209192
{
210-
row.PropertyValues[key] = jtokenValue;
193+
innerContentItem.PropertyValues[key] = jtokenValue;
211194
}
212195
else
213196
{
214-
row.PropertyValues[key] = convertedValue;
197+
innerContentItem.PropertyValues[key] = convertedValue;
215198
}
216199
}
217200
}
218201
else
219202
{
220-
row.PropertyValues[key] = rowValue;
203+
innerContentItem.PropertyValues[key] = rowValue;
221204
}
222205
}
223206
}
@@ -250,6 +233,8 @@ public class InnerContentValue
250233
public string Icon { get; set; }
251234
[JsonProperty("icContentTypeAlias")]
252235
public string IcContentTypeAlias { get; set; }
236+
[JsonProperty("icContentTypeGuid")]
237+
public Guid IcContentTypeGuid { get; set; }
253238

254239
/// <summary>
255240
/// The remaining properties will be serialized to a dictionary

0 commit comments

Comments
 (0)