diff --git a/src/Umbraco.Community.Contentment/Migrations/Upgrade/V_6_0_0/MigrateDataListConfiguration.cs b/src/Umbraco.Community.Contentment/Migrations/Upgrade/V_6_0_0/MigrateDataListConfiguration.cs index 609f021a..25c14e12 100644 --- a/src/Umbraco.Community.Contentment/Migrations/Upgrade/V_6_0_0/MigrateDataListConfiguration.cs +++ b/src/Umbraco.Community.Contentment/Migrations/Upgrade/V_6_0_0/MigrateDataListConfiguration.cs @@ -2,7 +2,7 @@ // Copyright © 2024 Lee Kelleher using System.Text.Json.Nodes; -using Newtonsoft.Json.Linq; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Infrastructure.Migrations; using Umbraco.Cms.Infrastructure.Persistence.Dtos; @@ -47,9 +47,150 @@ protected override void Migrate() var key = item["key"]?.ToString(); - if (key == "Umbraco.Community.Contentment.DataEditors.DataList.DataSources.UmbracoContentPropertyValueDataListSource, Umbraco.Community.Contentment") + switch (key) { - item["key"] = "Umbraco.Community.Contentment.DataEditors.UmbracoContentPropertyValueDataListSource, Umbraco.Community.Contentment"; + case "Umbraco.Community.Contentment.DataEditors.UmbracoContentDataListSource, Umbraco.Community.Contentment": + { + try + { + var value = item["value"]; + if (value is not null) + { + var parentNode = value["parentNode"]?.ToString(); + if (string.IsNullOrWhiteSpace(parentNode) == false && + UdiParser.TryParse(parentNode, out GuidUdi? udi) == true && + udi?.Guid.Equals(Guid.Empty) == false) + { + value["parentNode"] = new JsonObject + { + ["originKey"] = udi.Guid.ToString(), + ["originAlias"] = "ByKey", + }; + + item["value"] = value; + } + } + } + catch { /* ¯\_(ツ)_/¯ */ } + break; + } + + case "Umbraco.Community.Contentment.DataEditors.UmbracoContentPropertiesDataListSource, Umbraco.Community.Contentment": + { + try + { + var value = item["value"]; + if (value is not null) + { + var contentTypes = value["contentType"]?.AsArray(); + if (contentTypes?.Count > 0) + { + var uniques = contentTypes + .Select(x => UdiParser.TryParse(x?.ToString(), out GuidUdi? udi) == true ? udi.Guid : Guid.Empty) + .Where(x => x.Equals(Guid.Empty) == false); + + value["contentType"] = string.Join(",", uniques); + item["value"] = value; + } + } + } + catch { /* ¯\_(ツ)_/¯ */ } + break; + } + + case "Umbraco.Community.Contentment.DataEditors.DataList.DataSources.UmbracoContentPropertyValueDataListSource, Umbraco.Community.Contentment": + { + item["key"] = "Umbraco.Community.Contentment.DataEditors.UmbracoContentPropertyValueDataListSource, Umbraco.Community.Contentment"; + + try + { + var value = item["value"]; + if (value is not null) + { + var contentNode = value["contentNode"]?.ToString(); + if (string.IsNullOrWhiteSpace(contentNode) == false && + UdiParser.TryParse(contentNode, out GuidUdi? udi) == true && + udi?.Guid.Equals(Guid.Empty) == false) + { + value["contentNode"] = new JsonObject + { + ["originKey"] = udi.Guid.ToString(), + ["originAlias"] = "ByKey", + }; + + item["value"] = value; + } + } + } + catch { /* ¯\_(ツ)_/¯ */ } + break; + } + + case "Umbraco.Community.Contentment.DataEditors.UmbracoDictionaryDataListSource, Umbraco.Community.Contentment": + { + try + { + var value = item["value"]; + if (value is not null) + { + var items = value["item"]?.AsArray(); + if (items?.Count > 0) + { + var guid = items.FirstOrDefault()?["key"]?.ToString(); + value["item"] = guid; + item["value"] = value; + } + } + } + catch { /* ¯\_(ツ)_/¯ */ } + break; + } + + case "Umbraco.Community.Contentment.DataEditors.UmbracoMembersDataListSource, Umbraco.Community.Contentment": + { + try + { + var value = item["value"]; + if (value is not null) + { + var memberTypes = value["memberType"]?.AsArray(); + if (memberTypes?.Count > 0) + { + var uniques = memberTypes + .Select(x => UdiParser.TryParse(x?.ToString(), out GuidUdi? udi) == true ? udi.Guid : Guid.Empty) + .Where(x => x.Equals(Guid.Empty) == false); + + value["memberType"] = string.Join(",", uniques); + item["value"] = value; + } + } + } + catch { /* ¯\_(ツ)_/¯ */ } + break; + } + + case "Umbraco.Community.Contentment.DataEditors.UmbracoUsersDataListSource, Umbraco.Community.Contentment": + { + try + { + var value = item["value"]; + if (value is not null) + { + var userGroups = value["userGroup"]?.AsArray(); + if (userGroups?.Count > 0) + { + var aliases = userGroups.Select(x => x?.ToString()); + value["userGroup"] = string.Join(",", aliases); + item["value"] = value; + } + } + } + catch { /* ¯\_(ツ)_/¯ */ } + break; + } + + default: + break; } configurationData["dataSource"] = dataSource;