Skip to content

Commit

Permalink
Merge branch 'v4/4.2' into v9/9.1
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
AndyButland committed Sep 21, 2022
2 parents 3e19c08 + 8ab65d0 commit 329b0e7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 31 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

# Umbraco Deploy Contrib

This project contains community contributions for Umbraco Deploy targetted for version 8.
This project contains community contributions for Umbraco Deploy targetted for version 8 and above.

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).

## Branching

The main branches corresponding to the Umbraco and Umbraco Deploy major releases are:

- Umbraco 8/Deploy 4: `v4/dev`
- Umbraco 9/Deploy 9: `v9/dev`
- Umbraco 10/Deploy 10: `v10/dev`

## Connectors

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

### Installation

You can install the NuGet package using `Install-Package UmbracoDeploy.Contrib`.
When working with Umbraco 8, you can install the NuGet package using `Install-Package UmbracoDeploy.Contrib`.

For Umbraco 9+ the package is available for install by: `Install-Package Umbraco.Deploy.Contrib`

---
## Contributing to this project
Expand Down
3 changes: 1 addition & 2 deletions src/Umbraco.Deploy.Contrib/Umbraco.Deploy.Contrib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Umbraco.Deploy.Core" Version="9.5.0" />
<PackageReference Include="Umbraco.Deploy.Infrastructure" Version="9.5.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Umbraco.Deploy.Core.Connectors;
using Umbraco.Deploy.Core.Connectors.ValueConnectors;
using Umbraco.Deploy.Core.Connectors.ValueConnectors.Services;
using Umbraco.Deploy.Infrastructure.Extensions;
using Umbraco.Extensions;

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

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

if (string.IsNullOrWhiteSpace(svalue))
if (string.IsNullOrWhiteSpace(valueAsString))
{
_logger.LogDebug($"Value is null or whitespace. Skipping conversion to artifact.");
return null;
}

if (svalue.DetectIsJson() == false)
if (!valueAsString.TryParseJson(out BlockEditorValue blockEditorValue))
{
_logger.LogWarning("Value '{Value}' is not a json string. Skipping conversion to artifact.", svalue);
_logger.LogWarning("Value '{Value}' is not a JSON string. Skipping conversion to artifact.", valueAsString);
return null;
}

var blockEditorValue = JsonConvert.DeserializeObject<BlockEditorValue>(svalue);

if (blockEditorValue == null)
{
_logger.LogWarning("Deserialized value is null. Skipping conversion to artifact.");
Expand Down Expand Up @@ -148,13 +147,15 @@ public override object FromArtifact(string value, IPropertyType propertyType, ob
return value;
}

if (value.DetectIsJson() == false)
if (!value.TryParseJson(out BlockEditorValue blockEditorValue))
{
return value;

var blockEditorValue = JsonConvert.DeserializeObject<BlockEditorValue>(value);
}

if (blockEditorValue == null)
{
return value;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Umbraco.Deploy.Core.Connectors;
using Umbraco.Deploy.Core.Connectors.ValueConnectors;
using Umbraco.Deploy.Core.Connectors.ValueConnectors.Services;
using Umbraco.Deploy.Infrastructure.Extensions;
using Umbraco.Extensions;

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

if (string.IsNullOrWhiteSpace(svalue))
if (string.IsNullOrWhiteSpace(valueAsString))
{
_logger.LogDebug($"Value is null or whitespace. Skipping conversion to artifact.");
return null;
}

if (svalue.DetectIsJson() == false)
{
_logger.LogWarning("Value '{Value}' is not a json string. Skipping conversion to artifact.", svalue);
return null;
}

var nestedContent = new List<NestedContentValue>();
if (svalue.Trim().StartsWith("{"))
if (valueAsString.Trim().StartsWith("{"))
{
nestedContent.Add(JsonConvert.DeserializeObject<NestedContentValue>(svalue));
if (valueAsString.TryParseJson(out NestedContentValue nestedContentObjectValue))
{
nestedContent.Add(nestedContentObjectValue);
}
else
{
_logger.LogWarning("Value '{Value}' is not a JSON string. Skipping conversion to artifact.", valueAsString);
return null;
}
}
else
{
nestedContent.AddRange(JsonConvert.DeserializeObject<NestedContentValue[]>(svalue));
if (valueAsString.TryParseJson(out NestedContentValue[] nestedContentCollectionValue))
{
nestedContent.AddRange(nestedContentCollectionValue);
}
else
{
_logger.LogWarning("Value '{Value}' is not a JSON string. Skipping conversion to artifact.", valueAsString);
return null;
}
}

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

if (value.DetectIsJson() == false)
if (!value.TryParseJson(out NestedContentValue[] nestedContent))
{
_logger.LogWarning("Value '{Value}' is not a json string. Skipping conversion from artifact.", value);
return value;
}

var nestedContent = JsonConvert.DeserializeObject<NestedContentValue[]>(value);

if (nestedContent == null || nestedContent.All(x => x == null))
{
_logger.LogWarning("Value contained no elements. Skipping conversion from artifact.");
Expand All @@ -187,7 +196,7 @@ public sealed override object FromArtifact(string value, IPropertyType propertyT
// see note in NestedContentValue - leave it unchanged
if (key == "key")
continue;

var innerPropertyType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == key);

if (innerPropertyType == null)
Expand Down Expand Up @@ -217,9 +226,9 @@ public sealed override object FromArtifact(string value, IPropertyType propertyT
row.PropertyValues[key] = convertedValue.ToString();
}
// json strings need to be converted into JTokens
else if (convertedValue is string convertedStringValue && convertedStringValue.DetectIsJson())
else if (convertedValue is string convertedStringValue && convertedStringValue.TryParseJson(out JToken valueAsJToken))
{
row.PropertyValues[key] = JToken.Parse(convertedStringValue);
row.PropertyValues[key] = valueAsJToken;
}
else
{
Expand Down

0 comments on commit 329b0e7

Please sign in to comment.