From 3ab12e9b59e6a6f2c597d479f41b0c9a3e796544 Mon Sep 17 00:00:00 2001 From: Nicklas Kramer Date: Thu, 6 Nov 2025 10:40:29 +0100 Subject: [PATCH] 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 --- .../Migrations/Upgrade/UmbracoPlan.cs | 1 + .../Upgrade/UmbracoPremigrationPlan.cs | 1 + ...eDefaultMediaFolderHasDefaultCollection.cs | 45 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 src/Umbraco.Infrastructure/Migrations/Upgrade/V_17_0_0/EnsureDefaultMediaFolderHasDefaultCollection.cs diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs index 9a3f5dc8eb..7a781b889a 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs @@ -138,5 +138,6 @@ public class UmbracoPlan : MigrationPlan To("{7208B20D-6BFC-472E-9374-85EEA817B27D}"); To("{263075BF-F18A-480D-92B4-4947D2EAB772}"); To("26179D88-58CE-4C92-B4A4-3CBA6E7188AC"); + To("{8B2C830A-4FFB-4433-8337-8649B0BF52C8}"); } } diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPremigrationPlan.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPremigrationPlan.cs index f9334ae68d..85c141baa3 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPremigrationPlan.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPremigrationPlan.cs @@ -80,5 +80,6 @@ public class UmbracoPremigrationPlan : MigrationPlan // When logging in, we save the user to the cache so these need to have run. To("{1DC39DC7-A88A-4912-8E60-4FD36246E8D1}"); To("{A1B3F5D6-4C8B-4E7A-9F8C-1D2B3E4F5A6B}"); + To("{72894BCA-9FAD-4CC3-B0D0-D6CDA2FFA636}"); } } diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_17_0_0/EnsureDefaultMediaFolderHasDefaultCollection.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_17_0_0/EnsureDefaultMediaFolderHasDefaultCollection.cs new file mode 100644 index 0000000000..ca7db02e92 --- /dev/null +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_17_0_0/EnsureDefaultMediaFolderHasDefaultCollection.cs @@ -0,0 +1,45 @@ +using Umbraco.Cms.Core.Models; +using Umbraco.Cms.Core.Services; +using Constants = Umbraco.Cms.Core.Constants; + +namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_17_0_0; + +/// +/// Ensures that the Media Document Type called "Folder" gets a collection added to it. +/// +public class EnsureDefaultMediaFolderHasDefaultCollection : AsyncMigrationBase +{ + private readonly IMediaTypeService _mediaTypeService; + private readonly IDataTypeService _dataTypeService; + + public EnsureDefaultMediaFolderHasDefaultCollection( + IMigrationContext context, + IMediaTypeService mediaTypeService, + IDataTypeService dataTypeService) + : base(context) + { + _mediaTypeService = mediaTypeService; + _dataTypeService = dataTypeService; + } + + protected override async Task MigrateAsync() + { + IMediaType? folderMediaType = _mediaTypeService + .Get(Guid.Parse("f38bd2d7-65d0-48e6-95dc-87ce06ec2d3d")); // Folder media type default key. + + if (folderMediaType is null || folderMediaType.ListView is not null) + { + return; + } + + IDataType? dataType = await _dataTypeService.GetAsync(Guid.Parse("3a0156c4-3b8c-4803-bdc1-6871faa83fff")); // Media Collection default key. + + if (dataType is null) + { + return; + } + + folderMediaType.ListView = dataType.Key; + await _mediaTypeService.UpdateAsync(folderMediaType, Constants.Security.SuperUserKey); + } +}