Skip to content

Commit c998d46

Browse files
author
Claus
authored
Merge pull request #44 from umbraco/v3/feature/blocklist-improved-logging
Improved logging for Block Editor connector
2 parents ec4807f + 19a9d8b commit c998d46

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

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

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,37 @@ public BlockEditorValueConnector(IContentTypeService contentTypeService, Lazy<Va
3939

4040
public string ToArtifact(object value, PropertyType propertyType, ICollection<ArtifactDependency> dependencies)
4141
{
42+
_logger.Info<BlockEditorValueConnector>("Converting {PropertyType} to artifact.", propertyType.Alias);
4243
var svalue = value as string;
4344

4445
// nested values will arrive here as JObject - convert to string to enable reuse of same code as when non-nested.
4546
if (value is JObject)
47+
{
48+
_logger.Debug<BlockListValueConnector>("Value is a JObject - converting to string.");
4649
svalue = value.ToString();
50+
}
4751

4852
if (string.IsNullOrWhiteSpace(svalue))
53+
{
54+
_logger.Warn<BlockEditorValueConnector>($"Value is null or whitespace. Skipping conversion to artifact.");
4955
return null;
56+
}
5057

5158
if (svalue.DetectIsJson() == false)
59+
{
60+
_logger.Warn<BlockListValueConnector>("Value '{Value}' is not a json string. Skipping conversion to artifact.", svalue);
5261
return null;
62+
}
63+
5364
var blockEditorValue = JsonConvert.DeserializeObject<BlockEditorValue>(svalue);
5465

5566
if (blockEditorValue == null)
67+
{
68+
_logger.Warn<BlockEditorValueConnector>("Deserialized value is null. Skipping conversion to artifact.");
5669
return null;
70+
}
5771

58-
var allBlocks = blockEditorValue.Content.Concat(blockEditorValue.Settings);
72+
var allBlocks = blockEditorValue.Content.Concat(blockEditorValue.Settings).ToList();
5973

6074
// get all the content types used in block editor items
6175
var allContentTypes = allBlocks.Select(x => x.ContentTypeKey)
@@ -76,6 +90,7 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
7690
//Ensure that these content types have dependencies added
7791
foreach (var contentType in allContentTypes.Values)
7892
{
93+
_logger.Debug<BlockEditorValueConnector>("Adding dependency for content type {ContentType}.", contentType.Alias);
7994
dependencies.Add(new ArtifactDependency(contentType.GetUdi(), false, ArtifactDependencyMode.Match));
8095
}
8196

@@ -85,23 +100,23 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
85100

86101
foreach (var key in block.PropertyValues.Keys.ToArray())
87102
{
88-
var propType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
103+
var innerPropertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
89104

90-
if (propType == null)
105+
if (innerPropertyType == null)
91106
{
92-
_logger.Debug<BlockEditorValueConnector>("No property type found with alias {Key} on content type {ContentTypeAlias}.", key, contentType.Alias);
107+
_logger.Warn<BlockEditorValueConnector>("No property type found with alias {PropertyTypeAlias} on content type {ContentTypeAlias}.", key, contentType.Alias);
93108
continue;
94109
}
95110

96111
// fetch the right value connector from the collection of connectors, intended for use with this property type.
97112
// throws if not found - no need for a null check
98-
var propValueConnector = ValueConnectors.Get(propType);
113+
var propertyValueConnector = ValueConnectors.Get(innerPropertyType);
99114

100115
// 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);
116+
var innerValue = block.PropertyValues[key];
117+
object parsedValue = propertyValueConnector.ToArtifact(innerValue, innerPropertyType, dependencies);
103118

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

106121
parsedValue = parsedValue?.ToString();
107122

@@ -110,7 +125,8 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
110125
}
111126

112127
value = JsonConvert.SerializeObject(blockEditorValue);
113-
return (string)value;
128+
_logger.Info<BlockEditorValueConnector>("Finished converting {PropertyType} to artifact.", propertyType.Alias);
129+
return (string) value;
114130
}
115131

116132
public object FromArtifact(string value, PropertyType propertyType, object currentValue)
@@ -155,7 +171,7 @@ public object FromArtifact(string value, PropertyType propertyType, object curre
155171

156172
if (innerPropertyType == null)
157173
{
158-
_logger.Debug<BlockEditorValueConnector>("No property type found with alias {Key} on content type {ContentTypeAlias}.", key, contentType.Alias);
174+
_logger.Warn<BlockEditorValueConnector>("No property type found with alias {Key} on content type {ContentTypeAlias}.", key, contentType.Alias);
159175
continue;
160176
}
161177

0 commit comments

Comments
 (0)