Skip to content

Commit

Permalink
fixes related to K12 migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrch committed Sep 5, 2024
1 parent 1246223 commit 5d4d7aa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task<CommandResult> Handle(MigratePageTypesCommand request, Cancell
{
var (_, ksClass) = di;

if (ksClass.ClassInheritsFromClassID is { } classInheritsFromClassId && !primaryKeyMappingContext.HasMapping<CmsClass>(c => c.ClassId, classInheritsFromClassId))
if (ksClass.ClassInheritsFromClassID is { } classInheritsFromClassId && !primaryKeyMappingContext.HasMapping<ICmsClass>(c => c.ClassID, classInheritsFromClassId))
{
// defer migration to later stage
if (ksClasses.TryDeferItem(di))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private async Task MigratePageUrlPaths(Guid webPageItemGuid, int webPageItemId,
WebPageUrlPathGUID = contentItemCommonDataInfo.ContentItemCommonDataVersionStatus == VersionStatus.Draft
? Guid.NewGuid()
: ksPath.PageUrlPathGUID,
WebPageUrlPath = ksPath.PageUrlPathUrlPath,
WebPageUrlPath = ksPath.PageUrlPathUrlPath.TrimStart('/'),
WebPageUrlPathHash = ksPath.PageUrlPathUrlPathHash,
WebPageUrlPathWebPageItemGuid = webPageItemGuid,
WebPageUrlPathWebsiteChannelGuid = webSiteChannelGuid,
Expand Down Expand Up @@ -420,7 +420,7 @@ private async Task MigratePageUrlPaths(Guid webPageItemGuid, int webPageItemId,
WebPageUrlPathGUID = contentItemCommonDataInfo.ContentItemCommonDataVersionStatus == VersionStatus.Draft
? GuidHelper.CreateWebPageUrlPathGuid($"{ksDocument!.DocumentGUID}|{documentCulture}|{ksTree.NodeAliasPath}|DRAFT|{ksTree.NodeID}")
: GuidHelper.CreateWebPageUrlPathGuid($"{ksDocument!.DocumentGUID}|{ksTree.NodeAliasPath}|{ksTree.NodeID}"),
WebPageUrlPath = ksTree.NodeAliasPath, //ksPath.PageUrlPathUrlPath,
WebPageUrlPath = ksTree.NodeAliasPath.TrimStart('/'), //ksPath.PageUrlPathUrlPath,
// WebPageUrlPathHash = ksPath.PageUrlPathUrlPathHash,
WebPageUrlPathWebPageItemGuid = webPageItemGuid,
WebPageUrlPathWebsiteChannelGuid = webSiteChannelGuid,
Expand Down Expand Up @@ -460,13 +460,13 @@ private async Task MigratePageUrlPaths(Guid webPageItemGuid, int webPageItemId,
logger.LogTrace("Page url path common data info: CIID={ContentItemId} CLID={Language} ID={Id}", contentItemCommonDataInfo.ContentItemCommonDataContentItemID,
contentItemCommonDataInfo.ContentItemCommonDataContentLanguageID, contentItemCommonDataInfo.ContentItemCommonDataID);

string urlPath = (ksDocument switch
string urlPath = ((ksDocument switch
{
CmsDocumentK11 doc => isLinkedNode ? $"{languageInfo.ContentLanguageName}{ksTree.NodeAliasPath}" : doc.DocumentUrlPath,
CmsDocumentK12 doc => isLinkedNode ? $"{languageInfo.ContentLanguageName}{ksTree.NodeAliasPath}" : doc.DocumentUrlPath,
null => $"{languageInfo.ContentLanguageName}{ksTree.NodeAliasPath}",
_ => null
}).NullIf(string.Empty) ?? $"{ksTree.NodeAliasPath}";
}).NullIf(string.Empty) ?? $"{ksTree.NodeAliasPath}").TrimStart('/');

var webPageUrlPath = new WebPageUrlPathModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@

using System.Collections.Concurrent;
using System.Diagnostics;
using System.Text.RegularExpressions;
using CMS.ContentEngine.Internal;
using CMS.Core;
using CMS.Helpers;
using Kentico.Xperience.UMT.Services;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Logging;
Expand All @@ -23,15 +19,6 @@ public class AttachmentMigratorToContentItem(
IImporter importer
) : IAttachmentMigrator
{
private static readonly Regex sanitizationRegex =
RegexHelper.GetRegex("[^-_a-z0-9]", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.CultureInvariant);

private static readonly Regex libraryPathValidationRegex =
RegexHelper.GetRegex("^[-_a-z0-9]+$", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.CultureInvariant);


private readonly ConcurrentDictionary<(string libraryName, int siteId), int> mediaLibraryIdCache = new();

public async Task<IMigrateAttachmentResult> TryMigrateAttachmentByPath(string documentPath, string additionalPath)
{
if (string.IsNullOrWhiteSpace(documentPath))
Expand Down Expand Up @@ -108,7 +95,7 @@ public async Task<IMigrateAttachmentResult> MigrateAttachment(Guid ksAttachmentG
}
}

private bool assetFacadeInitialized = false;
private bool assetFacadeInitialized;
public async Task<IMigrateAttachmentResult> MigrateAttachment(ICmsAttachment ksAttachment, string? additionalMediaPath = null)
{
if (!assetFacadeInitialized)
Expand Down Expand Up @@ -151,7 +138,7 @@ public async Task<IMigrateAttachmentResult> MigrateAttachment(ICmsAttachment ksA
var contentLanguageRetriever = Service.Resolve<IContentLanguageRetriever>();
var defaultContentLanguage = await contentLanguageRetriever.GetDefaultContentLanguage();

var asset = await assetFacade.FromAttachment(ksAttachment, site, ksNode, [defaultContentLanguage.ContentLanguageName]);
var asset = await assetFacade.FromAttachment(ksAttachment, site, ksNode, [ksAttachmentDocument?.DocumentCulture ?? defaultContentLanguage.ContentLanguageName]);
switch (await importer.ImportAsync(asset))
{
case { Success: true }:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Linq.Expressions;

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

Expand Down

0 comments on commit 5d4d7aa

Please sign in to comment.