Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…o-universal-migration-tool into feat/github-actions-pipeline
  • Loading branch information
Martin Medek authored and Martin Medek committed Nov 21, 2024
2 parents 234816e + 9b6c9b3 commit 19ee3f3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Authors>$(Company)</Authors>
<Copyright>Copyright © $(Company) $([System.DateTime]::Now.Year)</Copyright>
<Trademark>$(Company)™</Trademark>
<VersionPrefix>1.9.0</VersionPrefix>
<VersionPrefix>1.10.1</VersionPrefix>
<VersionSuffix></VersionSuffix>
<PackageLicenseExpression>MIT</PackageLicenseExpression>

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -454,4 +457,24 @@ private static IEnumerable<FormFieldInfo> UnpackReusableFieldSchemas(IEnumerable
}

Guid? IInfoAdapter<IUmtModel>.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<AssetSource>();
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;
}
}
}
8 changes: 5 additions & 3 deletions src/Kentico.Xperience.UMT/Model/Auxiliary/AssetSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -26,13 +24,17 @@ 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");
}


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
Expand All @@ -44,5 +46,5 @@ public class AssetUrlSource : AssetSource
public class AssetDataSource : AssetSource
{
[Required]
public byte[]? Data { get; set; }
public byte[]? Data { get; set; }
}
6 changes: 3 additions & 3 deletions src/Kentico.Xperience.UMT/Services/AssetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task<ContentItemAssetMetadata> 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,
Expand All @@ -58,7 +58,7 @@ public async Task<ContentItemAssetMetadata> 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,
Expand All @@ -77,7 +77,7 @@ public async Task<ContentItemAssetMetadata> 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,
Expand Down

0 comments on commit 19ee3f3

Please sign in to comment.