Skip to content

Commit 3ab12e9

Browse files
authored
Migrations: Fixes migrations from 13 to 17. Media Folder without Collection & Last Synced Table not existing. (#20743)
* Creating and adding new migration. And fixing another small bug. * Adding XML Header and renaming to a more clearly defined name
1 parent f11b8ff commit 3ab12e9

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,6 @@ protected virtual void DefinePlan()
138138
To<V_17_0_0.MigrateSystemDatesToUtc>("{7208B20D-6BFC-472E-9374-85EEA817B27D}");
139139
To<V_17_0_0.AddDistributedJobLock>("{263075BF-F18A-480D-92B4-4947D2EAB772}");
140140
To<V_17_0_0.AddLastSyncedTable>("26179D88-58CE-4C92-B4A4-3CBA6E7188AC");
141+
To<V_17_0_0.EnsureDefaultMediaFolderHasDefaultCollection>("{8B2C830A-4FFB-4433-8337-8649B0BF52C8}");
141142
}
142143
}

src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPremigrationPlan.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,6 @@ protected virtual void DefinePlan()
8080
// When logging in, we save the user to the cache so these need to have run.
8181
To<V_17_0_0.AddCacheVersionDatabaseLock>("{1DC39DC7-A88A-4912-8E60-4FD36246E8D1}");
8282
To<V_17_0_0.AddRepositoryCacheVersionTable>("{A1B3F5D6-4C8B-4E7A-9F8C-1D2B3E4F5A6B}");
83+
To<V_17_0_0.AddLastSyncedTable>("{72894BCA-9FAD-4CC3-B0D0-D6CDA2FFA636}");
8384
}
8485
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Umbraco.Cms.Core.Models;
2+
using Umbraco.Cms.Core.Services;
3+
using Constants = Umbraco.Cms.Core.Constants;
4+
5+
namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_17_0_0;
6+
7+
/// <summary>
8+
/// Ensures that the Media Document Type called "Folder" gets a collection added to it.
9+
/// </summary>
10+
public class EnsureDefaultMediaFolderHasDefaultCollection : AsyncMigrationBase
11+
{
12+
private readonly IMediaTypeService _mediaTypeService;
13+
private readonly IDataTypeService _dataTypeService;
14+
15+
public EnsureDefaultMediaFolderHasDefaultCollection(
16+
IMigrationContext context,
17+
IMediaTypeService mediaTypeService,
18+
IDataTypeService dataTypeService)
19+
: base(context)
20+
{
21+
_mediaTypeService = mediaTypeService;
22+
_dataTypeService = dataTypeService;
23+
}
24+
25+
protected override async Task MigrateAsync()
26+
{
27+
IMediaType? folderMediaType = _mediaTypeService
28+
.Get(Guid.Parse("f38bd2d7-65d0-48e6-95dc-87ce06ec2d3d")); // Folder media type default key.
29+
30+
if (folderMediaType is null || folderMediaType.ListView is not null)
31+
{
32+
return;
33+
}
34+
35+
IDataType? dataType = await _dataTypeService.GetAsync(Guid.Parse("3a0156c4-3b8c-4803-bdc1-6871faa83fff")); // Media Collection default key.
36+
37+
if (dataType is null)
38+
{
39+
return;
40+
}
41+
42+
folderMediaType.ListView = dataType.Key;
43+
await _mediaTypeService.UpdateAsync(folderMediaType, Constants.Security.SuperUserKey);
44+
}
45+
}

0 commit comments

Comments
 (0)