Skip to content

Commit e3c77f3

Browse files
authored
Merge pull request #19 from UmbrellaInc/patch/ic-zero-props
InnerContentConnector - null check if the doctype has zero properties
2 parents 16cd10d + 55195c2 commit e3c77f3

File tree

1 file changed

+61
-55
lines changed

1 file changed

+61
-55
lines changed

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

Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -79,38 +79,41 @@ public string GetValue(Property property, ICollection<ArtifactDependency> depend
7979
dependencies.Add(new ArtifactDependency(contentTypeUdi,false,ArtifactDependencyMode.Match));
8080
}
8181

82-
foreach (var key in innerContentItem.PropertyValues.Keys.ToArray())
82+
if (innerContentItem.PropertyValues != null)
8383
{
84-
var propertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
85-
86-
if (propertyType == null)
84+
foreach (var key in innerContentItem.PropertyValues.Keys.ToArray())
8785
{
88-
LogHelper.Debug<InnerContentConnector>($"No Property Type found with alias {key} on Content Type {contentType.Alias}");
89-
continue;
90-
}
86+
var propertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
9187

92-
// throws if not found - no need for a null check
93-
var propValueConnector = ValueConnectors.Get(propertyType);
88+
if (propertyType == null)
89+
{
90+
LogHelper.Debug<InnerContentConnector>($"No Property Type found with alias {key} on Content Type {contentType.Alias}");
91+
continue;
92+
}
9493

95-
// this should be enough for all other value connectors to work with
96-
// as all they should need is the value, and the property type infos
97-
var mockProperty = new Property(propertyType, innerContentItem.PropertyValues[key]);
94+
// throws if not found - no need for a null check
95+
var propValueConnector = ValueConnectors.Get(propertyType);
9896

99-
object parsedValue = propValueConnector.GetValue(mockProperty, dependencies);
97+
// this should be enough for all other value connectors to work with
98+
// as all they should need is the value, and the property type infos
99+
var mockProperty = new Property(propertyType, innerContentItem.PropertyValues[key]);
100100

101-
// test if the value is a json object (thus could be a nested complex editor)
102-
// if that's the case we'll need to add it as a json object instead of string to avoid it being escaped
103-
var jtokenValue = parsedValue != null && parsedValue.ToString().DetectIsJson() ? JToken.Parse(parsedValue.ToString()) : null;
104-
if (jtokenValue != null)
105-
{
106-
parsedValue = jtokenValue;
107-
}
108-
else if (parsedValue != null)
109-
{
110-
parsedValue = parsedValue.ToString();
111-
}
101+
object parsedValue = propValueConnector.GetValue(mockProperty, dependencies);
112102

113-
innerContentItem.PropertyValues[key] = parsedValue;
103+
// test if the value is a json object (thus could be a nested complex editor)
104+
// if that's the case we'll need to add it as a json object instead of string to avoid it being escaped
105+
var jtokenValue = parsedValue != null && parsedValue.ToString().DetectIsJson() ? JToken.Parse(parsedValue.ToString()) : null;
106+
if (jtokenValue != null)
107+
{
108+
parsedValue = jtokenValue;
109+
}
110+
else if (parsedValue != null)
111+
{
112+
parsedValue = parsedValue.ToString();
113+
}
114+
115+
innerContentItem.PropertyValues[key] = parsedValue;
116+
}
114117
}
115118
}
116119

@@ -171,48 +174,51 @@ public void SetValue(IContentBase content, string alias, string value)
171174
if (!mocks.TryGetValue(contentType, out mockContent))
172175
mockContent = mocks[contentType] = new Content("IC_" + Guid.NewGuid(), -1, contentType);
173176

174-
foreach (var key in innerContentItem.PropertyValues.Keys.ToArray())
177+
if (innerContentItem.PropertyValues != null)
175178
{
176-
var propertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
177-
178-
if (propertyType == null)
179+
foreach (var key in innerContentItem.PropertyValues.Keys.ToArray())
179180
{
180-
LogHelper.Debug<InnerContentConnector>($"No Property Type found with alias {key} on Content Type {contentType.Alias}");
181-
continue;
182-
}
183-
184-
// throws if not found - no need for a null check
185-
var propValueConnector = ValueConnectors.Get(propertyType);
186-
187-
var rowValue = innerContentItem.PropertyValues[key];
181+
var propertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
188182

189-
if (rowValue != null)
190-
{
191-
propValueConnector.SetValue(mockContent, propertyType.Alias, rowValue.ToString());
192-
var convertedValue = mockContent.GetValue(propertyType.Alias);
193-
// integers needs to be converted into strings
194-
if (convertedValue is int)
183+
if (propertyType == null)
195184
{
196-
innerContentItem.PropertyValues[key] = convertedValue.ToString();
185+
LogHelper.Debug<InnerContentConnector>($"No Property Type found with alias {key} on Content Type {contentType.Alias}");
186+
continue;
197187
}
198-
else
188+
189+
// throws if not found - no need for a null check
190+
var propValueConnector = ValueConnectors.Get(propertyType);
191+
192+
var rowValue = innerContentItem.PropertyValues[key];
193+
194+
if (rowValue != null)
199195
{
200-
// test if the value is a json object (thus could be a nested complex editor)
201-
// if that's the case we'll need to add it as a json object instead of string to avoid it being escaped
202-
var jtokenValue = convertedValue.ToString().DetectIsJson() ? JToken.Parse(convertedValue.ToString()) : null;
203-
if (jtokenValue != null)
196+
propValueConnector.SetValue(mockContent, propertyType.Alias, rowValue.ToString());
197+
var convertedValue = mockContent.GetValue(propertyType.Alias);
198+
// integers needs to be converted into strings
199+
if (convertedValue is int)
204200
{
205-
innerContentItem.PropertyValues[key] = jtokenValue;
201+
innerContentItem.PropertyValues[key] = convertedValue.ToString();
206202
}
207203
else
208204
{
209-
innerContentItem.PropertyValues[key] = convertedValue;
205+
// test if the value is a json object (thus could be a nested complex editor)
206+
// if that's the case we'll need to add it as a json object instead of string to avoid it being escaped
207+
var jtokenValue = convertedValue.ToString().DetectIsJson() ? JToken.Parse(convertedValue.ToString()) : null;
208+
if (jtokenValue != null)
209+
{
210+
innerContentItem.PropertyValues[key] = jtokenValue;
211+
}
212+
else
213+
{
214+
innerContentItem.PropertyValues[key] = convertedValue;
215+
}
210216
}
211217
}
212-
}
213-
else
214-
{
215-
innerContentItem.PropertyValues[key] = rowValue;
218+
else
219+
{
220+
innerContentItem.PropertyValues[key] = rowValue;
221+
}
216222
}
217223
}
218224
}

0 commit comments

Comments
 (0)