diff --git a/Directory.Build.props b/Directory.Build.props index da9551e..09f314a 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.1 MIT 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 | 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,