Skip to content

Commit

Permalink
Merge pull request #224 from Kentico/feat/path_selector_migration
Browse files Browse the repository at this point in the history
Path selector migration
  • Loading branch information
tkrch authored Aug 19, 2024
2 parents 52618e0 + ccbd700 commit 4980d67
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.
38 changes: 27 additions & 11 deletions KVA/Migration.Toolkit.Source/Mappers/ContentItemMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions KVA/Migration.Toolkit.Source/Services/Model/PathSelectorItem.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
);
Expand Down

0 comments on commit 4980d67

Please sign in to comment.