Jumoo / uSyncMigrations

Rough and ready migration code.
Mozilla Public License 2.0
48 stars 63 forks source link

Migration plan that updates legacy grid to block grid and Umbraco.MediaPicker to MediaPicker3 issues #276

Open mistyn8 opened 4 months ago

mistyn8 commented 4 months ago

So as per the title.. Migration plan that updates legacy grid to block grid and Umbraco.MediaPicker to MediaPicker3 issues I can see that the conversions are occurring when exiting the GetContentValue() of the mediaPickerMigrator and the old UDI list of media is correctly changed over to {Key, MediaKey} etc... but at the end of the process the new block grid has `"images" : []" I can't see anything of note in the debug logs... I can also see that normal doctype properties do get converted correctly from legacy to mediapicker3.. so something in the internals of the DTGE block grid migrator? Any pointers on where to look in the source to try and track down the issue?

 public MigrationOptions Options => new()
 {
     Group = "Convert",
     Source = "uSync/v9",
     Target = $"{uSyncMigrations.MigrationFolder}/{DateTime.Now:yyyyMMdd_HHmmss}",
     Handlers = _migrationHandlers.SelectGroup(8, string.Empty),
     SourceVersion = 8,
     PreferredMigrators = new Dictionary<string, string>
     {
         { UmbConstants.PropertyEditors.Aliases.NestedContent, nameof(NestedToBlockListMigrator) },
         { UmbConstants.PropertyEditors.Aliases.Grid, nameof(GridToBlockGridMigrator) },
         { UmbConstants.PropertyEditors.Aliases.MediaPicker, nameof(SMMediaPickerMigrator) },
         { "Umbraco.MediaPicker2", nameof(SMMediaPickerMigrator) },
         { UmbConstants.PropertyEditors.Aliases.MultipleMediaPicker, nameof(SMMediaPickerMigrator)},
         { UmbConstants.PropertyEditors.Aliases.MultipleTextstring, nameof(SMMultipleTextStringMigrator)}
     }
 };
[SyncMigrator(UmbConstants.PropertyEditors.Aliases.MediaPicker)]
[SyncMigrator("Umbraco.MediaPicker2")]
[SyncMigrator(UmbConstants.PropertyEditors.Aliases.MultipleMediaPicker)]
[SyncMigratorVersion(8)]
public class SMMediaPickerMigrator : MediaPickerMigrator
{
    public override string? GetContentValue(SyncMigrationContentProperty contentProperty, SyncMigrationContext context)
    {
        return base.GetContentValue(contentProperty, context);
    }
}
<?xml version="1.0" encoding="utf-8"?>
<Content Key="81c190e0-7b28-481e-8b27-d138d81152c6" Alias="Charity Support" Level="2">
  <Info>
    <Parent Key="4b5454af-0fe2-4529-9972-31be8df1cae9">bw</Parent>
    <Path>/bw/CharitySupport</Path>
    <Trashed>false</Trashed>
    <ContentType>contentPage</ContentType>
    <CreateDate>2021-10-07T16:15:41</CreateDate>
    <NodeName Default="Charity Support" />
    <SortOrder>30</SortOrder>
    <Published Default="true" />
    <Schedule />
    <Template Key="da457eee-784b-4d85-bd24-c102089c2a9a">ContentPage</Template>
  </Info>
  <Properties>
    <accentColour>
      <Value><![CDATA[]]></Value>
    </accentColour>
    <confidences>
      <Value><![CDATA[]]></Value>
    </confidences>
    <hideConfidences>
      <Value><![CDATA[0]]></Value>
    </hideConfidences>
    <hideFromHtmlSitemap>
      <Value><![CDATA[0]]></Value>
    </hideFromHtmlSitemap>
    <hideFromSearch>
      <Value><![CDATA[0]]></Value>
    </hideFromSearch>
    <hidePromoBanner>
      <Value><![CDATA[0]]></Value>
    </hidePromoBanner>
    <listingIcon>
      <Value><![CDATA[]]></Value>
    </listingIcon>
    <listingImage>
      <Value><![CDATA[]]></Value>
    </listingImage>
    <listingSnippet>
      <Value><![CDATA[]]></Value>
    </listingSnippet>
    <listingTitle>
      <Value><![CDATA[]]></Value>
    </listingTitle>
    <mainSectionClass>
      <Value><![CDATA[]]></Value>
    </mainSectionClass>
    <menuText>
      <Value><![CDATA[]]></Value>
    </menuText>
    <ogDescription>
      <Value><![CDATA[]]></Value>
    </ogDescription>
    <ogImage>
      <Value><![CDATA[[
  {
    "key": "eaf23554-b693-488e-8314-b3b968d0c5a2",
    "mediaKey": "3317ec28-2a91-42c5-805e-5123441584cc",
    "crops": [],
    "focalPoint": {
      "left": 0.5,
      "top": 0.5
    }
  }
]]]></Value>
    </ogImage>
    <ogTitle>
      <Value><![CDATA[BW Auctions, Sales and Remarketing]]></Value>
    </ogTitle>
    <pageBody>
      <Value><![CDATA[{
  "name": "Layout",
  "sections": [
    {
      "grid": "12",
      "rows": [
        {
          "name": "Large left, Small right",
          "id": "eef2bb1a-d8ed-4692-a269-55108b5c00f0",
          "areas": [
            {
              "grid": "8",
              "controls": [
                {
                  "value": {
                    "dtgeContentTypeAlias": "rteComponent",
                    "value": {
                      "name": "Text",
                      "text": "<h3><strong>Lead Charity: St Michaels Hospice, Herefordshire</strong></h3>\n<p>St Michael’s has been at the forefront of the Hospice care movement since 1984. By sharing their knowledge and expertise with other healthcare professionals, they have played an important role in revolutionising palliative care.</p>\n<p>With patients living longer than ever before, their professional staff and trained volunteers are committed to improving the quality of life for the patients and their families and carers.</p>",
                      "padding": "1",
                      "backgroundColour": "",
                      "accentColour": ""
                    },
                    "id": "594ffc6f-d29c-7205-1083-7c02118df01f"
                  },
                  "editor": {
                    "alias": "richtextEditor",
                    "view": "/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.html"
                  },
                  "styles": null,
                  "config": null
                }
              ],
              "styles": null,
              "config": null
            },
            {
              "grid": "4",
              "controls": [
                {
                  "value": {
                    "dtgeContentTypeAlias": "imageGallery",
                    "value": {
                      "name": "Image",
                      "images": "umb://media/a55c69bb47c64d8fa7a5e4d536f3a1b5",
                      "showInCarousel": "0",
                      "cTALink": [],
                      "imageCropSetting": "",
                      "setAsBackgroundImage": "0"
                    },
                    "id": "7b7c9c6e-a784-9bc2-dd59-b32c48e48d0a"
                  },
                  "editor": {
                    "alias": "imageGallery",
                    "view": "/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.html"
                  },
                  "styles": null,
                  "config": null
                }
              ],
              "styles": null,
              "config": null
            }
          ],
          "styles": {},
          "config": {
            "fullScreen": "1"
          }
        },        
      ]
    }
  ]
}]]></Value>
    </pageBody>
    <pageClass>
      <Value><![CDATA[]]></Value>
    </pageClass>
    <promoBanner>
      <Value><![CDATA[]]></Value>
    </promoBanner>
    <seoDescription>
      <Value><![CDATA[]]></Value>
    </seoDescription>
    <seoTitle>
      <Value><![CDATA[BW Auctions, Sales and Remarketing]]></Value>
    </seoTitle>
    <seoXmlSiteMapHide>
      <Value><![CDATA[0]]></Value>
    </seoXmlSiteMapHide>
    <umbracoInternalRedirectId>
      <Value><![CDATA[]]></Value>
    </umbracoInternalRedirectId>
    <umbracoNaviHide>
      <Value><![CDATA[0]]></Value>
    </umbracoNaviHide>
    <umbracoRedirect>
      <Value><![CDATA[]]></Value>
    </umbracoRedirect>
    <umbracoUrlAlias>
      <Value><![CDATA[]]></Value>
    </umbracoUrlAlias>
    <umbracoUrlName>
      <Value><![CDATA[]]></Value>
    </umbracoUrlName>
  </Properties>
</Content>
mistyn8 commented 4 months ago

resultant conversion.. Which actually now I look closely has stripped an existing mediaPicker3 for ogImage, as well as Images: in the grid from dtge being []

<?xml version="1.0" encoding="utf-8"?>
<Content Key="81c190e0-7b28-481e-8b27-d138d81152c6" Alias="Charity Support" Level="2">
  <Info>
    <Parent Key="4b5454af-0fe2-4529-9972-31be8df1cae9">bw</Parent>
    <Path>/bw/CharitySupport</Path>
    <Trashed>false</Trashed>
    <ContentType>contentPage</ContentType>
    <CreateDate>2021-10-07T16:15:41</CreateDate>
    <NodeName Default="Charity Support" />
    <SortOrder>30</SortOrder>
    <Published Default="true" />
    <Schedule />
    <Template Key="da457eee-784b-4d85-bd24-c102089c2a9a">ContentPage</Template>
  </Info>
  <Properties>
    <accentColour>
      <Value><![CDATA[]]></Value>
    </accentColour>
    <confidences>
      <Value><![CDATA[]]></Value>
    </confidences>
    <hideConfidences>
      <Value><![CDATA[0]]></Value>
    </hideConfidences>
    <hideFromHtmlSitemap>
      <Value><![CDATA[0]]></Value>
    </hideFromHtmlSitemap>
    <hideFromSearch>
      <Value><![CDATA[0]]></Value>
    </hideFromSearch>
    <hidePromoBanner>
      <Value><![CDATA[0]]></Value>
    </hidePromoBanner>
    <listingIcon>
      <Value><![CDATA[]]></Value>
    </listingIcon>
    <listingImage>
      <Value><![CDATA[]]></Value>
    </listingImage>
    <listingSnippet>
      <Value><![CDATA[]]></Value>
    </listingSnippet>
    <listingTitle>
      <Value><![CDATA[]]></Value>
    </listingTitle>
    <mainSectionClass>
      <Value><![CDATA[]]></Value>
    </mainSectionClass>
    <menuText>
      <Value><![CDATA[]]></Value>
    </menuText>
    <ogDescription>
      <Value><![CDATA[]]></Value>
    </ogDescription>
    <ogImage>
      <Value><![CDATA[[]]]></Value>
    </ogImage>
    <ogTitle>
      <Value><![CDATA[BW Auctions, Sales and Remarketing]]></Value>
    </ogTitle>
    <pageBody>
      <Value><![CDATA[{
  "layout": {
    "Umbraco.BlockGrid": [
      {
        "contentUdi": "umb://element/eef2bb1ad8ed4692a26955108b5c00f0",
        "settingsUdi": "umb://element/eef2bb1ad8ed4692a26955108b5c00f0",
        "columnSpan": 12,
        "rowSpan": 1,
        "areas": [
          {
            "key": "bcfd72d1-259f-3cda-b572-bed732f2c333",
            "items": [
              {
                "contentUdi": "umb://element/8510a8d92f3a469bafa141a960e6d931",
                "columnSpan": 8,
                "rowSpan": 1,
                "areas": []
              }
            ]
          },
          {
            "key": "eb36d1a5-c92c-3b61-8335-455f5a12deee",
            "items": [
              {
                "contentUdi": "umb://element/3083b626627d4c77b75c1a5d6421ec58",
                "columnSpan": 4,
                "rowSpan": 1,
                "areas": []
              }
            ]
          }
        ]
      }
    ]
  },
  "contentData": [
    {
      "contentTypeKey": "016981ac-29fe-43fd-9298-f5df2ecfca6f",
      "udi": "umb://element/8510a8d92f3a469bafa141a960e6d931",
      "text": "<h3><strong>Lead Charity: St Michaels Hospice, Herefordshire</strong></h3>\n<p>St Michael’s has been at the forefront of the Hospice care movement since 1984. By sharing their knowledge and expertise with other healthcare professionals, they have played an important role in revolutionising palliative care.</p>\n<p>With patients living longer than ever before, their professional staff and trained volunteers are committed to improving the quality of life for the patients and their families and carers.</p>",
      "padding": "1",
      "backgroundColour": "",
      "accentColour": ""
    },
    {
      "contentTypeKey": "9dc20f98-5e70-4416-aeab-6916e9578d0b",
      "udi": "umb://element/3083b626627d4c77b75c1a5d6421ec58",
      "images": "[]",
      "showInCarousel": "0",
      "cTALink": [],
      "imageCropSetting": "",
      "setAsBackgroundImage": "0"
    },
    {
      "contentTypeKey": "cf4c9668-e11c-3d37-8d04-9aac10868781",
      "udi": "umb://element/eef2bb1ad8ed4692a26955108b5c00f0"
    }
  ],
  "settingsData": [
    {
      "contentTypeKey": "b986e86b-7810-322a-a051-47b7ef84b732",
      "udi": "umb://element/eef2bb1ad8ed4692a26955108b5c00f0",
      "fullScreen": "1"
    }
  ]
}]]></Value>
    </pageBody>
    <pageClass>
      <Value><![CDATA[]]></Value>
    </pageClass>
    <promoBanner>
      <Value><![CDATA[]]></Value>
    </promoBanner>
    <seoDescription>
      <Value><![CDATA[]]></Value>
    </seoDescription>
    <seoTitle>
      <Value><![CDATA[BW Auctions, Sales and Remarketing]]></Value>
    </seoTitle>
    <seoXmlSiteMapHide>
      <Value><![CDATA[0]]></Value>
    </seoXmlSiteMapHide>
    <umbracoInternalRedirectId>
      <Value><![CDATA[]]></Value>
    </umbracoInternalRedirectId>
    <umbracoNaviHide>
      <Value><![CDATA[0]]></Value>
    </umbracoNaviHide>
    <umbracoRedirect>
      <Value><![CDATA[]]></Value>
    </umbracoRedirect>
    <umbracoUrlAlias>
      <Value><![CDATA[]]></Value>
    </umbracoUrlAlias>
    <umbracoUrlName>
      <Value><![CDATA[]]></Value>
    </umbracoUrlName>
  </Properties>
</Content>
mistyn8 commented 4 months ago

And here is it exiting the content conversion.. with the corresponding a55c69bb47c64d8fa7a5e4d536f3a1b5 mediaKey? image

mistyn8 commented 4 months ago

Further digging, and it seems to loop through twice trying to update mediaPicker to mediaPicker3, though the contentAlias is still mediaPicker on the second iteration whilst the contentProperty.Value is already in the mediaPicker3 format..

adding a quick and dirty check for mediaKey seems to work for now

public override string? GetContentValue(SyncMigrationContentProperty contentProperty, SyncMigrationContext context)
{
    if (string.IsNullOrWhiteSpace(contentProperty.Value))
    {
        return contentProperty.Value;
    }
    //TODO: check it's not mediaPicker3Already... (seems to loop though twice for grid, and wipes out the ogImage)

    if (contentProperty.Value.Contains("mediaKey"))
    {
        return contentProperty.Value;
    }
    //otherwsie try and convert
    var x = base.GetContentValue(contentProperty, context);
    return x;
}
mistyn8 commented 4 months ago

or maybe better??

try
{
    var mp3 = JsonConvert.DeserializeObject<IEnumerable<MediaWithCropsDto>>(contentProperty.Value);
    return contentProperty.Value;
}
catch { }
shadowcaptain commented 4 months ago

or maybe better??

try
{
    var mp3 = JsonConvert.DeserializeObject<IEnumerable<MediaWithCropsDto>>(contentProperty.Value);
    return contentProperty.Value;
}
catch { }

Or this, as a pattern used in other migrators....

        if (contentProperty.Value.DetectIsJson())
        {
            return contentProperty.Value;
        }
mistyn8 commented 4 months ago

That just checks that it is a json string though... and not that it is specifically json that is the correct schema for a mediaPicker3?