Skip to content

Commit

Permalink
Merge pull request #235 from Jumoo/dev/migrator-library
Browse files Browse the repository at this point in the history
Project seperation.
  • Loading branch information
KevinJump authored Nov 3, 2023
2 parents cec05b2 + 64102bd commit 36dadbc
Show file tree
Hide file tree
Showing 325 changed files with 3,589 additions and 3,456 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: .NET

on:
push:
branches: [ main ]
branches: [ main, dev/* ]
pull_request:
branches: [ main ]

Expand Down Expand Up @@ -47,10 +47,22 @@ jobs:
run: dotnet test
working-directory: uSync.Migrations.Tests

- name: Dotnet Pack
- name: Dotnet Pack (Core)
run: dotnet pack --output ../build.out/ /p:version=${{ steps.gitversion.outputs.fullSemVer }}
working-directory: uSync.Migrations.Core

- name: Dotnet Pack (Client)
run: dotnet pack --output ../build.out/ /p:version=${{ steps.gitversion.outputs.fullSemVer }}
working-directory: uSync.Migrations.Client

- name: Dotnet Pack (Migrators)
run: dotnet pack --output ../build.out/ /p:version=${{ steps.gitversion.outputs.fullSemVer }}
working-directory: uSync.Migrations.Migrators

- name: Dotnet Pack (Main package)
run: dotnet pack --output ../build.out/ /p:version=${{ steps.gitversion.outputs.fullSemVer }}
working-directory: uSync.Migrations

- name: Upload nuget file as build artifact
uses: actions/upload-artifact@v2
with:
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/release-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,22 @@ jobs:
run: dotnet test
working-directory: uSync.Migrations.Tests

- name: Dotnet Pack
- name: Dotnet Pack (Core)
run: dotnet pack --configuration Release --output ../build.out/ /p:version=${{ steps.gitversion.outputs.NuGetVersionV2 }}
working-directory: uSync.Migrations.Core

- name: Dotnet Pack (Client)
run: dotnet pack --configuration Release --output ../build.out/ /p:version=${{ steps.gitversion.outputs.NuGetVersionV2 }}
working-directory: uSync.Migrations.Client

- name: Dotnet Pack (Migrators)
run: dotnet pack --configuration Release --output ../build.out/ /p:version=${{ steps.gitversion.outputs.NuGetVersionV2 }}
working-directory: uSync.Migrations.Migrators

- name: Dotnet Pack (Parent Package)
run: dotnet pack --configuration Release --output ../build.out/ /p:version=${{ steps.gitversion.outputs.NuGetVersionV2 }}
working-directory: uSync.Migrations

# - name: Push to Nuget Repo
# working-directory: build.out
# run: dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --skip-duplicate --api-key ${{secrets.NUGET_TOKEN}}
Expand Down
11 changes: 7 additions & 4 deletions MyMigrations/DTGEMigrator/DTGECheckboxListMigrator.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using Newtonsoft.Json;

using Umbraco.Extensions;
using uSync.Migrations.Context;
using uSync.Migrations.Migrators;
using uSync.Migrations.Migrators.Models;

using uSync.Migrations.Core.Context;
using uSync.Migrations.Core.Migrators;
using uSync.Migrations.Core.Migrators.Models;
using uSync.Migrations.Migrators.Core;

namespace MyMigrations.DTGEMigrator;

Expand All @@ -21,7 +24,7 @@ public class DTGECheckboxListMigrator : CheckboxListMigrator
DTGEPrevaluesMap prevaluesMap = new DTGEPrevaluesMap(context);

IList<string>? inputValues = JsonConvert.DeserializeObject<List<string>>(contentProperty.Value);
if (inputValues == null) return null;
if (inputValues == null) return null;

List<string> outputValues = new List<string>();
foreach (var inputVal in inputValues)
Expand Down
14 changes: 7 additions & 7 deletions MyMigrations/DTGEMigrator/DTGEDropDownMigrator.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

using Newtonsoft.Json;

using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Extensions;
using uSync.Migrations.Context;
using uSync.Migrations.Extensions;
using uSync.Migrations.Migrators;
using uSync.Migrations.Migrators.Models;

using uSync.Migrations.Core.Context;
using uSync.Migrations.Core.Migrators;
using uSync.Migrations.Core.Migrators.Models;
using uSync.Migrations.Migrators.Core;

namespace MyMigrations.DTGEMigrator;

Expand All @@ -15,7 +15,7 @@ namespace MyMigrations.DTGEMigrator;
[SyncMigrator("DTGE.Umbraco.DropDown")]
public class DTGEDropDownMigrator : DropdownMigrator
{

public override string? GetContentValue(SyncMigrationContentProperty contentProperty, SyncMigrationContext context)
{
if (contentProperty.Value == null)
Expand Down Expand Up @@ -45,6 +45,6 @@ public class DTGEDropDownMigrator : DropdownMigrator
}

return JsonConvert.SerializeObject(outputValues);

}
}
238 changes: 119 additions & 119 deletions MyMigrations/DTGEMigrator/DTGEMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,140 +6,140 @@
using Umbraco.Cms.Core.Models;
using Umbraco.Extensions;

using uSync.Migrations.Context;
using uSync.Migrations.Migrators;
using uSync.Migrations.Migrators.Models;
using uSync.Migrations.Core.Context;
using uSync.Migrations.Core.Migrators;
using uSync.Migrations.Core.Migrators.Models;

namespace MyMigrations.DTGEMigrator;

[SyncMigrator(Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.Grid)]
[SyncMigratorVersion(7,8)]
[SyncMigratorVersion(7, 8)]
[SyncDefaultMigrator]
public class DTGEMigrator : SyncPropertyMigratorBase
{
private readonly ILoggerFactory _loggerFactory;
private readonly ILogger<DTGEMigrator> _logger;

private readonly ILoggerFactory _loggerFactory;
private readonly ILogger<DTGEMigrator> _logger;


public DTGEMigrator(
ILoggerFactory loggerFactory)
ILoggerFactory loggerFactory)
{

_loggerFactory = loggerFactory;
_logger = loggerFactory.CreateLogger<DTGEMigrator>();
_logger = loggerFactory.CreateLogger<DTGEMigrator>();


}

public override string GetEditorAlias(SyncMigrationDataTypeProperty dataTypeProperty, SyncMigrationContext context)
=> Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.Grid;

public override string GetDatabaseType(SyncMigrationDataTypeProperty dataTypeProperty, SyncMigrationContext context)
=> nameof(ValueStorageType.Ntext);
public override object? GetConfigValues (SyncMigrationDataTypeProperty dataTypeProperty, SyncMigrationContext context)
{
var ignoreUserStartNodes = dataTypeProperty.PreValues?.SingleOrDefault(x => x.Alias == "ignoreUserStartNodes");
if (ignoreUserStartNodes != null)
{
bool newValue = bool.TryParse(ignoreUserStartNodes.Value, out var parsedValue) && parsedValue;
ignoreUserStartNodes.Value = newValue.ToString();
}

return base.GetConfigValues(dataTypeProperty, context);
}
public override string? GetContentValue(SyncMigrationContentProperty contentProperty, SyncMigrationContext context)
{
if (contentProperty.Value == null) return string.Empty;

var grid = JsonConvert.DeserializeObject<GridValue>(contentProperty.Value);
if (grid == null) return contentProperty.Value;
foreach (var section in grid.Sections)
{
foreach (var row in section.Rows)
{
foreach (var area in row.Areas)
{
foreach (var control in area.Controls)
{
if (!control.Value?.HasValues == true) continue;
var isDTGEvalue = !String.IsNullOrEmpty(control.Value?.Value<string>("dtgeContentTypeAlias"));
if (isDTGEvalue)
{
var updatedValues = GetPropertyValues(control, context);
var updatedValuesSerialized = JsonConvert.SerializeObject(updatedValues);
var controlValue = control.Value;
if (controlValue != null)
controlValue["value"] = JsonConvert.DeserializeObject<JToken>(updatedValuesSerialized);
}
}
}
}
}

var propValue = JsonConvert.SerializeObject(grid);
return propValue;
}
private string GetContentTypeAlias(GridValue.GridControl control)
=> control.Value?.Value<string>("dtgeContentTypeAlias") ?? string.Empty;



private Dictionary<string, object> GetPropertyValues(GridValue.GridControl control, SyncMigrationContext context)
{
var propertyValues = new Dictionary<string, object>();

var contentTypeAlias = GetContentTypeAlias(control);
if (string.IsNullOrWhiteSpace(contentTypeAlias)) return propertyValues;

var elementValue = control.Value?.Value<JObject>("value")?
.ToObject<IDictionary<string, object>>();

if (elementValue == null) return propertyValues;

foreach (var (propertyAlias, value) in elementValue)
{
var editorAlias = context.ContentTypes.GetEditorAliasByTypeAndProperty(contentTypeAlias, propertyAlias);

if (editorAlias == null) continue;

var migrator = context.Migrators.TryGetMigrator("DTGE." + editorAlias.OriginalEditorAlias);
if (migrator == null)
migrator = context.Migrators.TryGetMigrator(editorAlias.OriginalEditorAlias);
var propertyValue = value;
if (migrator != null)
{
var valueToConvert = (value?.ToString() ?? "").Trim();
var property = new SyncMigrationContentProperty(
$"DTGE.{editorAlias.OriginalEditorAlias}",
propertyAlias,
editorAlias.OriginalEditorAlias,
valueToConvert);

var convertedValue = migrator.GetContentValue(property, context);
if (convertedValue?.Trim().DetectIsJson() == true)
propertyValue = JsonConvert.DeserializeObject(convertedValue ?? "");
else
propertyValue = convertedValue;

}

if (propertyValue != null)
propertyValues[propertyAlias] = propertyValue;
}

return propertyValues;
}
=> Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.Grid;

public override string GetDatabaseType(SyncMigrationDataTypeProperty dataTypeProperty, SyncMigrationContext context)
=> nameof(ValueStorageType.Ntext);

public override object? GetConfigValues(SyncMigrationDataTypeProperty dataTypeProperty, SyncMigrationContext context)
{
var ignoreUserStartNodes = dataTypeProperty.PreValues?.SingleOrDefault(x => x.Alias == "ignoreUserStartNodes");
if (ignoreUserStartNodes != null)
{
bool newValue = bool.TryParse(ignoreUserStartNodes.Value, out var parsedValue) && parsedValue;
ignoreUserStartNodes.Value = newValue.ToString();
}

return base.GetConfigValues(dataTypeProperty, context);
}

public override string? GetContentValue(SyncMigrationContentProperty contentProperty, SyncMigrationContext context)
{
if (contentProperty.Value == null) return string.Empty;

var grid = JsonConvert.DeserializeObject<GridValue>(contentProperty.Value);
if (grid == null) return contentProperty.Value;

foreach (var section in grid.Sections)
{
foreach (var row in section.Rows)
{
foreach (var area in row.Areas)
{
foreach (var control in area.Controls)
{
if (!control.Value?.HasValues == true) continue;

var isDTGEvalue = !String.IsNullOrEmpty(control.Value?.Value<string>("dtgeContentTypeAlias"));
if (isDTGEvalue)
{
var updatedValues = GetPropertyValues(control, context);
var updatedValuesSerialized = JsonConvert.SerializeObject(updatedValues);

var controlValue = control.Value;

if (controlValue != null)
controlValue["value"] = JsonConvert.DeserializeObject<JToken>(updatedValuesSerialized);
}
}
}
}
}

var propValue = JsonConvert.SerializeObject(grid);
return propValue;
}

private string GetContentTypeAlias(GridValue.GridControl control)
=> control.Value?.Value<string>("dtgeContentTypeAlias") ?? string.Empty;



private Dictionary<string, object> GetPropertyValues(GridValue.GridControl control, SyncMigrationContext context)
{
var propertyValues = new Dictionary<string, object>();

var contentTypeAlias = GetContentTypeAlias(control);
if (string.IsNullOrWhiteSpace(contentTypeAlias)) return propertyValues;

var elementValue = control.Value?.Value<JObject>("value")?
.ToObject<IDictionary<string, object>>();

if (elementValue == null) return propertyValues;

foreach (var (propertyAlias, value) in elementValue)
{
var editorAlias = context.ContentTypes.GetEditorAliasByTypeAndProperty(contentTypeAlias, propertyAlias);

if (editorAlias == null) continue;

var migrator = context.Migrators.TryGetMigrator("DTGE." + editorAlias.OriginalEditorAlias);
if (migrator == null)
migrator = context.Migrators.TryGetMigrator(editorAlias.OriginalEditorAlias);

var propertyValue = value;

if (migrator != null)
{
var valueToConvert = (value?.ToString() ?? "").Trim();

var property = new SyncMigrationContentProperty(
$"DTGE.{editorAlias.OriginalEditorAlias}",
propertyAlias,
editorAlias.OriginalEditorAlias,
valueToConvert);

var convertedValue = migrator.GetContentValue(property, context);
if (convertedValue?.Trim().DetectIsJson() == true)
propertyValue = JsonConvert.DeserializeObject(convertedValue ?? "");
else
propertyValue = convertedValue;

}

if (propertyValue != null)
propertyValues[propertyAlias] = propertyValue;
}

return propertyValues;
}

}

Loading

0 comments on commit 36dadbc

Please sign in to comment.