Skip to content

Commit

Permalink
linked documents no longer generate same urls as original documents
Browse files Browse the repository at this point in the history
K11/K12 fix
  • Loading branch information
tkrch committed Sep 2, 2024
1 parent 040ba4e commit 6c572d6
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions KVA/Migration.Toolkit.Source/Handlers/MigratePagesCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ public async Task<CommandResult> Handle(MigratePagesCommand request, Cancellatio
.SelectWhere<ICmsDocument>("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);
Expand Down Expand Up @@ -153,7 +154,8 @@ public async Task<CommandResult> 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);
}
}

Expand Down Expand Up @@ -254,7 +256,8 @@ await MigratePageUrlPaths(
commonDataInfos,
migratedDocument,
ksNode,
migratedDocument.DocumentCulture
migratedDocument.DocumentCulture,
isLinkedNode
);

existingDocumentLanguages.Add(languageGuid);
Expand All @@ -271,7 +274,8 @@ await MigratePageUrlPaths(
commonDataInfos,
null,
ksNode,
culture.ContentLanguageName
culture.ContentLanguageName,
isLinkedNode
);
}

Expand Down Expand Up @@ -335,7 +339,7 @@ private static void AsserVersionStatusRule(List<ContentItemCommonDataInfo> commo
}

private async Task MigratePageUrlPaths(Guid webPageItemGuid, int webPageItemId, Guid webSiteChannelGuid, Guid languageGuid,
List<ContentItemCommonDataInfo> contentItemCommonDataInfos, ICmsDocument? ksDocument, ICmsTree ksTree, string documentCulture)
List<ContentItemCommonDataInfo> contentItemCommonDataInfos, ICmsDocument? ksDocument, ICmsTree ksTree, string documentCulture, bool isLinkedNode)
{
var existingPaths = WebPageUrlPathInfo.Provider.Get()
.WhereEquals(nameof(WebPageUrlPathInfo.WebPageUrlPathWebPageItemID), webPageItemId)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6c572d6

Please sign in to comment.