-
Notifications
You must be signed in to change notification settings - Fork 14
/
MigrationComponent.cs
54 lines (48 loc) · 1.86 KB
/
MigrationComponent.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
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Migrations;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Infrastructure.Migrations;
using Umbraco.Cms.Infrastructure.Migrations.Upgrade;
namespace DoStuff.Core.Migrations
{
/// <summary>
/// Register an event handler, so we can do stuff when the site starts.
/// </summary>
public class MigrationComponentComposer : IUserComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.AddNotificationHandler<UmbracoApplicationStartingNotification, MigrationAppStartingHandler>();
}
}
public class MigrationAppStartingHandler : INotificationHandler<UmbracoApplicationStartingNotification>
{
private readonly IScopeProvider _scopeProvider;
private readonly IKeyValueService _keyValueService;
private readonly IMigrationPlanExecutor _migrationPlanExecutor;
public MigrationAppStartingHandler(
IScopeProvider scopeProvider,
IKeyValueService keyValueService,
IMigrationPlanExecutor migrationPlanExecutor)
{
_scopeProvider = scopeProvider;
_keyValueService = keyValueService;
_migrationPlanExecutor = migrationPlanExecutor;
}
public void Handle(UmbracoApplicationStartingNotification notification)
{
if (notification.RuntimeLevel >= Umbraco.Cms.Core.RuntimeLevel.Run)
{
// register and run our migration plan
var upgrader = new Upgrader(new DoStuffMigrationPlan());
upgrader.Execute(_migrationPlanExecutor, _scopeProvider, _keyValueService);
}
}
}
}