Skip to content

Commit

Permalink
#245 target former urls instead of page urls paths
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrch committed Sep 19, 2024
1 parent 9531e7c commit cc712c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 39 deletions.
51 changes: 13 additions & 38 deletions KVA/Migration.Toolkit.Source/Handlers/MigratePagesCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CMS.ContentEngine;
using CMS.ContentEngine.Internal;
using CMS.Core;
using CMS.Core.Internal;
using CMS.DataEngine;
using CMS.DataEngine.Query;
using CMS.Websites;
Expand Down Expand Up @@ -366,7 +367,7 @@ private async Task MigratePageUrlPaths(Guid webSiteChannelGuid, Guid languageGui
}
else if (GetCmsClass(ksTree.NodeClassID) is { } cmsClass && string.IsNullOrWhiteSpace(cmsClass.ClassURLPattern))
{
logger.LogError("Cannot migrate url for document '{DocumentID}' / node '{NodeID}', class {ClassName} has no url pattern set - default fallback will be used.", ksDocument?.DocumentID, ksTree.NodeID, cmsClass.ClassName);
logger.LogWarning("Cannot migrate url for document '{DocumentID}' / node '{NodeID}', class {ClassName} has no url pattern set - cannot migrate to former url.", ksDocument?.DocumentID, ksTree.NodeID, cmsClass.ClassName);
}
else if (sourceInstanceContext.GetNodeUrls(ksTree.NodeID, site.SiteName) is not { Count: > 0 } pageModels)
{
Expand All @@ -383,44 +384,18 @@ private async Task MigratePageUrlPaths(Guid webSiteChannelGuid, Guid languageGui
else
{
string patchedUrl = pageModel.CultureUrl.TrimStart(['~']).TrimStart(['/']);

foreach (var contentItemCommonDataInfo in contentItemCommonDataInfos.Where(x => x.ContentItemCommonDataContentLanguageID == languageInfo.ContentLanguageID))
string urlHash = modelFacade.HashPath(patchedUrl);
var webPageFormerUrlPathInfo = new WebPageFormerUrlPathInfo
{
logger.LogTrace("Page url path common data info: CIID={ContentItemId} CLID={Language} ID={Id} IPC", contentItemCommonDataInfo.ContentItemCommonDataContentItemID, contentItemCommonDataInfo.ContentItemCommonDataContentLanguageID, contentItemCommonDataInfo.ContentItemCommonDataID);

// decision - if change in url occurs in source instance, it is desirable to overwrite migrated one.
var webPageUrlPathGuid = contentItemCommonDataInfo.ContentItemCommonDataVersionStatus == VersionStatus.Draft
? GuidHelper.CreateWebPageUrlPathGuid($"{ksDocument!.DocumentGUID}|{documentCulture}|{ksTree.NodeAliasPath}|DRAFT|{ksTree.NodeID}")
: GuidHelper.CreateWebPageUrlPathGuid($"{ksDocument!.DocumentGUID}|{documentCulture}|{ksTree.NodeAliasPath}|{ksTree.NodeID}");

string urlHash = modelFacade.HashPath(patchedUrl);

var webPageUrlPath = new WebPageUrlPathModel
{
WebPageUrlPathGUID = webPageUrlPathGuid,
WebPageUrlPath = patchedUrl,
WebPageUrlPathHash = urlHash,
WebPageUrlPathWebPageItemGuid = webPageItemInfo.WebPageItemGUID,
WebPageUrlPathWebsiteChannelGuid = webSiteChannelGuid,
WebPageUrlPathContentLanguageGuid = languageGuid,
WebPageUrlPathIsLatest = contentItemCommonDataInfo.ContentItemCommonDataIsLatest,
WebPageUrlPathIsDraft = contentItemCommonDataInfo.ContentItemCommonDataVersionStatus switch
{
VersionStatus.InitialDraft => false,
VersionStatus.Draft => true,
VersionStatus.Published => false,
VersionStatus.Unpublished => false,
_ => throw new ArgumentOutOfRangeException()
}
};

CheckPathAlreadyExists(webPageUrlPath, languageInfo, webSiteChannel, webPageItemInfo.WebPageItemID);

var importResult = await importer.ImportAsync(webPageUrlPath);

LogImportResult(importResult);
}

WebPageFormerUrlPath = patchedUrl,
WebPageFormerUrlPathHash = urlHash,
WebPageFormerUrlPathWebPageItemID = webPageItemInfo.WebPageItemID,
WebPageFormerUrlPathWebsiteChannelID = webSiteChannel.WebsiteChannelID,
WebPageFormerUrlPathContentLanguageID = languageInfo.ContentLanguageID,
WebPageFormerUrlPathLastModified = Service.Resolve<IDateTimeNowService>().GetDateTimeNow()
};
WebPageFormerUrlPathInfo.Provider.Set(webPageFormerUrlPathInfo);
logger.LogEntitySetAction(true, webPageItemInfo);
return;
}
}
Expand Down
3 changes: 2 additions & 1 deletion KVA/Migration.Toolkit.Source/Helpers/Printer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using CMS.MediaLibrary;
using CMS.Membership;
using CMS.Modules;

using CMS.Websites;
using Migration.Toolkit.Common.Helpers;
using Migration.Toolkit.Common.Services;
using Migration.Toolkit.KXP.Models;
Expand Down Expand Up @@ -61,6 +61,7 @@ string FormatModel(string inner) => printType
UserInfo item => FormatModel($"ID={item.UserID}, Guid={item.UserGUID} Name={item.UserName}"),
RoleInfo item => FormatModel($"ID={item.RoleID}, Guid={item.RoleGUID} Name={item.RoleName}"),
MemberInfo item => FormatModel($"ID={item.MemberID}, Guid={item.MemberGuid} Name={item.MemberName}"),
WebPageFormerUrlPathInfo item => FormatModel($"ID={item.WebPageFormerUrlPathID}, Guid=N/A Name={item.WebPageFormerUrlPath}"),

CmsForm item => FormatModel($"ID={item.FormId}, GUID={item.FormGuid}, Name={item.FormName}"),
CmsUser item => FormatModel($"ID={item.UserId}, GUID={item.UserGuid}, Name={item.UserName}"),
Expand Down

0 comments on commit cc712c1

Please sign in to comment.