I’m attempting to upgrade a site from 13 to 17, however I need a way to migrate Nested Content to a Block List and a Media Picker to Media Picker 3, Are there any pre-existing migration scripts out there that will do this. I can see something similar was done fro Umbraco Deploy - ReplaceNestedContentDataTypeArtifactMigrator and ReplaceMediaPickerDataTypeArtifactMigrator but we don’t have / use Deploy.
the autoblocklist package was great for my upgrade from 13 to 17, but I did have an issue with the legacy media picker, which is no longer available in v17, does Umbraco not migrate those as part of the update, after the upgrade, I had a message saying the content was still there and i needed to change the data type, which I did, but now I have lost the data. What do I need to do pre 17 upgrade to migrate the legacy media data types?
On the Legacy Media Pickers.. I had to go with a custom migration plan/profile, think along these lines..
public class MediaPicker3kMigrationPlan : ISyncMigrationPlan
{
private readonly SyncMigrationHandlerCollection _migrationHandlers;
public MediaPicker3kMigrationPlan(SyncMigrationHandlerCollection migrationHandlers)
{
_migrationHandlers = migrationHandlers;
}
public int Order => 203;
public string Name => "Convert Legacy Media to mediaPicker3";
public string Icon => "icon-brick color-green";
public string Description => "Convert Legacy Media to mediaPicker3";
public MigrationOptions Options => new()
{
Group = "Convert",
Source = "uSync/v9",
Target = $"{uSyncMigrations.MigrationFolder}/mediapickers-to-mp3",
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)},
//{ UmbConstants.PropertyEditors.Aliases.RadioButtonList, nameof(Lovell.Web.Extensions.Migrations.Migrators.SMRadioButtonListMigrator) }
}
};
}
and those custom migrators just slight tweaks on the MediaPickerMigrator… like
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Umbraco.Cms.Core.PropertyEditors.ValueConverters;
using uSync.Migrations.Core.Context;
using uSync.Migrations.Core.Migrators;
using uSync.Migrations.Core.Migrators.Models;
using uSync.Migrations.Migrators.Core;
using UmbConstants = Umbraco.Cms.Core.Constants;
namespace uSyncMigrationSite.Extensions.Migrators
{
[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)
{
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)
try
{
var mp3 = JsonConvert.DeserializeObject<IEnumerable<MediaWithCropsDto>>(contentProperty.Value);
return contentProperty.Value;
}
catch
{
//if (contentProperty.Value.Contains("mediaKey"))
//{
// return contentProperty.Value;
//}
//otherwsie try and convert
var x = base.GetContentValue(contentProperty, context);
return x;
}
}
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
private sealed class MediaWithCropsDto
{
public Guid Key { get; set; }
public Guid MediaKey { get; set; }
public IEnumerable<ImageCropperValue.ImageCropperCrop>? Crops { get; set; }
public ImageCropperValue.ImageCropperFocalPoint? FocalPoint { get; set; }
}
}
}