Skip to content

Commit

Permalink
Feat/199 unpublished doc versions published (#209)
Browse files Browse the repository at this point in the history
* document PublishTo & PublishFrom migration path support

* whitespace corrections

---------

Co-authored-by: Tomáš Krch <[email protected]>
  • Loading branch information
tkrch and tkrch authored Jul 22, 2024
1 parent 42ce815 commit 45d664a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ FROM Media_Library
GROUP BY LibraryName
HAVING COUNT(*) > 1
""",
(reader, _) => new { LibraryName = reader.Unbox<int>("LibraryName"), LibraryGuids = reader.Unbox<string?>("LibraryGUIDs")?.Split('|').Select(Guid.Parse).ToImmutableList() ?? [] });
(reader, _) => new { LibraryName = reader.Unbox<string>("LibraryName"), LibraryGuids = reader.Unbox<string?>("LibraryGUIDs")?.Split('|').Select(Guid.Parse).ToImmutableList() ?? [] });

foreach (var mlg in unsuitableMediaLibraries)
{
Expand Down
39 changes: 36 additions & 3 deletions KVA/Migration.Toolkit.Source/Mappers/ContentItemMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using CMS.ContentEngine;
using CMS.ContentEngine.Internal;
using CMS.Core;
using CMS.Core.Internal;
using CMS.FormEngine;
using CMS.MediaLibrary;
using CMS.Websites;
Expand Down Expand Up @@ -125,13 +127,42 @@ protected override IEnumerable<IUmtModel> MapInternal(CmsTreeMapperSource source

var versionStatus = cmsDocument switch
{
{ DocumentIsArchived: true } => VersionStatus.Archived,
{ DocumentIsArchived: true } => VersionStatus.Unpublished,
{ DocumentPublishedVersionHistoryID: null, DocumentCheckedOutVersionHistoryID: null } => VersionStatus.Published,
{ DocumentPublishedVersionHistoryID: { } pubId, DocumentCheckedOutVersionHistoryID: { } chId } when pubId <= chId => VersionStatus.Published,
{ DocumentPublishedVersionHistoryID: null, DocumentCheckedOutVersionHistoryID: not null } => VersionStatus.InitialDraft,
_ => draftMigrated ? VersionStatus.Published : VersionStatus.InitialDraft
};

DateTime? scheduledPublishWhen = null;
DateTime? scheduleUnpublishWhen = null;

if (cmsDocument.DocumentPublishFrom is { } publishFrom)
{
var now = Service.Resolve<IDateTimeNowService>().GetDateTimeNow();
if (publishFrom > now)
{
versionStatus = VersionStatus.Unpublished;
}
else
{
scheduledPublishWhen = publishFrom;
}
}

if (cmsDocument.DocumentPublishTo is { } publishTo)
{
var now = Service.Resolve<IDateTimeNowService>().GetDateTimeNow();
if (publishTo < now)
{
versionStatus = VersionStatus.Unpublished;
}
else
{
scheduleUnpublishWhen = publishTo;
}
}

string? contentItemCommonDataPageBuilderWidgets = null;
string? contentItemCommonDataPageTemplateConfiguration = null;
switch (cmsDocument)
Expand Down Expand Up @@ -171,7 +202,7 @@ protected override IEnumerable<IUmtModel> MapInternal(CmsTreeMapperSource source
ContentItemCommonDataVersionStatus = versionStatus,
ContentItemCommonDataIsLatest = !draftMigrated, // Flag for latest record to know what to retrieve for the UI
ContentItemCommonDataPageBuilderWidgets = contentItemCommonDataPageBuilderWidgets,
ContentItemCommonDataPageTemplateConfiguration = contentItemCommonDataPageTemplateConfiguration
ContentItemCommonDataPageTemplateConfiguration = contentItemCommonDataPageTemplateConfiguration,
};

if (ndp)
Expand Down Expand Up @@ -275,7 +306,9 @@ protected override IEnumerable<IUmtModel> MapInternal(CmsTreeMapperSource source
// logic inaccessible, not supported
// ContentItemLanguageMetadataHasImageAsset = ContentItemAssetHasImageArbiter.HasImage(contentItemDataInfo), // This is for admin UI optimization - set to true if latest version contains a field with an image asset
ContentItemLanguageMetadataHasImageAsset = false,
ContentItemLanguageMetadataContentLanguageGuid = languageGuid // DocumentCulture -> language entity needs to be created and its ID used here
ContentItemLanguageMetadataContentLanguageGuid = languageGuid, // DocumentCulture -> language entity needs to be created and its ID used here
ContentItemLanguageMetadataScheduledPublishWhen = scheduledPublishWhen,
ContentItemLanguageMetadataScheduledUnpublishWhen = scheduleUnpublishWhen
};
yield return languageMetadataInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.1.0"/>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.2.0" />
<PackageReference Include="MediatR" Version="12.3.0"/>
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Migration.Toolkit.Common/Migration.Toolkit.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.1.0"/>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.2.0" />
<PackageReference Include="MediatR" Version="12.3.0"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.1.0"/>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.2.0" />
<PackageReference Include="MediatR" Version="12.3.0"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
</ItemGroup>
Expand Down

0 comments on commit 45d664a

Please sign in to comment.