Skip to content

Commit 8f3978a

Browse files
Merge pull request #46 from umbraco/fix-for-empty-blocks
Possible fix for an issue with transferring/restoring empty blocks
2 parents b56c611 + a5c650c commit 8f3978a

File tree

1 file changed

+47
-38
lines changed

1 file changed

+47
-38
lines changed

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

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,34 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
8383
{
8484
var contentType = allContentTypes[block.ContentTypeKey];
8585

86-
foreach (var key in block.PropertyValues.Keys.ToArray())
86+
if (block.PropertyValues != null)
8787
{
88-
var propType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
89-
90-
if (propType == null)
88+
foreach (var key in block.PropertyValues.Keys.ToArray())
9189
{
92-
_logger.Debug<BlockEditorValueConnector>("No property type found with alias {Key} on content type {ContentTypeAlias}.", key, contentType.Alias);
93-
continue;
94-
}
90+
var propType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
91+
92+
if (propType == null)
93+
{
94+
_logger.Debug<BlockEditorValueConnector>("No property type found with alias {Key} on content type {ContentTypeAlias}.", key, contentType.Alias);
95+
continue;
96+
}
9597

96-
// fetch the right value connector from the collection of connectors, intended for use with this property type.
97-
// throws if not found - no need for a null check
98-
var propValueConnector = ValueConnectors.Get(propType);
98+
// fetch the right value connector from the collection of connectors, intended for use with this property type.
99+
// throws if not found - no need for a null check
100+
var propValueConnector = ValueConnectors.Get(propType);
99101

100-
// pass the value, property type and the dependencies collection to the connector to get a "artifact" value
101-
var val = block.PropertyValues[key];
102-
object parsedValue = propValueConnector.ToArtifact(val, propType, dependencies);
102+
// pass the value, property type and the dependencies collection to the connector to get a "artifact" value
103+
var val = block.PropertyValues[key];
104+
object parsedValue = propValueConnector.ToArtifact(val, propType, dependencies);
103105

104-
_logger.Debug<BlockEditorValueConnector>("Map {Key} value '{PropertyValue}' to '{ParsedValue}' using {PropValueConnectorType} for {PropTypeAlias}.", key, block.PropertyValues[key], parsedValue, propValueConnector.GetType(), propType.Alias);
106+
_logger.Debug<BlockEditorValueConnector>("Map {Key} value '{PropertyValue}' to '{ParsedValue}' using {PropValueConnectorType} for {PropTypeAlias}.", key, block.PropertyValues[key], parsedValue, propValueConnector.GetType(), propType.Alias);
105107

106-
parsedValue = parsedValue?.ToString();
108+
parsedValue = parsedValue?.ToString();
107109

108-
block.PropertyValues[key] = parsedValue;
110+
block.PropertyValues[key] = parsedValue;
111+
}
109112
}
113+
110114
}
111115

112116
value = JsonConvert.SerializeObject(blockEditorValue);
@@ -149,40 +153,45 @@ public object FromArtifact(string value, PropertyType propertyType, object curre
149153
{
150154
var contentType = allContentTypes[block.ContentTypeKey];
151155

152-
foreach (var key in block.PropertyValues.Keys.ToArray())
156+
if (block.PropertyValues != null)
153157
{
154-
var innerPropertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
155-
156-
if (innerPropertyType == null)
158+
foreach (var key in block.PropertyValues.Keys.ToArray())
157159
{
158-
_logger.Debug<BlockEditorValueConnector>("No property type found with alias {Key} on content type {ContentTypeAlias}.", key, contentType.Alias);
159-
continue;
160-
}
160+
var innerPropertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
161161

162-
// fetch the right value connector from the collection of connectors, intended for use with this property type.
163-
// throws if not found - no need for a null check
164-
var propValueConnector = ValueConnectors.Get(innerPropertyType);
162+
if (innerPropertyType == null)
163+
{
164+
_logger.Debug<BlockEditorValueConnector>("No property type found with alias {Key} on content type {ContentTypeAlias}.", key, contentType.Alias);
165+
continue;
166+
}
165167

166-
var propertyValue = block.PropertyValues[key];
168+
// fetch the right value connector from the collection of connectors, intended for use with this property type.
169+
// throws if not found - no need for a null check
170+
var propValueConnector = ValueConnectors.Get(innerPropertyType);
167171

168-
if (propertyValue != null)
169-
{
170-
// pass the artifact value and property type to the connector to get a real value from the artifact
171-
var convertedValue = propValueConnector.FromArtifact(propertyValue.ToString(), innerPropertyType, null);
172-
if (convertedValue == null)
172+
var propertyValue = block.PropertyValues[key];
173+
174+
if (propertyValue != null)
173175
{
174-
block.PropertyValues[key] = null;
176+
// pass the artifact value and property type to the connector to get a real value from the artifact
177+
var convertedValue = propValueConnector.FromArtifact(propertyValue.ToString(), innerPropertyType, null);
178+
if (convertedValue == null)
179+
{
180+
block.PropertyValues[key] = null;
181+
}
182+
else
183+
{
184+
block.PropertyValues[key] = convertedValue;
185+
}
175186
}
176187
else
177188
{
178-
block.PropertyValues[key] = convertedValue;
189+
block.PropertyValues[key] = propertyValue;
179190
}
180191
}
181-
else
182-
{
183-
block.PropertyValues[key] = propertyValue;
184-
}
185192
}
193+
194+
186195
}
187196

188197
return JObject.FromObject(blockEditorValue);

0 commit comments

Comments
 (0)