diff --git a/KVA/Migration.Toolkit.Source/Mappers/ContentItemMapper.cs b/KVA/Migration.Toolkit.Source/Mappers/ContentItemMapper.cs index 6aa5cd75..ea788966 100644 --- a/KVA/Migration.Toolkit.Source/Mappers/ContentItemMapper.cs +++ b/KVA/Migration.Toolkit.Source/Mappers/ContentItemMapper.cs @@ -7,7 +7,8 @@ using CMS.FormEngine; using CMS.MediaLibrary; using CMS.Websites; - +using CMS.Websites.Internal; +using Kentico.Components.Web.Mvc.FormComponents; using Kentico.Xperience.UMT.Model; using Microsoft.Extensions.Logging; @@ -77,12 +78,20 @@ protected override IEnumerable<IUmtModel> MapInternal(CmsTreeMapperSource source ContentItemChannelGuid = siteGuid }; + var targetWebPage = WebPageItemInfo.Provider.Get() + .WhereEquals(nameof(WebPageItemInfo.WebPageItemGUID), contentItemGuid) + .FirstOrDefault(); + string? treePath = targetWebPage?.WebPageItemTreePath; + var websiteChannelInfo = WebsiteChannelInfoProvider.ProviderObject.Get(siteGuid); var treePathConvertor = TreePathConvertor.GetSiteConverter(websiteChannelInfo.WebsiteChannelID); - (bool treePathIsDifferent, string treePath) = treePathConvertor.ConvertAndEnsureUniqueness(cmsTree.NodeAliasPath).GetAwaiter().GetResult(); - if (treePathIsDifferent) + if (treePath == null) { - logger.LogInformation($"Original node alias path '{cmsTree.NodeAliasPath}' of '{cmsTree.NodeName}' item was converted to '{treePath}' since the value does not allow original range of allowed characters."); + (bool treePathIsDifferent, treePath) = treePathConvertor.ConvertAndEnsureUniqueness(cmsTree.NodeAliasPath).GetAwaiter().GetResult(); + if (treePathIsDifferent) + { + logger.LogInformation($"Original node alias path '{cmsTree.NodeAliasPath}' of '{cmsTree.NodeName}' item was converted to '{treePath}' since the value does not allow original range of allowed characters."); + } } foreach (var cmsDocument in migratedDocuments) @@ -339,7 +348,7 @@ private void PatchJsonDefinitions(int sourceSiteId, ref string? pageTemplateConf { if (pageTemplateConfiguration != null) { - var pageTemplateConfigurationObj = JsonConvert.DeserializeObject<PageTemplateConfiguration>(pageTemplateConfiguration); + var pageTemplateConfigurationObj = JsonConvert.DeserializeObject<Services.Model.PageTemplateConfiguration>(pageTemplateConfiguration); if (pageTemplateConfigurationObj?.Identifier != null) { logger.LogTrace("Walk page template configuration {Identifier}", pageTemplateConfigurationObj.Identifier); @@ -829,11 +838,18 @@ private void WalkProperties(int siteId, JObject properties, List<EditingFormCont switch (oldFormComponent) { - // case Kx13FormComponents.Kentico_PathSelector: - // { - // // new PathSelectorItem() - // break; - // } + case Kx13FormComponents.Kentico_PathSelector: + { + if (value?.ToObject<List<Services.Model.PathSelectorItem>>() is { Count: > 0 } items) + { + properties[key] = JToken.FromObject(items.Select(x => new Kentico.Components.Web.Mvc.FormComponents.PathSelectorItem + { + TreePath = x.NodeAliasPath + }).ToList()); + } + + break; + } case Kx13FormComponents.Kentico_AttachmentSelector when newFormComponent == FormComponents.AdminAssetSelectorComponent: { if (value?.ToObject<List<AttachmentSelectorItem>>() is { Count: > 0 } items) @@ -846,7 +862,7 @@ private void WalkProperties(int siteId, JObject properties, List<EditingFormCont } case Kx13FormComponents.Kentico_PageSelector when newFormComponent == FormComponents.Kentico_Xperience_Admin_Websites_WebPageSelectorComponent: { - if (value?.ToObject<List<PageSelectorItem>>() is { Count: > 0 } items) + if (value?.ToObject<List<Services.Model.PageSelectorItem>>() is { Count: > 0 } items) { properties[key] = JToken.FromObject(items.Select(x => new WebPageRelatedItem { WebPageGuid = spoiledGuidContext.EnsureNodeGuid(x.NodeGuid, siteId) }).ToList()); } diff --git a/KVA/Migration.Toolkit.Source/Mappers/PageTemplateConfigurationMapper.cs b/KVA/Migration.Toolkit.Source/Mappers/PageTemplateConfigurationMapper.cs index ec579cb8..986f5442 100644 --- a/KVA/Migration.Toolkit.Source/Mappers/PageTemplateConfigurationMapper.cs +++ b/KVA/Migration.Toolkit.Source/Mappers/PageTemplateConfigurationMapper.cs @@ -179,6 +179,18 @@ private void WalkProperties(int siteId, JObject properties, List<EditingFormCont switch (oldFormComponent) { + case Kx13FormComponents.Kentico_PathSelector: + { + if (value?.ToObject<List<Services.Model.PathSelectorItem>>() is { Count: > 0 } items) + { + properties[key] = JToken.FromObject(items.Select(x => new Kentico.Components.Web.Mvc.FormComponents.PathSelectorItem + { + TreePath = x.NodeAliasPath + }).ToList()); + } + + break; + } case Kx13FormComponents.Kentico_AttachmentSelector when newFormComponent == FormComponents.AdminAssetSelectorComponent: { if (value?.ToObject<List<AttachmentSelectorItem>>() is { Count: > 0 } items) diff --git a/KVA/Migration.Toolkit.Source/Services/Model/PathSelectorItem.cs b/KVA/Migration.Toolkit.Source/Services/Model/PathSelectorItem.cs new file mode 100644 index 00000000..d02e73a1 --- /dev/null +++ b/KVA/Migration.Toolkit.Source/Services/Model/PathSelectorItem.cs @@ -0,0 +1,15 @@ +using Newtonsoft.Json; + +namespace Migration.Toolkit.Source.Services.Model; + +// +// Summary: +// Represents an item for a path selector. +public class PathSelectorItem +{ + // + // Summary: + // Node Alias Path of a page. + [JsonProperty("nodeAliasPath")] + public string? NodeAliasPath { get; set; } +} diff --git a/Migration.Toolkit.KXP.Api/Services/CmsClass/FormFieldMappingModel.cs b/Migration.Toolkit.KXP.Api/Services/CmsClass/FormFieldMappingModel.cs index d829d6b6..ab325f5d 100644 --- a/Migration.Toolkit.KXP.Api/Services/CmsClass/FormFieldMappingModel.cs +++ b/Migration.Toolkit.KXP.Api/Services/CmsClass/FormFieldMappingModel.cs @@ -63,6 +63,7 @@ public static class FieldMappingInstance new FieldMigration(KsFieldDataType.Text, FieldDataType.Text, FcText.RadioButtonsControl, FormComponents.AdminRadioGroupComponent), new FieldMigration(KsFieldDataType.Text, FieldDataType.Text, FcText.TextAreaControl, FormComponents.AdminTextAreaComponent), new FieldMigration(KsFieldDataType.Text, FieldDataType.Text, SfcDirective.CatchAnyNonMatching, FormComponents.AdminTextInputComponent), + new FieldMigration(KsFieldDataType.Text, FieldDataType.Text, SfcDirective.CatchAnyNonMatching, FormComponents.AdminTextInputComponent), new FieldMigration(KsFieldDataType.LongText, FieldDataType.LongText, FcLongText.HtmlAreaControl, FormComponents.AdminRichTextEditorComponent), new FieldMigration(KsFieldDataType.LongText, FieldDataType.LongText, FcLongText.TextBoxControl, FormComponents.AdminTextInputComponent), new FieldMigration(KsFieldDataType.LongText, FieldDataType.LongText, FcLongText.DropDownListControl, FormComponents.AdminDropDownComponent), @@ -92,8 +93,8 @@ public static class FieldMappingInstance BuiltInFieldMigrations, [ new FormComponentReplacement(Kx13FormComponents.Kentico_AttachmentSelector, FormComponents.AdminAssetSelectorComponent), - new FormComponentReplacement(Kx13FormComponents.Kentico_PageSelector, FormComponents.Kentico_Xperience_Admin_Websites_WebPageSelectorComponent) - // new(Kx13FormComponents.Kentico_PathSelector, FormComponents.Kentico_Xperience_Admin_Websites_WebPageSelectorComponent) + new FormComponentReplacement(Kx13FormComponents.Kentico_PageSelector, FormComponents.Kentico_Xperience_Admin_Websites_WebPageSelectorComponent), + new FormComponentReplacement(Kx13FormComponents.Kentico_PathSelector, FormComponents.Kentico_Xperience_Admin_Websites_WebPageSelectorComponent) ], [] // legacy mode is no more );