Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,7 @@ protected virtual void DefinePlan()
To<V_14_0_0.DeleteMacroTables>("{0D82C836-96DD-480D-A924-7964E458BD34}");
To<V_14_0_0.MoveDocumentBlueprintsToFolders>("{1A0FBC8A-6FC6-456C-805C-B94816B2E570}");
To<V_14_0_0.MigrateTours>("{302DE171-6D83-4B6B-B3C0-AC8808A16CA1}");
To<V_14_0_0.MigrateUserGroup2PermissionPermissionColumnType>("{8184E61D-ECBA-4AAA-B61B-D7A82EB82EB7}");
To<V_14_0_0.MigrateNotificationCharsToStrings>("{E261BF01-2C7F-4544-BAE7-49D545B21D68}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class MigrateCharPermissionsToStrings : MigrationBase
{
private readonly IIdKeyMap _idKeyMap;

private static Dictionary<char, IEnumerable<string>> _charToStringPermissionDictionary =
internal static Dictionary<char, IEnumerable<string>> CharToStringPermissionDictionary { get; } =
new()
{
['I'] = new []{ActionAssignDomain.ActionLetter},
Expand Down Expand Up @@ -110,5 +110,5 @@ protected override void Migrate()
Delete.Table(Constants.DatabaseSchema.Tables.UserGroup2Node).Do();
}

private IEnumerable<string> ReplacePermissionValue(char oldPermission) => _charToStringPermissionDictionary.TryGetValue(oldPermission, out IEnumerable<string>? newPermission) ? newPermission : oldPermission.ToString().Yield();
private IEnumerable<string> ReplacePermissionValue(char oldPermission) => CharToStringPermissionDictionary.TryGetValue(oldPermission, out IEnumerable<string>? newPermission) ? newPermission : oldPermission.ToString().Yield();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using NPoco;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Actions;
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
using Umbraco.Extensions;

namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_14_0_0;

[Obsolete("Remove in Umbraco 18.")]
public class MigrateNotificationCharsToStrings : MigrationBase
{
public MigrateNotificationCharsToStrings(IMigrationContext context) : base(context)
{
}

protected override void Migrate()
{
List<LegacyUser2NodeNotifyDto>? legacyNotifyDtos = Database.Fetch<LegacyUser2NodeNotifyDto>();
Delete.Table(Constants.DatabaseSchema.Tables.User2NodeNotify).Do();

Create.Table<User2NodeNotifyDto>().Do();
var notifyDtos = legacyNotifyDtos.Select(ReplaceAction).ToList();
Database.InsertBulk(notifyDtos);
}

private User2NodeNotifyDto ReplaceAction(LegacyUser2NodeNotifyDto dto)
{
// Action is non-nullable
dto.Action = MigrateCharPermissionsToStrings.CharToStringPermissionDictionary.TryGetValue(dto.Action!.ToCharArray().First(), out var action) ? string.Join(string.Empty, action) : dto.Action;

return new User2NodeNotifyDto
{
UserId = dto.UserId,
NodeId = dto.NodeId,
Action = dto.Action
};
}


[TableName(Constants.DatabaseSchema.Tables.User2NodeNotify)]
[PrimaryKey("userId", AutoIncrement = false)]
[ExplicitColumns]
private class LegacyUser2NodeNotifyDto
{
[Column("userId")]
[PrimaryKeyColumn(AutoIncrement = false, Name = "PK_umbracoUser2NodeNotify", OnColumns = "userId, nodeId, action")]
[ForeignKey(typeof(UserDto))]
public int UserId { get; set; }

[Column("nodeId")]
[ForeignKey(typeof(NodeDto))]
public int NodeId { get; set; }
[Column("action")]
[SpecialDbType(SpecialDbTypes.NCHAR)]
[Length(1)]

public string? Action { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NPoco;
using Umbraco.Cms.Core;
using Umbraco.Cms.Infrastructure.Persistence.Dtos;

namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_14_0_0;

[Obsolete("Remove in Umbraco 18.")]
public class MigrateUserGroup2PermissionPermissionColumnType : MigrationBase
{
public MigrateUserGroup2PermissionPermissionColumnType(IMigrationContext context) : base(context)
{
}

protected override void Migrate()
{
// We don't need to update the column for SQLite since it just uses TEXT.
if (DatabaseType == DatabaseType.SQLite)
{
return;
}

// The action column is part of the primary key, so we must drop the constraint before we can alter the column.
AlterColumn<UserGroup2PermissionDto>(Constants.DatabaseSchema.Tables.UserGroup2Permission, "permission");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ internal class User2NodeNotifyDto
public int NodeId { get; set; }

[Column("action")]
[SpecialDbType(SpecialDbTypes.NCHAR)]
[Length(1)]
[Length(255)]
public string? Action { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class UserGroup2PermissionDto
public Guid UserGroupKey { get; set; }

[Column("permission")]
[SpecialDbType(SpecialDbTypes.NVARCHARMAX)]
[Length(255)]
public required string Permission { get; set; }
}