Skip to content

Commit

Permalink
Merge pull request #280 from Kentico/fix/content-type-for-legacymedia…
Browse files Browse the repository at this point in the history
…file

Add legacy media file allowed content type for migrated field
  • Loading branch information
akfakmot authored Oct 29, 2024
2 parents fc4b656 + e49acc1 commit 37930ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions KVA/Migration.Tool.Source/Services/AssetFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ private void AssertSuccess(IImportResult importResult, IUmtModel model)
Properties = new FormFieldProperties { FieldCaption = "Asset", },
Settings = new FormFieldSettings { CustomProperties = new Dictionary<string, object?> { { "AllowedExtensions", "_INHERITED_" } }, ControlName = "Kentico.Administration.ContentItemAssetUploader" }
};
internal static readonly DataClassModel LegacyMediaFileContentType = new()
public static readonly DataClassModel LegacyMediaFileContentType = new()
{
ClassName = "Legacy.MediaFile",
ClassType = ClassType.CONTENT_TYPE,
Expand Down Expand Up @@ -398,7 +398,7 @@ private void AssertSuccess(IImportResult importResult, IUmtModel model)
Properties = new FormFieldProperties { FieldCaption = "Asset", },
Settings = new FormFieldSettings { CustomProperties = new Dictionary<string, object?> { { "AllowedExtensions", "_INHERITED_" } }, ControlName = "Kentico.Administration.ContentItemAssetUploader" }
};
internal static readonly DataClassModel LegacyAttachmentContentType = new()
public static readonly DataClassModel LegacyAttachmentContentType = new()
{
ClassName = "Legacy.Attachment",
ClassType = ClassType.CONTENT_TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Migration.Tool.Source.Helpers;
using Migration.Tool.Source.Model;
using Migration.Tool.Source.Services;
using Newtonsoft.Json;

namespace Migration.Tool.Extensions.DefaultMigrations;

Expand Down Expand Up @@ -327,10 +328,16 @@ public void MigrateFieldDefinition(FormDefinitionPatcher formDefinitionPatcher,
columnTypeAttr?.SetValue(configuration.MigrateMediaToMediaLibrary ? FieldDataType.Assets : FieldDataType.ContentItemReference);

var settings = field.EnsureElement(FormDefinitionPatcher.FieldElemSettings);
settings.EnsureElement(FormDefinitionPatcher.SettingsElemControlname, e => e.Value = configuration.MigrateMediaToMediaLibrary ? FormComponents.AdminAssetSelectorComponent : FormComponents.AdminContentItemSelectorComponent);
if (configuration.MigrateMediaToMediaLibrary)
{
settings.EnsureElement(FormDefinitionPatcher.SettingsElemControlname, e => e.Value = FormComponents.AdminAssetSelectorComponent);
settings.EnsureElement(FormDefinitionPatcher.SettingsMaximumassets, maxAssets => maxAssets.Value = FormDefinitionPatcher.SettingsMaximumassetsFallback);
}
else
{
settings.EnsureElement(FormDefinitionPatcher.SettingsElemControlname, e => e.Value = FormComponents.AdminContentItemSelectorComponent);
Guid[] allowedContentTypes = [AssetFacade.LegacyMediaFileContentType.ClassGUID!.Value, AssetFacade.LegacyAttachmentContentType.ClassGUID!.Value];
settings.EnsureElement(FormDefinitionPatcher.AllowedContentItemTypeIdentifiers, e => e.Value = JsonConvert.SerializeObject(allowedContentTypes.Select(x => x.ToString()).ToArray()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class FormDefinitionPatcher
public const string FieldElem = "field";
public const string FieldElemProperties = "properties";
public const string FieldElemSettings = "settings";
public const string AllowedContentItemTypeIdentifiers = "AllowedContentItemTypeIdentifiers";
public const string PropertiesElemDefaultvalue = "defaultvalue";
public const string SettingsElemControlname = "controlname";
public const string SettingsMaximumassets = "MaximumAssets";
Expand Down

0 comments on commit 37930ff

Please sign in to comment.