Skip to content

Commit

Permalink
experimental changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrch committed Nov 26, 2024
1 parent 695eb6d commit 3f7dd0d
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Migration.Tool.Common/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public record MigratePageTypesCommand : IRequest<CommandResult>, ICommand

public record MigratePagesCommand : IRequest<CommandResult>, 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";
Expand Down
4 changes: 2 additions & 2 deletions Migration.Tool.Common/Services/CommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public List<ICommand> Parse(Queue<string> args, ref bool bypassDependencyCheck,
commands.Add(new MigrateCustomTablesCommand());
}
}

return commands;
return commands.OrderBy(c => c.Rank).ToList();
}

private void PrintCommandDescriptions()
Expand Down
103 changes: 103 additions & 0 deletions Migration.Tool.Tests/MediaHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, HashSet<string>>
// {
// {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<int, HashSet<string>>
{
{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);
}
}
}

0 comments on commit 3f7dd0d

Please sign in to comment.