Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to convert Media Picker v2 to v3 progressively #10517

Merged
merged 6 commits into from
Jun 23, 2021

Conversation

nul800sebastiaan
Copy link
Member

In order to be easily able to move from Media Picker 2 (MP2) to Media Picker 3 (MP3), this PR helps convert existing values when you switch the datatype.

In the backoffice, when you switch a datatype from MP2 to MP3 and load any node with this new datatype, we'll detect if the old values were stored (a list of UDIs) and if so, we convert those to the new MediaWithCrops type. This allows us to show the previously selected media items in the backoffice. This happens in MediaPicker3PropertyEditor.ToEditor.

Once you save and publish the item with the new MP3 datatype, the converted data will be saved and we won't have to do that conversion again in the future. This way you will be progressively updating your nodes when an editor saves them and it is not needed to do a database migration to convert all the data on all the nodes.

In the frontend, you will need to replace your MP2 querying with MP3 querying. As we can see from the documentation the return type is change, so an example of updating a multiple media picker would be:

  • Media Picker 2: var typedMultiMediaPicker = Model.Value<IEnumerable<IPublishedContent>>("medias"); / @entry.Url
  • Media Picker 3: var typedMultiMediaPicker = Model.Value<IEnumerable<MediaWithCrops>>("medias"); / @entry.MediaItem.Url()

We do the exact same detection and conversion that we did in the backoffice on the frontend, see MediaPickerWithCropsValueConverter.

Both of the conversions are ultimately being done in MediaPicker3PropertyEditor.MediaPicker3PropertyValueEditor.Deserialize

A note: in Umbraco 7, we stored picked media items by integer identifiers, this was never the case in v8 and the property value converter in v8 never dealt with integer ids. Therefore we did not implement conversions here either.

If you want to make it an even simpler conversion and you do not plan to use the "local crops" feature on the MP3 datatype (don't configure any crops) then you can write your own property value converter (PVC) to give you the same data as MP2 gave you (IPublishedContent/IEnumerable<IPublishedContent>). If you want to add local crops in the future you could probably find a solution with an extension method in your PVC.
We recommend updating your templates with the new MediaWithCrops return type.

Final note: going back from MP3 to MP2 is not possible if MP3 values have been stored already, this is a forward-only fix.

Copy link
Member Author

@nul800sebastiaan nul800sebastiaan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left two comments for you to consider @ronaldbarendse but otherwise this is all great, I tested a few different scenarios and it seems like it should all work 🎉

ronaldbarendse and others added 2 commits June 23, 2021 09:42
# Conflicts:
#	src/Umbraco.Web.UI.Client/src/views/prevalueeditors/obsoletemediapickernotice.html
@nul800sebastiaan nul800sebastiaan changed the title Convert Media Picker v2 to v3 progressively Add the ability to convert Media Picker v2 to v3 progressively Jun 23, 2021
@nul800sebastiaan nul800sebastiaan merged commit 9382f6c into v8/contrib Jun 23, 2021
@nul800sebastiaan nul800sebastiaan deleted the v8/feature/convert-mp2-mp3-progressively branch June 23, 2021 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants