Skip to content

Commit 329b0e7

Browse files
committed
Merge branch 'v4/4.2' into v9/9.1
# Conflicts: # build/version.txt # src/Umbraco.Deploy.Contrib.Connectors/GridCellValueConnectors/DocTypeGridEditorCellValueConnector.cs # src/Umbraco.Deploy.Contrib.Connectors/Umbraco.Deploy.Contrib.Connectors.csproj # src/Umbraco.Deploy.Contrib/Properties/VersionInfo.cs # src/Umbraco.Deploy.Contrib/ValueConnectors/BlockEditorValueConnector.cs # src/Umbraco.Deploy.Contrib/ValueConnectors/NestedContentValueConnector.cs
2 parents 3e19c08 + 8ab65d0 commit 329b0e7

File tree

4 files changed

+49
-31
lines changed

4 files changed

+49
-31
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22

33
# Umbraco Deploy Contrib
44

5-
This project contains community contributions for Umbraco Deploy targetted for version 8.
5+
This project contains community contributions for Umbraco Deploy targetted for version 8 and above.
66

77
Primarily this project offers connectors for the most popular Umbraco community packages - these are used by Deploy to aid with the deployment and transferring of content/property-data between environments on [Umbraco Cloud](https://umbraco.com/cloud).
88

9+
## Branching
10+
11+
The main branches corresponding to the Umbraco and Umbraco Deploy major releases are:
12+
13+
- Umbraco 8/Deploy 4: `v4/dev`
14+
- Umbraco 9/Deploy 9: `v9/dev`
15+
- Umbraco 10/Deploy 10: `v10/dev`
916

1017
## Connectors
1118

@@ -25,7 +32,9 @@ Value connectors for certain core property editors are also included:
2532

2633
### Installation
2734

28-
You can install the NuGet package using `Install-Package UmbracoDeploy.Contrib`.
35+
When working with Umbraco 8, you can install the NuGet package using `Install-Package UmbracoDeploy.Contrib`.
36+
37+
For Umbraco 9+ the package is available for install by: `Install-Package Umbraco.Deploy.Contrib`
2938

3039
---
3140
## Contributing to this project

src/Umbraco.Deploy.Contrib/Umbraco.Deploy.Contrib.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
11-
<PackageReference Include="Umbraco.Deploy.Core" Version="9.5.0" />
10+
<PackageReference Include="Umbraco.Deploy.Infrastructure" Version="9.5.0" />
1211
</ItemGroup>
1312
</Project>

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Umbraco.Deploy.Core.Connectors;
1212
using Umbraco.Deploy.Core.Connectors.ValueConnectors;
1313
using Umbraco.Deploy.Core.Connectors.ValueConnectors.Services;
14+
using Umbraco.Deploy.Infrastructure.Extensions;
1415
using Umbraco.Extensions;
1516

1617
namespace Umbraco.Deploy.Contrib.ValueConnectors
@@ -47,29 +48,27 @@ public BlockEditorValueConnector(IContentTypeService contentTypeService, Lazy<Va
4748
public override string ToArtifact(object value, IPropertyType propertyType, ICollection<ArtifactDependency> dependencies, IContextCache contextCache)
4849
{
4950
_logger.LogDebug("Converting {PropertyType} to artifact.", propertyType.Alias);
50-
var svalue = value as string;
51+
var valueAsString = value as string;
5152

5253
// nested values will arrive here as JObject - convert to string to enable reuse of same code as when non-nested.
5354
if (value is JObject)
5455
{
5556
_logger.LogDebug("Value is a JObject - converting to string.");
56-
svalue = value.ToString();
57+
valueAsString = value.ToString();
5758
}
5859

59-
if (string.IsNullOrWhiteSpace(svalue))
60+
if (string.IsNullOrWhiteSpace(valueAsString))
6061
{
6162
_logger.LogDebug($"Value is null or whitespace. Skipping conversion to artifact.");
6263
return null;
6364
}
6465

65-
if (svalue.DetectIsJson() == false)
66+
if (!valueAsString.TryParseJson(out BlockEditorValue blockEditorValue))
6667
{
67-
_logger.LogWarning("Value '{Value}' is not a json string. Skipping conversion to artifact.", svalue);
68+
_logger.LogWarning("Value '{Value}' is not a JSON string. Skipping conversion to artifact.", valueAsString);
6869
return null;
6970
}
7071

71-
var blockEditorValue = JsonConvert.DeserializeObject<BlockEditorValue>(svalue);
72-
7372
if (blockEditorValue == null)
7473
{
7574
_logger.LogWarning("Deserialized value is null. Skipping conversion to artifact.");
@@ -148,13 +147,15 @@ public override object FromArtifact(string value, IPropertyType propertyType, ob
148147
return value;
149148
}
150149

151-
if (value.DetectIsJson() == false)
150+
if (!value.TryParseJson(out BlockEditorValue blockEditorValue))
151+
{
152152
return value;
153-
154-
var blockEditorValue = JsonConvert.DeserializeObject<BlockEditorValue>(value);
153+
}
155154

156155
if (blockEditorValue == null)
156+
{
157157
return value;
158+
}
158159

159160
var allBlocks = blockEditorValue.Content.Concat(blockEditorValue.Settings ?? Enumerable.Empty<Block>()).ToList();
160161

src/Umbraco.Deploy.Contrib/ValueConnectors/NestedContentValueConnector.cs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Umbraco.Deploy.Core.Connectors;
1212
using Umbraco.Deploy.Core.Connectors.ValueConnectors;
1313
using Umbraco.Deploy.Core.Connectors.ValueConnectors.Services;
14+
using Umbraco.Deploy.Infrastructure.Extensions;
1415
using Umbraco.Extensions;
1516

1617
namespace Umbraco.Deploy.Contrib.ValueConnectors
@@ -51,28 +52,38 @@ public NestedContentValueConnector(IContentTypeService contentTypeService, Lazy<
5152
public sealed override string ToArtifact(object value, IPropertyType propertyType, ICollection<ArtifactDependency> dependencies, IContextCache contextCache)
5253
{
5354
_logger.LogDebug("Converting {PropertyType} to artifact.", propertyType.Alias);
54-
var svalue = value as string;
55+
var valueAsString = value as string;
5556

56-
if (string.IsNullOrWhiteSpace(svalue))
57+
if (string.IsNullOrWhiteSpace(valueAsString))
5758
{
5859
_logger.LogDebug($"Value is null or whitespace. Skipping conversion to artifact.");
5960
return null;
6061
}
6162

62-
if (svalue.DetectIsJson() == false)
63-
{
64-
_logger.LogWarning("Value '{Value}' is not a json string. Skipping conversion to artifact.", svalue);
65-
return null;
66-
}
67-
6863
var nestedContent = new List<NestedContentValue>();
69-
if (svalue.Trim().StartsWith("{"))
64+
if (valueAsString.Trim().StartsWith("{"))
7065
{
71-
nestedContent.Add(JsonConvert.DeserializeObject<NestedContentValue>(svalue));
66+
if (valueAsString.TryParseJson(out NestedContentValue nestedContentObjectValue))
67+
{
68+
nestedContent.Add(nestedContentObjectValue);
69+
}
70+
else
71+
{
72+
_logger.LogWarning("Value '{Value}' is not a JSON string. Skipping conversion to artifact.", valueAsString);
73+
return null;
74+
}
7275
}
7376
else
7477
{
75-
nestedContent.AddRange(JsonConvert.DeserializeObject<NestedContentValue[]>(svalue));
78+
if (valueAsString.TryParseJson(out NestedContentValue[] nestedContentCollectionValue))
79+
{
80+
nestedContent.AddRange(nestedContentCollectionValue);
81+
}
82+
else
83+
{
84+
_logger.LogWarning("Value '{Value}' is not a JSON string. Skipping conversion to artifact.", valueAsString);
85+
return null;
86+
}
7687
}
7788

7889
if (nestedContent.All(x => x == null))
@@ -153,14 +164,12 @@ public sealed override object FromArtifact(string value, IPropertyType propertyT
153164
return value;
154165
}
155166

156-
if (value.DetectIsJson() == false)
167+
if (!value.TryParseJson(out NestedContentValue[] nestedContent))
157168
{
158169
_logger.LogWarning("Value '{Value}' is not a json string. Skipping conversion from artifact.", value);
159170
return value;
160171
}
161172

162-
var nestedContent = JsonConvert.DeserializeObject<NestedContentValue[]>(value);
163-
164173
if (nestedContent == null || nestedContent.All(x => x == null))
165174
{
166175
_logger.LogWarning("Value contained no elements. Skipping conversion from artifact.");
@@ -187,7 +196,7 @@ public sealed override object FromArtifact(string value, IPropertyType propertyT
187196
// see note in NestedContentValue - leave it unchanged
188197
if (key == "key")
189198
continue;
190-
199+
191200
var innerPropertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);
192201

193202
if (innerPropertyType == null)
@@ -217,9 +226,9 @@ public sealed override object FromArtifact(string value, IPropertyType propertyT
217226
row.PropertyValues[key] = convertedValue.ToString();
218227
}
219228
// json strings need to be converted into JTokens
220-
else if (convertedValue is string convertedStringValue && convertedStringValue.DetectIsJson())
229+
else if (convertedValue is string convertedStringValue && convertedStringValue.TryParseJson(out JToken valueAsJToken))
221230
{
222-
row.PropertyValues[key] = JToken.Parse(convertedStringValue);
231+
row.PropertyValues[key] = valueAsJToken;
223232
}
224233
else
225234
{

0 commit comments

Comments
 (0)