From 77f6af191bd5482bc007a31bf6558d4e6c9054ab Mon Sep 17 00:00:00 2001 From: Michal Jakubis <64188398+michalJakubis@users.noreply.github.com> Date: Mon, 18 Nov 2024 12:21:31 +0100 Subject: [PATCH 1/4] Bump to v1.10.0 --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index da9551e..e476110 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,7 +5,7 @@ $(Company) Copyright © $(Company) $([System.DateTime]::Now.Year) $(Company)™ - 1.9.0 + 1.10.0 MIT From 3abc0a6059e24225b4d2453997f06bdea270df56 Mon Sep 17 00:00:00 2001 From: Michal Jakubis <64188398+michalJakubis@users.noreply.github.com> Date: Mon, 18 Nov 2024 12:23:56 +0100 Subject: [PATCH 2/4] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 08b343b..615d335 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ The Xperience by Kentico: Universal Migration Tool (UMT) is an open-source set o | Xperience Version | Library Version | | ----------------- | --------------- | +| >= 29.7.0 | >= 1.10.0 | | >= 29.6.0 | >= 1.9.0 | | >= 29.5.0 | >= 1.7.0 | | >= 29.4.0 | >= 1.6.0 | From ad9a4318720b30cf6c41aa3539b2c024556531ab Mon Sep 17 00:00:00 2001 From: akfakmot Date: Wed, 20 Nov 2024 00:00:03 +0100 Subject: [PATCH 3/4] Fix content hub previews of items with image asset Fix: Fix content hub previews of items with image asset --- .../ContentItemSimplifiedAdapter.cs | 27 +++++++++++++++++-- .../Model/Auxiliary/AssetSource.cs | 8 +++--- .../Services/AssetManager.cs | 6 ++--- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/Kentico.Xperience.UMT/InfoAdapter/ContentItemSimplifiedAdapter.cs b/src/Kentico.Xperience.UMT/InfoAdapter/ContentItemSimplifiedAdapter.cs index 02c539e..51cee8a 100644 --- a/src/Kentico.Xperience.UMT/InfoAdapter/ContentItemSimplifiedAdapter.cs +++ b/src/Kentico.Xperience.UMT/InfoAdapter/ContentItemSimplifiedAdapter.cs @@ -1,9 +1,12 @@ -using CMS.ContentEngine; +using System.Text.Json; + +using CMS.ContentEngine; using CMS.ContentEngine.Internal; using CMS.Core; using CMS.Core.Internal; using CMS.DataEngine; using CMS.FormEngine; +using CMS.Helpers; using CMS.Membership; using CMS.Websites; using CMS.Websites.Internal; @@ -244,7 +247,7 @@ public ContentItemInfo Adapt(IUmtModel input) ContentItemLanguageMetadataCreatedByUserGuid = languageData.UserGuid, ContentItemLanguageMetadataModifiedWhen = null, ContentItemLanguageMetadataModifiedByUserGuid = languageData.UserGuid, - // ContentItemLanguageMetadataHasImageAsset = null, + ContentItemLanguageMetadataHasImageAsset = languageData.ContentItemData?.Values.Any(IsImageAsset) ?? false, ContentItemLanguageMetadataContentLanguageGuid = contentLanguageInfo.ContentLanguageGUID, ContentItemLanguageMetadataScheduledPublishWhen = languageData.ScheduledPublishWhen, ContentItemLanguageMetadataScheduledUnpublishWhen = languageData.ScheduledUnpublishWhen @@ -454,4 +457,24 @@ private static IEnumerable UnpackReusableFieldSchemas(IEnumerable } Guid? IInfoAdapter.GetUniqueIdOrNull(IUmtModel input) => input is ContentItemSimplifiedModel sm ? sm.ContentItemGUID : null; + + private static bool IsImageAsset(object? value) + { + if (value is JsonElement { ValueKind: JsonValueKind.Object } element && element.GetProperty(AssetSource.DISCRIMINATOR_PROPERTY).GetString() is { }) + { + var assetSource = element.Deserialize(); + if (assetSource is not null) + { + return ImageHelper.IsImage(assetSource.InferExtension()); + } + else + { + throw new InvalidOperationException($"JSON object with property {AssetSource.DISCRIMINATOR_PROPERTY} cannot be deserialized"); + } + } + else + { + return false; + } + } } diff --git a/src/Kentico.Xperience.UMT/Model/Auxiliary/AssetSource.cs b/src/Kentico.Xperience.UMT/Model/Auxiliary/AssetSource.cs index 2564814..61e4310 100644 --- a/src/Kentico.Xperience.UMT/Model/Auxiliary/AssetSource.cs +++ b/src/Kentico.Xperience.UMT/Model/Auxiliary/AssetSource.cs @@ -14,10 +14,8 @@ namespace Kentico.Xperience.UMT.Model; public class AssetSource { public const string DISCRIMINATOR_PROPERTY = "$assetType"; - [Required] public Guid? ContentItemGuid { get; set; } - [Required] public Guid? Identifier { get; set; } [Required] @@ -26,6 +24,8 @@ public class AssetSource public string? Extension { get; set; } public long? Size { get; set; } public DateTime? LastModified { get; set; } + + public virtual string InferExtension() => Extension ?? throw new InvalidOperationException($"{nameof(AssetFileSource)} has unknown extension. Specify explicitly by {nameof(Extension)} property"); } @@ -33,6 +33,8 @@ public class AssetFileSource : AssetSource { [Required] public string? FilePath { get; set; } + + public override string InferExtension() => Extension ?? CMS.IO.FileInfo.New(FilePath).Extension ?? throw new InvalidOperationException($"{nameof(AssetFileSource)} has unknown extension. Specify explicitly by {nameof(Extension)} property"); } public class AssetUrlSource : AssetSource @@ -44,5 +46,5 @@ public class AssetUrlSource : AssetSource public class AssetDataSource : AssetSource { [Required] - public byte[]? Data { get; set; } + public byte[]? Data { get; set; } } diff --git a/src/Kentico.Xperience.UMT/Services/AssetManager.cs b/src/Kentico.Xperience.UMT/Services/AssetManager.cs index 2a40252..56c24e2 100644 --- a/src/Kentico.Xperience.UMT/Services/AssetManager.cs +++ b/src/Kentico.Xperience.UMT/Services/AssetManager.cs @@ -37,7 +37,7 @@ public async Task SetAsset(string className, AssetSour var assetMetadata = new ContentItemAssetMetadata { - Extension = byteSource.Extension, + Extension = assetSource.InferExtension(), Identifier = byteSource.Identifier.Value, LastModified = byteSource.LastModified ?? dateTimeNowService.GetDateTimeNow(), Name = byteSource.Name, @@ -58,7 +58,7 @@ public async Task SetAsset(string className, AssetSour var file = CMS.IO.FileInfo.New(fileSource.FilePath); var assetMetadata = new ContentItemAssetMetadata { - Extension = fileSource.Extension ?? file.Extension, + Extension = assetSource.InferExtension(), Identifier = fileSource.Identifier.Value, LastModified = fileSource.LastModified ?? dateTimeNowService.GetDateTimeNow(), Name = fileSource.Name ?? file.Name, @@ -77,7 +77,7 @@ public async Task SetAsset(string className, AssetSour var assetMetadata = new ContentItemAssetMetadata { - Extension = urlSource.Extension, + Extension = assetSource.InferExtension(), Identifier = urlSource.Identifier.Value, LastModified = urlSource.LastModified ?? dateTimeNowService.GetDateTimeNow(), Name = urlSource.Name, From 9b6c9b39c7760692663b13107b9cccc5e9aae0a6 Mon Sep 17 00:00:00 2001 From: Michal Jakubis <64188398+michalJakubis@users.noreply.github.com> Date: Wed, 20 Nov 2024 09:58:17 +0100 Subject: [PATCH 4/4] Update Directory.Build.props --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index e476110..09f314a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,7 +5,7 @@ $(Company) Copyright © $(Company) $([System.DateTime]::Now.Year) $(Company)™ - 1.10.0 + 1.10.1 MIT