Skip to content

Commit

Permalink
Merge pull request #222 from Kentico/rls/v1.2.0
Browse files Browse the repository at this point in the history
release of version 1.2.0
  • Loading branch information
tkrch authored Aug 21, 2024
2 parents 5c6f427 + d6e57ab commit 9f902dd
Show file tree
Hide file tree
Showing 23 changed files with 376 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Migration.Toolkit.KXP.Context;
using Migration.Toolkit.KXP.Models;
using Migration.Toolkit.Source.Contexts;
using Migration.Toolkit.Source.Helpers;
using Migration.Toolkit.Source.Mappers;
using Migration.Toolkit.Source.Model;

Expand Down Expand Up @@ -180,8 +181,34 @@ private async Task RequireMigratedMediaFiles(List<(IMediaLibrary sourceLibrary,
if (!toolkitConfiguration.MigrateOnlyMediaFileInfo.GetValueOrDefault(true) &&
!string.IsNullOrWhiteSpace(toolkitConfiguration.KxCmsDirPath))
{
sourceMediaLibraryPath = Path.Combine(toolkitConfiguration.KxCmsDirPath, ksSite.SiteName, DirMedia, ksMediaLibrary.LibraryFolder);
loadMediaFileData = true;
string? cmsMediaLibrariesFolder = KenticoHelper.GetSettingsKey(modelFacade, ksSite.SiteID, "CMSMediaLibrariesFolder");
if (cmsMediaLibrariesFolder != null)
{
if (Path.IsPathRooted(cmsMediaLibrariesFolder))
{
sourceMediaLibraryPath = Path.Combine(cmsMediaLibrariesFolder, ksSite.SiteName, ksMediaLibrary.LibraryFolder);
loadMediaFileData = true;
}
else
{
if (cmsMediaLibrariesFolder.StartsWith("~/"))
{
string cleared = $"{cmsMediaLibrariesFolder[2..]}".Replace("/", "\\");
sourceMediaLibraryPath = Path.Combine(toolkitConfiguration.KxCmsDirPath, cleared, ksSite.SiteName, ksMediaLibrary.LibraryFolder);
loadMediaFileData = true;
}
else
{
sourceMediaLibraryPath = Path.Combine(toolkitConfiguration.KxCmsDirPath, cmsMediaLibrariesFolder, ksSite.SiteName, ksMediaLibrary.LibraryFolder);
loadMediaFileData = true;
}
}
}
else
{
sourceMediaLibraryPath = Path.Combine(toolkitConfiguration.KxCmsDirPath, ksSite.SiteName, DirMedia, ksMediaLibrary.LibraryFolder);
loadMediaFileData = true;
}
}

var ksMediaFiles = modelFacade.SelectWhere<IMediaFile>("FileLibraryID = @FileLibraryId", new SqlParameter("FileLibraryId", ksMediaLibrary.LibraryID));
Expand Down
264 changes: 155 additions & 109 deletions KVA/Migration.Toolkit.Source/Handlers/MigratePagesCommandHandler.cs

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions KVA/Migration.Toolkit.Source/Helpers/KenticoHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Globalization;
using CMS.Helpers;
using Microsoft.Data.SqlClient;
using Migration.Toolkit.Source.Model;

namespace Migration.Toolkit.Source.Helpers;

Expand All @@ -13,4 +16,23 @@ public static void CopyCustomData(ContainerCustomData target, string? sourceXml)
target.SetValue(columnName, customNodeData.GetValue(columnName));
}
}

public static string? GetSettingsKey(ModelFacade facade, int? siteId, string keyName)
{
var keys = facade.Select<ICmsSettingsKey>("KeyName = @keyName", "SiteID", new SqlParameter("keyName", keyName)).ToList();
return (keys.FirstOrDefault(x => x.SiteID == siteId)
?? keys.FirstOrDefault(x => x.SiteID == null))?.KeyValue;
}

public static T? GetSettingsKey<T>(ModelFacade facade, int? siteId, string keyName) where T : struct, IParsable<T>
{
var keys = facade.Select<ICmsSettingsKey>("KeyName = @keyName", "SiteID", new SqlParameter("keyName", keyName)).ToList();
string? value = (keys.FirstOrDefault(x => x.SiteID == siteId)
?? keys.FirstOrDefault(x => x.SiteID == null))?.KeyValue;


return T.TryParse(value, CultureInfo.InvariantCulture, out var result)
? result
: null;
}
}
35 changes: 25 additions & 10 deletions KVA/Migration.Toolkit.Source/Mappers/ContentItemMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using CMS.FormEngine;
using CMS.MediaLibrary;
using CMS.Websites;

using CMS.Websites.Internal;
using Kentico.Xperience.UMT.Model;

using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -77,12 +77,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 +347,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 +837,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<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
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<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
4 changes: 2 additions & 2 deletions KVA/Migration.Toolkit.Source/Migration.Toolkit.Source.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.2.0" />
<PackageReference Include="MediatR" Version="12.3.0"/>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.4.0" />
<PackageReference Include="MediatR" Version="12.4.0" />
</ItemGroup>

<PropertyGroup>
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; }
}
2 changes: 1 addition & 1 deletion Migration.Toolkit.CLI/Migration.Toolkit.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="12.3.0"/>
<PackageReference Include="MediatR" Version="12.4.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0"/>
Expand Down
4 changes: 2 additions & 2 deletions Migration.Toolkit.Common/Migration.Toolkit.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.2.0" />
<PackageReference Include="MediatR" Version="12.3.0"/>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.4.0" />
<PackageReference Include="MediatR" Version="12.4.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="12.3.0"/>
<PackageReference Include="MediatR" Version="12.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="12.3.0"/>
<PackageReference Include="MediatR" Version="12.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.2.0" />
<PackageReference Include="MediatR" Version="12.3.0"/>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.4.0" />
<PackageReference Include="MediatR" Version="12.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
</ItemGroup>

Expand Down
6 changes: 3 additions & 3 deletions Migration.Toolkit.K11/Migration.Toolkit.K11.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions Migration.Toolkit.KX12/Migration.Toolkit.KX12.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions Migration.Toolkit.KX13/Migration.Toolkit.KX13.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit 9f902dd

Please sign in to comment.