Copied to clipboard

Flag this post as spam?

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


  • Jamie Townsend 59 posts 279 karma points c-trib
    Apr 12, 2022 @ 08:49
    Jamie Townsend
    0

    7.15.2 to v8 latest migration

    Hi all,

    I am going through the process for a client to upgrade from 7.15.2 to the latest v8 currently 8.18.3.

    Using the Umbraco migrations and the Proworks amazing migration package most things are working well. One strange thing that isn't working is the migration of Related Links to MultiUrlPicker. when inside nested content.

    It should be noted that any Related Links successfully convert to MultiUrlPicker when not used inside of Nested Content.

    When used inside a Nested Content item the migration to MultiUrlPicker is done at data type level but the property data is not updated.

    Anyone have any ideas? Or solutions?

    Thanks muchly.

    J

  • Jamie Townsend 59 posts 279 karma points c-trib
    Apr 13, 2022 @ 17:57
    Jamie Townsend
    100

    I am sure there is a better way to do this, my client only had a few links to fix so I got away with a dirty bit of SQL but a better SQL could be written to find all of the MultiUrlPickers who's value is not updated from RelatedLinks. I.e. has a caption field etc.

    I created a migration so it's only ran once.

    var sql = Sql($"SELECT upd.* FROM dbo.umbracoPropertyData AS upd INNER JOIN dbo.umbracoContentVersion AS ucv ON ucv.id = upd.versionId WHERE upd.textValue LIKE '%\"caption\":%' AND upd.textValue LIKE '%\"isInternal\":%' AND ucv.[current] = 1");
            var dataToConvert = Database.Fetch<PropertyDataDto>(sql);
    
            if (dataToConvert.Any())
            {
                Logger.Info<NestedContentRelatedLinkMigration>("Found " + dataToConvert.Count + " RelatedLinks to fix");
    
                foreach (var propertyDataDto in dataToConvert)
                {
                    var items = JArray.Parse(propertyDataDto.TextValue);
                    if (items.Any())
                    {
                        foreach (var item in items)
                        {
                            if (item is JObject arrayProperty)
                            {
                                var aliasFound = LinkAliases.Where(x => arrayProperty.ContainsKey(x)).ToList();
                                if (aliasFound.Any())
                                {
                                    foreach (var alias in aliasFound)
                                    {
                                        var i = arrayProperty[alias];
                                        var t = JsonConvert.DeserializeObject<List<RelatedLinkDto>>(i.ToString());
    
                                        var toLink = (from x in t
                                            select new LinkDto()
                                            {
                                                Name = x.Caption,
                                                Target = x.NewWindow ? "_blank" : null,
                                                Udi = x.Link.Contains("umb://") ? x.Link : null,
                                                Url = x.IsInternal == false ? x.Link : null
                                            }).ToList();
    
                                        arrayProperty[alias] = JToken.Parse(JsonConvert.SerializeObject(toLink));
                                    }
                                }
                            }
                        }
    
                        propertyDataDto.TextValue = items.ToString();
                        Database.Update(propertyDataDto);
                    }
                }
            }
    
Please Sign in or register to post replies

Write your reply to:

Draft