Skip to content

Commit

Permalink
Merge pull request #228 from bielu/fix/grid-value-mistake
Browse files Browse the repository at this point in the history
fix: another small bits and bobs at migrations
  • Loading branch information
KevinJump authored Oct 6, 2023
2 parents 3f5dad8 + 21e6e27 commit 40d1c1d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using uSync.Migrations.Legacy.Grid;
using uSync.Migrations.Migrators.BlockGrid.BlockMigrators;
using uSync.Migrations.Migrators.BlockGrid.Models;
using GridConfiguration = Umbraco.Cms.Core.PropertyEditors.GridConfiguration;

namespace uSync.Migrations.Migrators.BlockGrid.Extensions;
internal static class GridConfigurationExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using uSync.Migrations.Migrators.BlockGrid.Content;
using uSync.Migrations.Migrators.BlockGrid.Extensions;
using uSync.Migrations.Migrators.Models;
using GridConfiguration = uSync.Migrations.Migrators.BlockGrid.Models.GridConfiguration;

namespace uSync.Migrations.Migrators.BlockGrid;

Expand Down Expand Up @@ -61,7 +62,7 @@ public override string GetDatabaseType(SyncMigrationDataTypeProperty dataTypePro
}

var gridConfiguration = JsonConvert
.DeserializeObject<GridConfiguration>(dataTypeProperty.ConfigAsString);
.DeserializeObject<GridConfiguration>(dataTypeProperty.ConfigAsString );

if (gridConfiguration == null)
{
Expand All @@ -71,7 +72,7 @@ public override string GetDatabaseType(SyncMigrationDataTypeProperty dataTypePro


var legacyGridEditorsConfig = GetGridConfig(context);
var gridToBlockContext = new GridToBlockGridConfigContext(gridConfiguration, legacyGridEditorsConfig);
var gridToBlockContext = new GridToBlockGridConfigContext(gridConfiguration.ToUmbracoGridConfiguration(), legacyGridEditorsConfig);

var contentBlockHelper = new GridToBlockGridConfigBlockHelper(_blockMigrators, _loggerFactory.CreateLogger<GridToBlockGridConfigBlockHelper>());
var layoutBlockHelper = new GridToBlockGridConfigLayoutBlockHelper(_conventions, _loggerFactory.CreateLogger<GridToBlockGridConfigLayoutBlockHelper>());
Expand Down
40 changes: 40 additions & 0 deletions uSync.Migrations/Migrators/BlockGrid/Models/GridConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Infrastructure.Serialization;

namespace uSync.Migrations.Migrators.BlockGrid.Models;

public class GridConfiguration: IIgnoreUserStartNodesConfig
{
// TODO: Make these strongly typed, for now this works though
[ConfigurationField("items", "Grid", "views/propertyeditors/grid/grid.prevalues.html", Description = "Grid configuration")]
public JObject? Items { get; set; }

// TODO: Make these strongly typed, for now this works though
[ConfigurationField("rte", "Rich text editor", "views/propertyeditors/rte/rte.prevalues.html", Description = "Rich text editor configuration", HideLabel = true)]
public JObject? Rte { get; set; }

[ConfigurationField("mediaParentId", "Image Upload Folder", "mediafolderpicker", Description = "Choose the upload location of pasted images")]
public GuidUdi? MediaParentId { get; set; }

[ConfigurationField(
Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes,
"Ignore User Start Nodes",
"boolean",
Description = "Selecting this option allows a user to choose nodes that they normally don't have access to.")]
[JsonConverter(typeof(FuzzyBooleanConverter))]
public bool IgnoreUserStartNodes { get; set; }

public Umbraco.Cms.Core.PropertyEditors.GridConfiguration ToUmbracoGridConfiguration()
{
return new Umbraco.Cms.Core.PropertyEditors.GridConfiguration()
{
Items = this.Items,
Rte = this.Rte,
MediaParentId = this.MediaParentId,
IgnoreUserStartNodes = this.IgnoreUserStartNodes
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override string GetEditorAlias(SyncMigrationDataTypeProperty dataTypeProp
.DeserializeObject<List<StackedContentConfigurationBlock>>(contentTypes)?
.Select(x => new BlockListConfiguration.BlockConfiguration
{
ContentElementTypeKey = x.ContentTypeKey,
ContentElementTypeKey = !string.IsNullOrWhiteSpace(x.ContentTypeAlias)? context.ContentTypes.GetKeyByAlias(x.ContentTypeAlias) : x.ContentTypeKey,
Label = x.NameTemplate,
})
.ToArray();
Expand All @@ -52,7 +52,7 @@ public override string GetEditorAlias(SyncMigrationDataTypeProperty dataTypeProp
return new BlockListConfiguration
{
Blocks = blocks ?? Array.Empty<BlockListConfiguration.BlockConfiguration>(),
ValidationLimit = validationLimit,
ValidationLimit = validationLimit
};
}

Expand All @@ -75,7 +75,11 @@ public override string GetEditorAlias(SyncMigrationDataTypeProperty dataTypeProp

foreach (var item in items)
{
var contentTypeAlias = context.ContentTypes.GetAliasByKey(item.ContentTypeKey);
var useGuid = string.IsNullOrWhiteSpace(item.ContentTypeAlias);
var contentTypeKey = useGuid
? item.ContentTypeKey
: context.ContentTypes.GetKeyByAlias(item.ContentTypeAlias);
var contentTypeAlias = useGuid ? context.ContentTypes.GetAliasByKey(item.ContentTypeKey) : item.ContentTypeAlias;

foreach (var (propertyAlias, value) in item.Values)
{
Expand All @@ -102,7 +106,7 @@ public override string GetEditorAlias(SyncMigrationDataTypeProperty dataTypeProp

var block = new BlockItemData
{
ContentTypeKey = item.ContentTypeKey,
ContentTypeKey = contentTypeKey,
Udi = Udi.Create(UmbConstants.UdiEntityType.Element, item.Key),
RawPropertyValues = item.Values,
};
Expand Down Expand Up @@ -131,6 +135,8 @@ public override string GetEditorAlias(SyncMigrationDataTypeProperty dataTypeProp

internal class StackedContentItem
{
[JsonProperty("icContentTypeAlias")]
public string ContentTypeAlias { get; set; }
[JsonProperty("icContentTypeGuid")]
public Guid ContentTypeKey { get; set; }

Expand All @@ -151,6 +157,8 @@ internal class StackedContentConfigurationBlock
{
[JsonProperty("icContentTypeGuid")]
public Guid ContentTypeKey { get; set; }
[JsonProperty("icContentTypeAlias")]
public string ContentTypeAlias { get; set; }

[JsonProperty("nameTemplate")]
public string? NameTemplate { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public SyncMigrationDataTypeProperty(string dataTypeAlias, string editorAlias, s
var json = new Dictionary<string, object>();
foreach (var oPreValue in preValues)
{
json.TryAdd(oPreValue.Alias, oPreValue.Value.ToString().DetectIsJson() ? JsonConvert.DeserializeObject(oPreValue.Value) : oPreValue);
json.TryAdd(oPreValue.Alias, oPreValue.Value.ToString().DetectIsJson() ? JsonConvert.DeserializeObject(oPreValue.Value) : oPreValue.Value);
}
return JsonConvert.SerializeObject(json);
}
Expand Down

0 comments on commit 40d1c1d

Please sign in to comment.