From 6c572d6fbc06fbd0804bde1deb3479e01b439ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Krch?= Date: Mon, 2 Sep 2024 02:50:20 +0200 Subject: [PATCH] linked documents no longer generate same urls as original documents K11/K12 fix --- .../Handlers/MigratePagesCommandHandler.cs | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/KVA/Migration.Toolkit.Source/Handlers/MigratePagesCommandHandler.cs b/KVA/Migration.Toolkit.Source/Handlers/MigratePagesCommandHandler.cs index 4e4e0e7c..f645b5ed 100644 --- a/KVA/Migration.Toolkit.Source/Handlers/MigratePagesCommandHandler.cs +++ b/KVA/Migration.Toolkit.Source/Handlers/MigratePagesCommandHandler.cs @@ -90,9 +90,10 @@ public async Task Handle(MigratePagesCommand request, Cancellatio .SelectWhere("DocumentNodeID = @nodeId", new SqlParameter("nodeId", ksNode.NodeID)) .ToList(); - if (nodeLinkedNode != null) + bool isLinkedNode = nodeLinkedNode != null; + if (isLinkedNode) { - if (nodeLinkedNode.NodeSiteID != ksNode.NodeSiteID) + if (nodeLinkedNode?.NodeSiteID != ksNode.NodeSiteID) { // skip & write to protocol logger.LogWarning("Linked node with NodeGuid {NodeGuid} is linked from different site - unable to migrate", ksTreeOriginal.NodeGUID); @@ -153,7 +154,8 @@ public async Task Handle(MigratePagesCommand request, Cancellatio CmsTreeK13 node => node with { NodeLinkedNodeID = null, NodeLinkedNodeSiteID = null }, _ => ksNode }; - logger.LogTrace("Linked node with NodeGuid {NodeGuid} was materialized", ksNode.NodeGUID); + + logger.LogWarning("Linked node with NodeGuid {NodeGuid} was materialized (Xperience by Kentico doesn't support links), it no longer serves as link to original document. This affect also routing, this document will have own link generated from node alias path", ksNode.NodeGUID); } } @@ -254,7 +256,8 @@ await MigratePageUrlPaths( commonDataInfos, migratedDocument, ksNode, - migratedDocument.DocumentCulture + migratedDocument.DocumentCulture, + isLinkedNode ); existingDocumentLanguages.Add(languageGuid); @@ -271,7 +274,8 @@ await MigratePageUrlPaths( commonDataInfos, null, ksNode, - culture.ContentLanguageName + culture.ContentLanguageName, + isLinkedNode ); } @@ -335,7 +339,7 @@ private static void AsserVersionStatusRule(List commo } private async Task MigratePageUrlPaths(Guid webPageItemGuid, int webPageItemId, Guid webSiteChannelGuid, Guid languageGuid, - List contentItemCommonDataInfos, ICmsDocument? ksDocument, ICmsTree ksTree, string documentCulture) + List contentItemCommonDataInfos, ICmsDocument? ksDocument, ICmsTree ksTree, string documentCulture, bool isLinkedNode) { var existingPaths = WebPageUrlPathInfo.Provider.Get() .WhereEquals(nameof(WebPageUrlPathInfo.WebPageUrlPathWebPageItemID), webPageItemId) @@ -413,8 +417,8 @@ private async Task MigratePageUrlPaths(Guid webPageItemGuid, int webPageItemId, var webPageUrlPath = new WebPageUrlPathModel { WebPageUrlPathGUID = contentItemCommonDataInfo.ContentItemCommonDataVersionStatus == VersionStatus.Draft - ? GuidHelper.CreateWebPageUrlPathGuid($"{ksDocument!.DocumentGUID}|{documentCulture}|{ksTree.NodeAliasPath}|DRAFT") - : GuidHelper.CreateWebPageUrlPathGuid($"{ksDocument!.DocumentGUID}|{ksTree.NodeAliasPath}"), + ? GuidHelper.CreateWebPageUrlPathGuid($"{ksDocument!.DocumentGUID}|{documentCulture}|{ksTree.NodeAliasPath}|DRAFT|{ksTree.NodeID}") + : GuidHelper.CreateWebPageUrlPathGuid($"{ksDocument!.DocumentGUID}|{ksTree.NodeAliasPath}|{ksTree.NodeID}"), WebPageUrlPath = ksTree.NodeAliasPath, //ksPath.PageUrlPathUrlPath, // WebPageUrlPathHash = ksPath.PageUrlPathUrlPathHash, WebPageUrlPathWebPageItemGuid = webPageItemGuid, @@ -457,17 +461,16 @@ private async Task MigratePageUrlPaths(Guid webPageItemGuid, int webPageItemId, string urlPath = (ksDocument switch { - CmsDocumentK11 doc => doc.DocumentUrlPath, - CmsDocumentK12 doc => doc.DocumentUrlPath, + 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}"; var webPageUrlPath = new WebPageUrlPathModel { - WebPageUrlPathGUID = GuidHelper.CreateWebPageUrlPathGuid($"{urlPath}|{documentCulture}|{webSiteChannel.WebsiteChannelGUID}"), + WebPageUrlPathGUID = GuidHelper.CreateWebPageUrlPathGuid($"{urlPath}|{documentCulture}|{webSiteChannel.WebsiteChannelGUID}|{ksTree.NodeID}"), WebPageUrlPath = urlPath, - // WebPageUrlPathHash = kx13PageUrlPath.PageUrlPathUrlPathHash, WebPageUrlPathWebPageItemGuid = webPageItemGuid, WebPageUrlPathWebsiteChannelGuid = webSiteChannelGuid, WebPageUrlPathContentLanguageGuid = languageGuid, @@ -496,7 +499,7 @@ private async Task CreateDefaultPageUrlAsync(Guid webPageItemGuid, Guid webSiteC var webPageUrlPath = new WebPageUrlPathModel { - WebPageUrlPathGUID = GuidHelper.CreateWebPageUrlPathGuid($"{urlPath}|{documentCulture}|{webSiteChannel.WebsiteChannelGUID}"), + WebPageUrlPathGUID = GuidHelper.CreateWebPageUrlPathGuid($"{urlPath}|{documentCulture}|{webSiteChannel.WebsiteChannelGUID}|{ksTree.NodeID}"), WebPageUrlPath = urlPath, WebPageUrlPathWebPageItemGuid = webPageItemGuid, WebPageUrlPathWebsiteChannelGuid = webSiteChannelGuid,