Kentico/xperience-by-kentico-kentico-migration-tool

Page Type Migration: Media Library Form Control backed by Text field

Closed this issue · 7 comments

Brief bug description

For KX13 Page Types that are a data type of Text and use the Media Selector Form Control:

image

The migration toolkit brings those fields over into Xperience by Kentico as Text fields

image

This makes those types of fields unusable in Xperience by Kentico when you try to use them as Media Library selectors in Xperience because you have to change the type to Media Library but the value of the field is not the expected JSON format.

image

Repro steps

  1. Migrate command that uses --media-libraries to migrate via the CLI
  2. Change a given page type that has a field that should be a media file selector.
  3. Attempt to load that page in the pages app - edit mode.

Expected behavior

What is the correct behavior?

I should be able to use the field as a Media Library selector without the Pages app causing a 500.

tkrch commented

hello @mcbeev, this scenario is unfortunately unsupported.

There is no form component that supports media selection for text fields.
Migration to data type "Media files" is not possible with 100% accuracy or without losing data.

As You correctly pointed out, "Media files" component requires JSON structure, for example:
[{"Identifier":"de3e9831-5e1b-44c4-8688-e51fd2054792","Name":"Ungrouped-attachment-2.png","Size":32658,"Dimensions":{"Width":653,"Height":367}}]
(this structure implies, that url in KX13 shall have GUID identifier of media file or attachment - but this condition is not satisfied)

What KX13 "Media selector" for text field supports?

  1. url in format ~/getmedia/968e4486-8dce-4026-b21a-0f0db1e02a5f/testingmedia-wellformed.png?width=912&height=202&ext=.png
  2. url in format ~/getattachment/2f7afe3a-6973-4c8c-9cae-a54072ec9e6d/UngroupedAttachments.png?lang=en-US&ext=.png
  3. any url at all:
    image
    image

Why it isn't possible to convert data

An attempt migration to data type "Media files" would destroy all urls in format no.3. - valid data, those urls can be pointing to valid images.
As of now, only possible solution to not break data is to migrate field 1:1 - when media selector is supported for text field, i will change the target component for XbK.

It is not the issue of migration toolkit, rather than XbK simply doesn't support media selection for text field (in supported XbK version)

tkrch commented

I will try to further consult possibilities of what is better for product:

  • (actual behavior) migrate field 1:1 while keeping all links to images intact
  • (possible behavior) drop support for migration of generic link without GUID media or attachment identifier while ensuring better editor experience in XbK admin

Thanks for the update @tkrch, I think your specific answer makes sense. However, I think this is a very common use case for Kentico projects. I think there should be something different that happens here though as I have 250 blog posts to migrate and now basically won't have images for each one of them if nothing changes.

tkrch commented

@mcbeev i know Brian, it is very common use case - but it is not broken by Migration.Toolkit, this particular functionality is not supported in XbK (as far as i know, there is no media selector for free selection of url from Media files or anywhere else). I can try to convert data and drop unsupported data, however this should be decision of Migration.Toolkit user. It is also pretty common, that not all images in text field where "Media selector" is set are from media library.

Possible solution

i can see possible solution in letting the end user of Migration.Toolkit to choose (make behavior of conversion configurable) if he wants to convert text containing image to JSON containing explicit image GUID reference. But it shouldn't be default behavior - in that way any instance, that uses external reference to image or even own image stored somewhere else in system would be destroyed.

@DavidSlavik what are your thoughts on this? I can't decide, however i find it beneficial for solving pretty common use-case (with cost of lost data - that part can be mitigated by letting user to choose to convert or not).

All of our sites built since K12 MVC have used the text field of Page Types to store paths created by the Media Selector or URL Selector (with only the media library tab).

This inserts urls with the /getmedia/... path as the text value of the field.

We then use a Regex on this value to extract the Guid of the Media File and retrieve the file from the database to access the Description, Width, Height properties.

So this feature would be extremely important for us to be able to migrate any site to XbyK.

Make this a configurable setting would be nice.

But, this has me thinking about the extensibility story for the Migration Toolkit - are developers expected to fork, modify the source and then build the toolkit to handle use cases that it doesn't support?

Maybe there's a plugin/extension model that could let the Toolkit hand off migration of specific data to custom code/assembly without rebuilding the tool to get the custom functionality 🤔.

Hello all,

@mcbeev thank you for your feedback!

@seangwright I don't expect you or any other Partner to extend the tool by features that everybody can leverage from and could be done by us. We are fully committed to developing and supporting this tool and we are happy to extend the tool if our customers need it. The reason why the tool is open-sourced is to support all specific/niche needs but it is not the case.

We will introduce a new feature that will support Brian's scenario and it will be possible to turn it on/off in the configuration. I expect this to be delivered in the middle of the next week. We will keep you informed.

@mcbeev I'm sorry for your troubles...

tkrch commented

Hello @mcbeev, feature implementation was merged into master branch. You may test before documentation is updated (#128).

To activate feature, please add following configuration to "appsettings.json" section "Settings":

"OptInFeatures":{
  "CustomMigration":{
    "FieldMigrations": [
      {
        "SourceDataType": "text",
        "TargetDataType": "assets",
        "SourceFormControl": "MediaSelectionControl",
        "TargetFormComponent": "Kentico.Administration.AssetSelector",
        "Actions": [ "convert to asset" ],
        "FieldNameRegex": ".*"
      }
    ]
  }
}   

For details, please look into task #128 or feel free to ask me here.

Let me know if issue still persists, sorry for any inconvenience.