Skip to content

Commit

Permalink
updating ability to convert web pages to content hub
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrch committed Nov 6, 2024
1 parent 78cf3a6 commit 5818f39
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ public async Task<CommandResult> Handle(MigratePageTypesCommand request, Cancell

foreach (string sourceClassName in classMapping.SourceClassNames)
{
if (newDt.ClassContentTypeType is ClassContentTypeType.REUSABLE)
{
continue;
}

var sourceClass = cmsClasses.First(c => c.ClassName.Equals(sourceClassName, StringComparison.InvariantCultureIgnoreCase));
foreach (var cmsClassSite in modelFacade.SelectWhere<ICmsClassSite>("ClassId = @classId", new SqlParameter("classId", sourceClass.ClassID)))
{
Expand Down
26 changes: 1 addition & 25 deletions KVA/Migration.Tool.Source/Handlers/MigratePagesCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,31 +213,7 @@ public async Task<CommandResult> Handle(MigratePagesCommand request, Cancellatio
var commonDataInfos = new List<ContentItemCommonDataInfo>();
foreach (var umtModel in results)
{
bool isReusable = toolConfiguration.ClassNamesConvertToContentHub.Contains(targetClass?.ClassName) || targetClass?.ClassContentTypeType is ClassContentTypeType.REUSABLE;


bool skipWebPageItem = umtModel is WebPageItemModel && isReusable;

IImportResult result = new ImportResult { Success = true };
if (skipWebPageItem)
{
if (targetClass is { } && targetClass.ClassContentTypeType == ClassContentTypeType.WEBSITE)
{
targetClass.ClassContentTypeType = ClassContentTypeType.REUSABLE;
targetClass.ClassWebPageHasUrl = false;
targetClass.Update();
}
}
else
{
result = await importer.ImportAsync(umtModel);
}
if (result is { Success: false } && !skipWebPageItem)
{
logger.LogError("Failed to import: {Exception}, {ValidationResults}", result.Exception, JsonConvert.SerializeObject(result.ModelValidationResults));
}

switch (result)
switch (await importer.ImportAsync(umtModel))
{
case { Success: true, Imported: ContentItemCommonDataInfo ccid }:
{
Expand Down
27 changes: 13 additions & 14 deletions KVA/Migration.Tool.Source/Mappers/ContentItemMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,12 @@ protected override IEnumerable<IUmtModel> MapInternal(CmsTreeMapperSource source
bool migratedAsContentFolder = sourceNodeClass.ClassName.Equals("cms.folder", StringComparison.InvariantCultureIgnoreCase) && !configuration.UseDeprecatedFolderPageType.GetValueOrDefault(false);

var contentItemGuid = spoiledGuidContext.EnsureNodeGuid(cmsTree.NodeGUID, cmsTree.NodeSiteID, cmsTree.NodeID);

string className = targetClassInfo?.ClassName ?? sourceNodeClass.ClassName;
bool isMappedTypeReusable = targetClassInfo?.ClassContentTypeType is ClassContentTypeType.REUSABLE;
bool isReusable = configuration.ClassNamesConvertToContentHub.Contains(className) || isMappedTypeReusable;

yield return new ContentItemModel
{
ContentItemGUID = contentItemGuid,
ContentItemName = safeNodeName,
ContentItemIsReusable = isReusable,
ContentItemIsReusable = isMappedTypeReusable,
ContentItemIsSecured = cmsTree.IsSecuredNode ?? false,
ContentItemDataClassGuid = migratedAsContentFolder ? null : targetClassGuid,
ContentItemChannelGuid = siteGuid
Expand Down Expand Up @@ -357,16 +353,19 @@ protected override IEnumerable<IUmtModel> MapInternal(CmsTreeMapperSource source
Debug.Assert(cmsTree.NodeLinkedNodeID == null, "cmsTree.NodeLinkedNodeId == null");
Debug.Assert(cmsTree.NodeLinkedNodeSiteID == null, "cmsTree.NodeLinkedNodeSiteId == null");

yield return new WebPageItemModel
if (!isMappedTypeReusable)
{
WebPageItemParentGuid = nodeParentGuid, // NULL => under root
WebPageItemGUID = contentItemGuid,
WebPageItemName = safeNodeName,
WebPageItemTreePath = treePath,
WebPageItemWebsiteChannelGuid = siteGuid,
WebPageItemContentItemGuid = contentItemGuid,
WebPageItemOrder = cmsTree.NodeOrder ?? 0 // 0 is nullish value
};
yield return new WebPageItemModel
{
WebPageItemParentGuid = nodeParentGuid, // NULL => under root
WebPageItemGUID = contentItemGuid,
WebPageItemName = safeNodeName,
WebPageItemTreePath = treePath,
WebPageItemWebsiteChannelGuid = siteGuid,
WebPageItemContentItemGuid = contentItemGuid,
WebPageItemOrder = cmsTree.NodeOrder ?? 0 // 0 is nullish value
};
}
}

private IEnumerable<IUmtModel> MigrateDraft(ICmsVersionHistory checkoutVersion, ICmsTree cmsTree, string sourceFormClassDefinition, string targetFormDefinition, Guid contentItemGuid,
Expand Down
1 change: 0 additions & 1 deletion Migration.Tool.Common/ConfigurationNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class ConfigurationNames
public const string UseDeprecatedFolderPageType = "UseDeprecatedFolderPageType";

public const string ExcludeCodeNames = "ExcludeCodeNames";
public const string ConvertClassesToContentHub = "ConvertClassesToContentHub";
public const string ExplicitPrimaryKeyMapping = "ExplicitPrimaryKeyMapping";

public const string SiteName = "SiteName";
Expand Down
10 changes: 0 additions & 10 deletions Migration.Tool.Common/ToolConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,11 @@ public class ToolConfiguration
[ConfigurationKeyName(ConfigurationNames.CreateReusableFieldSchemaForClasses)]
public string? CreateReusableFieldSchemaForClasses { get; set; }

[ConfigurationKeyName(ConfigurationNames.ConvertClassesToContentHub)]
public string? ConvertClassesToContentHub { get; set; }


public IReadOnlySet<string> ClassNamesCreateReusableSchema => classNamesCreateReusableSchema ??= new HashSet<string>(
(CreateReusableFieldSchemaForClasses?.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries) ?? []).Select(x => x.Trim()),
StringComparer.InvariantCultureIgnoreCase
);

public IReadOnlySet<string> ClassNamesConvertToContentHub => classNamesConvertToContentHub ??= new HashSet<string>(
(ConvertClassesToContentHub?.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries) ?? []).Select(x => x.Trim()),
StringComparer.InvariantCultureIgnoreCase
);

#region Opt-in features

[ConfigurationKeyName(ConfigurationNames.OptInFeatures)]
Expand Down Expand Up @@ -105,7 +96,6 @@ public void SetXbKConnectionStringIfNotEmpty(string? connectionString)
#region Path to root directory of target instance

private HashSet<string>? classNamesCreateReusableSchema;
private HashSet<string>? classNamesConvertToContentHub;
private string? xbKConnectionString;

[ConfigurationKeyName(ConfigurationNames.XbKDirPath)]
Expand Down
2 changes: 1 addition & 1 deletion Migration.Tool.Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static IServiceCollection UseCustomizations(this IServiceCollection servi

// services.AddClassMergeExample();
// services.AddSimpleRemodelingSample();
//services.AddReusableRemodelingSample();
// services.AddReusableRemodelingSample();
// services.AddReusableSchemaIntegrationSample();
return services;
}
Expand Down

0 comments on commit 5818f39

Please sign in to comment.