Skip to content

Commit 48f67d1

Browse files
committed
Finished article with examples
1 parent f811991 commit 48f67d1

File tree

1 file changed

+83
-3
lines changed

1 file changed

+83
-3
lines changed
Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,88 @@
1+
## Introduction
12
V17 introduces the single block property editor. It's purpose is to replace the "single mode" option that exists in the blocklist property editor. This is part off the more general effort to ensure type consistency within core propertyeditors.
23

4+
## Included migration
5+
V17 ships with a migration to
6+
- update all block list data types that have been properly configured in "single" mode.
7+
- update all (nested) property data that uses this data type.
38

4-
### Optional migration
9+
We will not be enabling this migration until at least V18
510

6-
### Extending the migration
7-
If you have a non core propertyEditor that allows nesting content within it and stores that content within it's own value, then you will need to extend the migration. To do this you will need create and register a class that implements `ITypedSingleBlockListProcessor`
11+
## Pre running the migration
12+
You can run the migration at any time by using your own migration plan as shown in the example below. If you run this migration yourself and we later enable it trough the default umbraco migration, then our run should not update any data as it only changes data that is in the old format.
813

14+
```csharp
15+
using Umbraco.Cms.Core;
16+
using Umbraco.Cms.Core.Composing;
17+
using Umbraco.Cms.Core.Events;
18+
using Umbraco.Cms.Core.Migrations;
19+
using Umbraco.Cms.Core.Notifications;
20+
using Umbraco.Cms.Core.Scoping;
21+
using Umbraco.Cms.Core.Services;
22+
using Umbraco.Cms.Infrastructure.Migrations;
23+
using Umbraco.Cms.Infrastructure.Migrations.Upgrade;
24+
using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_18_0_0;
25+
26+
namespace SingleBlockMigrationRunner;
27+
28+
public class TestMigrationComposer : IComposer
29+
{
30+
public void Compose(IUmbracoBuilder builder)
31+
{
32+
builder.AddNotificationAsyncHandler<UmbracoApplicationStartingNotification, RunTestMigration>();
33+
}
34+
}
35+
36+
public class RunTestMigration : INotificationAsyncHandler<UmbracoApplicationStartingNotification>
37+
{
38+
private readonly IMigrationPlanExecutor _migrationPlanExecutor;
39+
private readonly ICoreScopeProvider _coreScopeProvider;
40+
private readonly IKeyValueService _keyValueService;
41+
private readonly IRuntimeState _runtimeState;
42+
43+
public RunTestMigration(
44+
ICoreScopeProvider coreScopeProvider,
45+
IMigrationPlanExecutor migrationPlanExecutor,
46+
IKeyValueService keyValueService,
47+
IRuntimeState runtimeState)
48+
{
49+
_migrationPlanExecutor = migrationPlanExecutor;
50+
_coreScopeProvider = coreScopeProvider;
51+
_keyValueService = keyValueService;
52+
_runtimeState = runtimeState;
53+
}
54+
55+
public async Task HandleAsync(UmbracoApplicationStartingNotification notification, CancellationToken cancellationToken)
56+
{
57+
if (_runtimeState.Level < RuntimeLevel.Run)
58+
{
59+
return;
60+
}
61+
62+
// One-off migration plan
63+
var migrationPlan = new MigrationPlan("Single Block Migration");
64+
65+
// define the step
66+
migrationPlan.From(string.Empty)
67+
.To<MigrateSingleBlockList>("test-run-singleBlock-migration");
68+
69+
// Go and upgrade our site (Will check if it needs to do the work or not)
70+
// Based on the current/latest step
71+
var upgrader = new Upgrader(migrationPlan);
72+
await upgrader.ExecuteAsync(
73+
_migrationPlanExecutor,
74+
_coreScopeProvider,
75+
_keyValueService);
76+
}
77+
}
78+
79+
```
80+
81+
## Extending the migration
82+
If you have a non core propertyEditor that allows nesting content within it and stores that content within it's own value, then you will need to extend the migration. To do this you will need create and register a class that implements `ITypedSingleBlockListProcessor` and register it. You can see how we register the build in types at `Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_18_0_0.SingleBlockList.MigrateSingleBlockListComposer`. The interface needs the following properties and methods:
83+
- `IEnumerable<string> PropertyEditorAliases`: The alias of the property editor as defined on its DataEditor attribute. Since a processor can support multiple editors if they use the same model, it takes an IEnumerable over a single string. These alias are used to limit the amount of data fetched from the database.
84+
- `Type PropertyEditorValueType`: The type of the value the propertyEditor would return when `valueEditor.ToEditor()` would be called.
85+
- `Func<object?, Func<object?, bool>, Func<BlockListValue,object>, bool> Process` The function to run when the main processor detects a value that matches your processor. The function needs to suport the following parameters
86+
- `object?`: The value being passed in from the outer caller or the top level processor
87+
- `Func<object?, bool>` The function the processor needs to call when it detects nested content. This is passed in from the top level processor.
88+
- `Func<BlockListValue, object>` The function that needs to be called when the outer layer of the current value is a blockList that needs to be converted to singleblock. This should only ever be called from the core processors. It is passed around to make recursion just the little bit easier.

0 commit comments

Comments
 (0)