Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Oct 30, 2019 @ 17:31
    Ali Sheikh Taheri
    1

    '1150' is not a valid udi, after content migration from v7.15.3 to 8.2

    Hi

    I have migrated the content of my site from Umbraco version 7.15.3 to 8.2. During the upgrade, I was getting an error relating to using the unsupported Media Picker Property Editor. In order to complete the upgrade process, I had to delete MediaPicker Property Editor and assign MediaPicker2 to the data type I had on Umbraco version 7.15.3.

    Having removed and then changed the Media Picker the content migration was successful. Then with the new site (v8.2) when I write a simple query like

    var heroImage = content.Value("heroImage")

    getting an error saying "String "1150" is not a valid udi."

    I believe the value that is saved in the database it is still an integer whereas it should be UDI.

    I really appreciate if anyone can help as I might be missing some obvious steps here or there is a possibility that the content migration has forgotten to convert int to UDI.

    Many thank

  • Steve Megson 151 posts 1024 karma points MVP c-trib
    Oct 31, 2019 @ 14:44
    Steve Megson
    104

    Changing the property editor in v7 doesn't change any of the existing data, so you will still have int IDs in the database. Then the migration to v8 will just see that you're using the UDI-based property editor and expect that all the stored data is UDIs.

    There are plans to support the legacy property editors in the migration and convert int IDs to UDIs, but that doesn't help you right now if you've already run the migration.

    I think the easiest solution would be to add a custom version of MediaPickerValueConverter to your site, modifying it to handle both int and UDI values. I haven't tested it, but I think something like this should work:

    public class IntFriendlyMediaPickerValueConverter : Umbraco.Web.PropertyEditors.ValueConverters.MediaPickerValueConverter
    {
        public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType,
            object source, bool preview)
        {
            if (source == null) return null;
    
            var nodeIds = source.ToString()
                .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                .Select(id =>
                {
                    if (Udi.TryParse(id, out var udi))
                    {
                        return udi;
                    }
                    else if (Int32.TryParse(id, out var integer))
                    {
                        var item = _publishedSnapshotAccessor.PublishedSnapshot.Media.GetById(integer);
                        if (item != null)
                            return new GuidUdi(Constants.UdiEntityType.Media, item.Key);
                    }
                    return null;                        
                })                
                .ToArray();
            return nodeIds;
        }
    }
    
    public class MyComposer : IUserComposer
    {
        public void Compose(Composition composition)
        {
            composition.Register<IntFriendlyMediaPickerValueConverter>();
        }
    }
    

    That should solve any problems rendering templates.

    You may still have problems editing the migrated content, but I think it should only be a problem if you have a multi-valued media picker and add a new item. Removing and re-adding the existing item before adding the new one should get around that.

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Nov 01, 2019 @ 11:00
    Ali Sheikh Taheri
    0

    Thank you so much Steve, that has resolved the issue.

    I have tried a few approaches to convert the id to UDI without writing any custom code but that wasn't successful.

  • Ian Grainger 71 posts 135 karma points
    Dec 20, 2023 @ 12:57
    Ian Grainger
    1

    I'm seeing this in a migrated site.

    I have caught the formatException and used (int)GetProperty("image")?.GetSourceValue() - which seems to get the integer I'm looking for without an error!

Please Sign in or register to post replies

Write your reply to:

Draft