From 3f7dd0dc1c25acd319d14a0068dd03ee60b101da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Krch?= Date: Wed, 27 Nov 2024 00:34:40 +0100 Subject: [PATCH] experimental changes --- Migration.Tool.Common/Commands.cs | 2 +- .../Services/CommandParser.cs | 4 +- Migration.Tool.Tests/MediaHelperTest.cs | 103 ++++++++++++++++++ 3 files changed, 106 insertions(+), 3 deletions(-) diff --git a/Migration.Tool.Common/Commands.cs b/Migration.Tool.Common/Commands.cs index 1393020e..801ab8a1 100644 --- a/Migration.Tool.Common/Commands.cs +++ b/Migration.Tool.Common/Commands.cs @@ -86,7 +86,7 @@ public record MigratePageTypesCommand : IRequest, ICommand public record MigratePagesCommand : IRequest, ICommand { - public static readonly int Rank = 1 + MigrateSitesCommand.Rank + MigrateUsersCommand.Rank + MigratePageTypesCommand.Rank; + public static readonly int Rank = 1 + MigrateSitesCommand.Rank + MigrateUsersCommand.Rank + MigratePageTypesCommand.Rank + MigrateMediaLibrariesCommand.Rank; public static string Moniker => "pages"; public static string MonikerFriendly => "Pages"; diff --git a/Migration.Tool.Common/Services/CommandParser.cs b/Migration.Tool.Common/Services/CommandParser.cs index f5009468..dd123873 100644 --- a/Migration.Tool.Common/Services/CommandParser.cs +++ b/Migration.Tool.Common/Services/CommandParser.cs @@ -119,8 +119,8 @@ public List Parse(Queue args, ref bool bypassDependencyCheck, commands.Add(new MigrateCustomTablesCommand()); } } - - return commands; + + return commands.OrderBy(c => c.Rank).ToList(); } private void PrintCommandDescriptions() diff --git a/Migration.Tool.Tests/MediaHelperTest.cs b/Migration.Tool.Tests/MediaHelperTest.cs index a57718e4..1d1c4a62 100644 --- a/Migration.Tool.Tests/MediaHelperTest.cs +++ b/Migration.Tool.Tests/MediaHelperTest.cs @@ -293,5 +293,108 @@ public void ParseMediaLinkDirectPath() Assert.Equal(3, a.LinkSiteId); Assert.Equal("MediaLibraryS3", a.LibraryDir); } + + { + var a = mediaLinkService.MatchMediaLink("http://localhost:5003/Site3/media/MediaLibraryS3/some sub dir/myfile.jpg", 3); + Assert.True(a.Success); + Assert.Equal("/MediaLibraryS3/some sub dir/myfile.jpg", a.Path); + Assert.Null(a.MediaGuid); + Assert.Equal(MediaKind.MediaFile, a.MediaKind); + Assert.Equal(MediaLinkKind.DirectMediaPath, a.LinkKind); + Assert.Equal(3, a.LinkSiteId); + Assert.Equal("MediaLibraryS3/some sub dir", a.LibraryDir); + } + } + + // [Fact] + // public void ParseMediaLinkDirectPath_SpacesInPath() + // { + // var mediaLinkService = new MediaLinkService( + // [ + // (1, "Site1", "http://localhost:5001"), // site with custom global dir + // (2, "Site2", "http://localhost:5002/SiteSubPath"), // site with custom global dir & subpath + // (3, "Site3", "http://localhost:5003"), // site without custom global media library dir + // (4, "Site4", "http://localhost:5004"), // site with custom global media library dir & without media sites folder + // // add site with live site url "localhost" - that was valid in K11 + // ], + // [ + // // (null, null), not set globally + // (1, "Site1MediaFolder"), + // (2, "Site2MediaFolder"), + // // (3, null) not set for site 3 + // (4, "Site4MediaFolder"), + // ], + // [ + // // (null, null) not set globally + // (1, "False"), + // (2, "False"), + // (3, "True"), + // (4, "True"), + // ], + // new Dictionary> + // { + // {1, new (["MediaLibraryS1"],StringComparer.InvariantCultureIgnoreCase)}, + // {2, new (["MediaLibraryS2"],StringComparer.InvariantCultureIgnoreCase)}, + // {3, new (["MediaLibraryS3"],StringComparer.InvariantCultureIgnoreCase)}, + // {4, new (["MediaLibraryS4"],StringComparer.InvariantCultureIgnoreCase)} + // } + // ); + // + // { + // var a = mediaLinkService.MatchMediaLink("http://localhost:5003/Site3/media/MediaLibraryS3/some sub dir/myfile.jpg", 3); + // Assert.True(a.Success); + // Assert.Equal("/MediaLibraryS3/some sub dir/myfile.jpg", a.Path); + // Assert.Null(a.MediaGuid); + // Assert.Equal(MediaKind.MediaFile, a.MediaKind); + // Assert.Equal(MediaLinkKind.DirectMediaPath, a.LinkKind); + // Assert.Equal(3, a.LinkSiteId); + // Assert.Equal("MediaLibraryS3/some sub dir", a.LibraryDir); + // } + // } + + [Fact] + public void ParseMediaLinkDirectPath_SpacesInPath_CorrectlyEscaped() + { + var mediaLinkService = new MediaLinkService( + [ + (1, "Site1", "http://localhost:5001"), // site with custom global dir + (2, "Site2", "http://localhost:5002/SiteSubPath"), // site with custom global dir & subpath + (3, "Site3", "http://localhost:5003"), // site without custom global media library dir + (4, "Site4", "http://localhost:5004"), // site with custom global media library dir & without media sites folder + // add site with live site url "localhost" - that was valid in K11 + ], + [ + // (null, null), not set globally + (1, "Site1MediaFolder"), + (2, "Site2MediaFolder"), + // (3, null) not set for site 3 + (4, "Site4MediaFolder"), + ], + [ + // (null, null) not set globally + (1, "False"), + (2, "False"), + (3, "True"), + (4, "True"), + ], + new Dictionary> + { + {1, new (["MediaLibraryS1"],StringComparer.InvariantCultureIgnoreCase)}, + {2, new (["MediaLibraryS2"],StringComparer.InvariantCultureIgnoreCase)}, + {3, new (["MediaLibraryS3"],StringComparer.InvariantCultureIgnoreCase)}, + {4, new (["MediaLibraryS4"],StringComparer.InvariantCultureIgnoreCase)} + } + ); + + { + var a = mediaLinkService.MatchMediaLink("http://localhost:5003/Site3/media/MediaLibraryS3/some%20sub%20dir/myfile.jpg", 3); + Assert.True(a.Success); + Assert.Equal("/MediaLibraryS3/some sub dir/myfile.jpg", a.Path); + Assert.Null(a.MediaGuid); + Assert.Equal(MediaKind.MediaFile, a.MediaKind); + Assert.Equal(MediaLinkKind.DirectMediaPath, a.LinkKind); + Assert.Equal(3, a.LinkSiteId); + Assert.Equal("MediaLibraryS3", a.LibraryDir); + } } }