forked from Jumoo/uSyncMigrations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyMigrationComposer.cs
56 lines (48 loc) · 1.98 KB
/
MyMigrationComposer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using uSync.Core;
using uSync.Migrations.Composing;
using uSync.Migrations.Migrators;
using uSync.Migrations.Notifications;
namespace MyMigrations;
/// <summary>
/// this is an example of how you might extend, and replace
/// core migrations for certain types (e.g the grid)
/// </summary>
/// <remarks>
/// by default the core will convert what it can, but if you
/// want to do something special, you can implement your
/// own ISyncPropertyMigrator and remove the core ones.
/// </remarks>
/// **********************************************************
/// NOTE: This project is not referenced in the Sample site
/// so this code isn't going to actually fire.
/// **********************************************************
[ComposeAfter(typeof(SyncMigrationsComposer))]
public class MySyncMigrationComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
// if we have a custom migration for the grid, we should
// remove the existing one.
// builder.SyncPropertyMigrators().Replace<GridMigrator, GridToBlockListMigrator>();
// our migration will be discovered, if it implements ISyncItemMigrator
// you can also intercept with notifications
builder.AddNotificationHandler<SyncMigratedNotification<Content>, MySyncMigratedNotificationHandler>();
}
}
/// <summary>
/// the migrated handler is fired pre save to disk, so
/// if you want to do extra work on the xml you could do it here.
/// </summary>
public class MySyncMigratedNotificationHandler : INotificationHandler<SyncMigratedNotification<Content>>
{
public void Handle(SyncMigratedNotification<Content> notification)
{
// you can also use the usync xml helpers, to quickly get things like the alias or the key.
var alias = notification.Xml.GetAlias();
var key = notification.Xml.GetKey();
}
}