uSync Migrations - custom Nested Content migration
# help-with-umbraco
r
Hey, Appreciate the fantastic uSync migrations project I've inherited a v8 project that has a custom implementation of a Nested Content datatype. From what I can tell there's not much difference to the original Nested Content datatype, but I don't know the history of the project. I've recreated the DocType with a standard Nested Content DataType so I can see how the data is different in preparation to use uSync migrations. The data structure is the same it seems, but new lines are handled differently. Custom Nested Content
Copy code
<layout>
      <Value><![CDATA[[
  {
    "key": "f0a8df2b-f1f4-4a80-9c16-2b70a52216ae",
    "name": "Standard",
    "ncContentTypeAlias": "standard",
    "pageHeader": [
      {
        "key": "d7774230-5a6c-4415-b0e0-88193b4a379f",
        "name": "Hero",
        "ncContentTypeAlias": "hero",
        "title": "Hero Title Custom Nested Content",
        "subTitle": "Hero subTitle Custom Nested Content",
        "component": []
      }
    ],
    "display": [
      {
        "key": "c172bc9a-14e8-4a78-8567-7a4375bdf469",
        "name": "Html",
        "ncContentTypeAlias": "html",
        "text": "<p>Custom display</p>"
      }
    ]
  }
]]]></Value>
    </layout>
Standard Nested Content
Copy code
<layout13>
      <Value><![CDATA[[
  {
    "key": "d2327547-8933-4803-ac84-a9c769326c60",
    "name": "Standard",
    "ncContentTypeAlias": "standard",
    "pageHeader": "[\r\n  {\r\n    \"key\": \"21275e98-78c6-4563-933f-4389bfeef470\",\r\n    \"name\": \"Hero\",\r\n    \"ncContentTypeAlias\": \"hero\",\r\n    \"title\": \"Hero Title Standard Nested Content\",\r\n    \"subTitle\": \"Hero subTitle Standard Nested Content\",\r\n    \"component\": []\r\n  }\r\n]",
    "display": "[\r\n  {\r\n    \"key\": \"e073dbe0-9d90-40e7-be69-a4a0141fe236\",\r\n    \"name\": \"Html\",\r\n    \"ncContentTypeAlias\": \"html\",\r\n    \"text\": \"<p>Standard display</p>\"\r\n  }\r\n]"
  }
]]]></Value>
    </layout13>
tbc.
continued: Am I right in thinking this is the correct approach of how to deal with this: * Add uSync Migrations to my Umbraco project (do I just add 'uSync.Migrations.csproj' to my project instead of installing uSync Migrations?) * Copy the uSync.Migrations.Migrators/Core/NestedContentMigrator.cs code into a new file 'CustomNestedContentMigrator.cs' * Edit that file so that [SyncMigrator("Our.Umbraco.NestedContent")] is [SyncMigrator("CustomNestedContent")] * Figure out in this file by stepping through the code as it runs to deal with the way new lines are held and edit the code. Then run the migration and it should take my CustomNestedContent and transform it to BlockGrid / BlockList in the usync files as if it was a normal NestedContent item. Just so I'm super clear in my thinking, I then run this code on my v8 project so that the files are in good order for my v13 project to pick them up right? Hope that makes sense!
k
looks like migrations isn't escaping the nested elements (the values in the standard one is the JSON "escaped" into string values). the onward ever changing curse of the controls that do or don't do this. is one of the pains in my life 🙂 . I would hope it would still import ok, so i would try but i know from experience it might not, my advice for working on it if you want to changed this for your project. 1. Install a new blank Umbraco 2. add uSync migrations project to that 3. copy any uSync files you are working on in to that project (or upload if you used one of the packers to generate a zip) 4. add any custom code in that project 5. run your migrations throught that. you can then write your own custom nested content in that (you can see there two nested content already, one for nested content and one for nested to block list), and write your own migration plan to use it. (see https://github.com/Jumoo/uSyncMigrations/tree/main/MyMigrations for examples of the plan) OR you can create a fork of the main repository, down load and work on that as the umbraco project and put any fixes directly into the existing nested content migratior, then we will accept any fixes asa pull request and put them into the core package.
Also quicky say, I habef had a chance to look (painting the house today!) but there will be a method to do this escaping in the core uSync package so it's probably only a 1 line fix when it comes down to it If I get some time today, I will try to see if that's true
r
Thanks Kevin as always. Just to say, those json escaped into string values has come directly from usync rather than anything to do with migrations. That is essentially the original v8 project with usync installed. Not sure if that makes a difference. Will have another look. Really appreciate your help here.
k
Just went round in a big loop, and debugging only to relalise that between v8 -> v10+ we don't actually run the nested content throught any converters (the built in converter is for v7 only) doh!
So if you want to run the nested content through the converter when going from v8, you need to create a new migrator (which is just a stub of the exsiting one) and then a migration plan that tells usync.migrations to use this migrator for nested content . if you add the following to your project https://gist.github.com/KevinJump/ce72343e92b8f8b2566a70c5c6e340d8
you should then see a new option in the migration plan dropdown.
and that runs the migration through the converter, which will escape the json .
r
Thanks Kevin, That makes sense. So in my head the issue was the fact they this v8 was using a custom implementation of NestedContent but it wouldn't have been migrated in v8 anyways 🙂 Just so I'm clear, my actual need here is to convert NestedContent to BlockList, rather than Legacy NestedContent to Community NestedContent. Or do I just need to do this step first? Does the v7 migrator actually migrate the NestedContent to BlockList? If so, my aim is to replicate this for the v8 migrator My C# isn't actually the best, but can get one of my team to look into it
k
you can go v7 nested -> to block list, its just often easier to go to v8 first as its less of a big bang, in that sense i wouldn't worry about what the nested content looks like, because all the json parsed when its then converted to block list. and it will be in the right format at the end.
230 Views