Fix existing DisplayPreferences migration

This commit is contained in:
crobibero 2020-12-03 15:00:26 -07:00
parent 685c966468
commit e765184afa
2 changed files with 18 additions and 2 deletions

View File

@ -177,7 +177,7 @@ namespace Jellyfin.Api.Controllers
foreach (var key in displayPreferences.CustomPrefs.Keys.Where(key => key.StartsWith("landing-", StringComparison.OrdinalIgnoreCase))) foreach (var key in displayPreferences.CustomPrefs.Keys.Where(key => key.StartsWith("landing-", StringComparison.OrdinalIgnoreCase)))
{ {
if (Guid.TryParse(key.Substring("landing-".Length), out var preferenceId)) if (Guid.TryParse(key.AsSpan().Slice("landing-".Length), out var preferenceId))
{ {
var itemPreferences = _displayPreferencesManager.GetItemDisplayPreferences(existingDisplayPreferences.UserId, preferenceId, existingDisplayPreferences.Client); var itemPreferences = _displayPreferencesManager.GetItemDisplayPreferences(existingDisplayPreferences.UserId, preferenceId, existingDisplayPreferences.Client);
itemPreferences.ViewType = Enum.Parse<ViewType>(displayPreferences.ViewType); itemPreferences.ViewType = Enum.Parse<ViewType>(displayPreferences.ViewType);

View File

@ -105,6 +105,7 @@ namespace Jellyfin.Server.Migrations.Routines
var chromecastVersion = dto.CustomPrefs.TryGetValue("chromecastVersion", out var version) var chromecastVersion = dto.CustomPrefs.TryGetValue("chromecastVersion", out var version)
? chromecastDict[version] ? chromecastDict[version]
: ChromecastVersion.Stable; : ChromecastVersion.Stable;
dto.CustomPrefs.Remove("chromecastVersion");
var displayPreferences = new DisplayPreferences(dtoUserId, result[2].ToString()) var displayPreferences = new DisplayPreferences(dtoUserId, result[2].ToString())
{ {
@ -126,15 +127,24 @@ namespace Jellyfin.Server.Migrations.Routines
TvHome = dto.CustomPrefs.TryGetValue("tvhome", out var home) ? home : string.Empty TvHome = dto.CustomPrefs.TryGetValue("tvhome", out var home) ? home : string.Empty
}; };
dto.CustomPrefs.Remove("skipForwardLength");
dto.CustomPrefs.Remove("skipBackLength");
dto.CustomPrefs.Remove("enableNextVideoInfoOverlay");
dto.CustomPrefs.Remove("dashboardtheme");
dto.CustomPrefs.Remove("tvhome");
for (int i = 0; i < 7; i++) for (int i = 0; i < 7; i++)
{ {
dto.CustomPrefs.TryGetValue("homesection" + i, out var homeSection); var key = "homesection" + i;
dto.CustomPrefs.TryGetValue(key, out var homeSection);
displayPreferences.HomeSections.Add(new HomeSection displayPreferences.HomeSections.Add(new HomeSection
{ {
Order = i, Order = i,
Type = Enum.TryParse<HomeSectionType>(homeSection, true, out var type) ? type : defaults[i] Type = Enum.TryParse<HomeSectionType>(homeSection, true, out var type) ? type : defaults[i]
}); });
dto.CustomPrefs.Remove(key);
} }
var defaultLibraryPrefs = new ItemDisplayPreferences(displayPreferences.UserId, Guid.Empty, displayPreferences.Client) var defaultLibraryPrefs = new ItemDisplayPreferences(displayPreferences.UserId, Guid.Empty, displayPreferences.Client)
@ -167,9 +177,15 @@ namespace Jellyfin.Server.Migrations.Routines
libraryDisplayPreferences.ViewType = viewType; libraryDisplayPreferences.ViewType = viewType;
} }
dto.CustomPrefs.Remove(key);
dbContext.ItemDisplayPreferences.Add(libraryDisplayPreferences); dbContext.ItemDisplayPreferences.Add(libraryDisplayPreferences);
} }
foreach (var (key, value) in dto.CustomPrefs)
{
dbContext.Add(new CustomItemDisplayPreferences(displayPreferences.UserId, displayPreferences.Client, key, value));
}
dbContext.Add(displayPreferences); dbContext.Add(displayPreferences);
} }