aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Migrations/Routines
diff options
context:
space:
mode:
Diffstat (limited to 'Jellyfin.Server/Migrations/Routines')
-rw-r--r--Jellyfin.Server/Migrations/Routines/FixPlaylistOwner.cs76
-rw-r--r--Jellyfin.Server/Migrations/Routines/MigrateDisplayPreferencesDb.cs4
-rw-r--r--Jellyfin.Server/Migrations/Routines/MigrateRatingLevels.cs103
-rw-r--r--Jellyfin.Server/Migrations/Routines/MigrateUserDb.cs1
4 files changed, 180 insertions, 4 deletions
diff --git a/Jellyfin.Server/Migrations/Routines/FixPlaylistOwner.cs b/Jellyfin.Server/Migrations/Routines/FixPlaylistOwner.cs
new file mode 100644
index 000000000..cf3182003
--- /dev/null
+++ b/Jellyfin.Server/Migrations/Routines/FixPlaylistOwner.cs
@@ -0,0 +1,76 @@
+using System;
+using System.Linq;
+using System.Threading;
+
+using Jellyfin.Data.Enums;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.Playlists;
+using Microsoft.Extensions.Logging;
+
+namespace Jellyfin.Server.Migrations.Routines;
+
+/// <summary>
+/// Properly set playlist owner.
+/// </summary>
+internal class FixPlaylistOwner : IMigrationRoutine
+{
+ private readonly ILogger<RemoveDuplicateExtras> _logger;
+ private readonly ILibraryManager _libraryManager;
+ private readonly IPlaylistManager _playlistManager;
+
+ public FixPlaylistOwner(
+ ILogger<RemoveDuplicateExtras> logger,
+ ILibraryManager libraryManager,
+ IPlaylistManager playlistManager)
+ {
+ _logger = logger;
+ _libraryManager = libraryManager;
+ _playlistManager = playlistManager;
+ }
+
+ /// <inheritdoc/>
+ public Guid Id => Guid.Parse("{615DFA9E-2497-4DBB-A472-61938B752C5B}");
+
+ /// <inheritdoc/>
+ public string Name => "FixPlaylistOwner";
+
+ /// <inheritdoc/>
+ public bool PerformOnNewInstall => false;
+
+ /// <inheritdoc/>
+ public void Perform()
+ {
+ var playlists = _libraryManager.GetItemList(new InternalItemsQuery
+ {
+ IncludeItemTypes = new[] { BaseItemKind.Playlist }
+ })
+ .Cast<Playlist>()
+ .Where(x => x.OwnerUserId.Equals(Guid.Empty))
+ .ToArray();
+
+ if (playlists.Length > 0)
+ {
+ foreach (var playlist in playlists)
+ {
+ var shares = playlist.Shares;
+ if (shares.Length > 0)
+ {
+ var firstEditShare = shares.First(x => x.CanEdit);
+ if (firstEditShare is not null && Guid.TryParse(firstEditShare.UserId, out var guid))
+ {
+ playlist.OwnerUserId = guid;
+ playlist.Shares = shares.Where(x => x != firstEditShare).ToArray();
+ playlist.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).GetAwaiter().GetResult();
+ _playlistManager.SavePlaylistFile(playlist);
+ }
+ }
+ else
+ {
+ playlist.OpenAccess = true;
+ playlist.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).GetAwaiter().GetResult();
+ }
+ }
+ }
+ }
+}
diff --git a/Jellyfin.Server/Migrations/Routines/MigrateDisplayPreferencesDb.cs b/Jellyfin.Server/Migrations/Routines/MigrateDisplayPreferencesDb.cs
index 7c4ffdbc0..8fe2b087d 100644
--- a/Jellyfin.Server/Migrations/Routines/MigrateDisplayPreferencesDb.cs
+++ b/Jellyfin.Server/Migrations/Routines/MigrateDisplayPreferencesDb.cs
@@ -133,9 +133,7 @@ namespace Jellyfin.Server.Migrations.Routines
SkipBackwardLength = dto.CustomPrefs.TryGetValue("skipBackLength", out length) && int.TryParse(length, out var skipBackwardLength)
? skipBackwardLength
: 10000,
- EnableNextVideoInfoOverlay = dto.CustomPrefs.TryGetValue("enableNextVideoInfoOverlay", out var enabled) && !string.IsNullOrEmpty(enabled)
- ? bool.Parse(enabled)
- : true,
+ EnableNextVideoInfoOverlay = !dto.CustomPrefs.TryGetValue("enableNextVideoInfoOverlay", out var enabled) || string.IsNullOrEmpty(enabled) || bool.Parse(enabled),
DashboardTheme = dto.CustomPrefs.TryGetValue("dashboardtheme", out var theme) ? theme : string.Empty,
TvHome = dto.CustomPrefs.TryGetValue("tvhome", out var home) ? home : string.Empty
};
diff --git a/Jellyfin.Server/Migrations/Routines/MigrateRatingLevels.cs b/Jellyfin.Server/Migrations/Routines/MigrateRatingLevels.cs
new file mode 100644
index 000000000..9dee520a5
--- /dev/null
+++ b/Jellyfin.Server/Migrations/Routines/MigrateRatingLevels.cs
@@ -0,0 +1,103 @@
+using System;
+using System.Globalization;
+using System.IO;
+
+using Emby.Server.Implementations.Data;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Persistence;
+using MediaBrowser.Model.Globalization;
+using Microsoft.Extensions.Logging;
+using SQLitePCL.pretty;
+
+namespace Jellyfin.Server.Migrations.Routines
+{
+ /// <summary>
+ /// Migrate rating levels to new rating level system.
+ /// </summary>
+ internal class MigrateRatingLevels : IMigrationRoutine
+ {
+ private const string DbFilename = "library.db";
+ private readonly ILogger<MigrateRatingLevels> _logger;
+ private readonly IServerApplicationPaths _applicationPaths;
+ private readonly ILocalizationManager _localizationManager;
+ private readonly IItemRepository _repository;
+
+ public MigrateRatingLevels(
+ IServerApplicationPaths applicationPaths,
+ ILoggerFactory loggerFactory,
+ ILocalizationManager localizationManager,
+ IItemRepository repository)
+ {
+ _applicationPaths = applicationPaths;
+ _localizationManager = localizationManager;
+ _repository = repository;
+ _logger = loggerFactory.CreateLogger<MigrateRatingLevels>();
+ }
+
+ /// <inheritdoc/>
+ public Guid Id => Guid.Parse("{67445D54-B895-4B24-9F4C-35CE0690EA07}");
+
+ /// <inheritdoc/>
+ public string Name => "MigrateRatingLevels";
+
+ /// <inheritdoc/>
+ public bool PerformOnNewInstall => false;
+
+ /// <inheritdoc/>
+ public void Perform()
+ {
+ var dbPath = Path.Combine(_applicationPaths.DataPath, DbFilename);
+
+ // Back up the database before modifying any entries
+ for (int i = 1; ; i++)
+ {
+ var bakPath = string.Format(CultureInfo.InvariantCulture, "{0}.bak{1}", dbPath, i);
+ if (!File.Exists(bakPath))
+ {
+ try
+ {
+ File.Copy(dbPath, bakPath);
+ _logger.LogInformation("Library database backed up to {BackupPath}", bakPath);
+ break;
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Cannot make a backup of {Library} at path {BackupPath}", DbFilename, bakPath);
+ throw;
+ }
+ }
+ }
+
+ // Migrate parental rating strings to new levels
+ _logger.LogInformation("Recalculating parental rating levels based on rating string.");
+ using (var connection = SQLite3.Open(
+ dbPath,
+ ConnectionFlags.ReadWrite,
+ null))
+ {
+ var queryResult = connection.Query("SELECT DISTINCT OfficialRating FROM TypedBaseItems");
+ foreach (var entry in queryResult)
+ {
+ var ratingString = entry[0].ToString();
+ if (string.IsNullOrEmpty(ratingString))
+ {
+ connection.Execute("UPDATE TypedBaseItems SET InheritedParentalRatingValue = NULL WHERE OfficialRating IS NULL OR OfficialRating='';");
+ }
+ else
+ {
+ var ratingValue = _localizationManager.GetRatingLevel(ratingString).ToString();
+ if (string.IsNullOrEmpty(ratingValue))
+ {
+ ratingValue = "NULL";
+ }
+
+ var statement = connection.PrepareStatement("UPDATE TypedBaseItems SET InheritedParentalRatingValue = @Value WHERE OfficialRating = @Rating;");
+ statement.TryBind("@Value", ratingValue);
+ statement.TryBind("@Rating", ratingString);
+ statement.ExecuteQuery();
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/Jellyfin.Server/Migrations/Routines/MigrateUserDb.cs b/Jellyfin.Server/Migrations/Routines/MigrateUserDb.cs
index 9bf1e6b80..0186500a1 100644
--- a/Jellyfin.Server/Migrations/Routines/MigrateUserDb.cs
+++ b/Jellyfin.Server/Migrations/Routines/MigrateUserDb.cs
@@ -127,7 +127,6 @@ namespace Jellyfin.Server.Migrations.Routines
RememberSubtitleSelections = config.RememberSubtitleSelections,
SubtitleLanguagePreference = config.SubtitleLanguagePreference,
Password = mockup.Password,
- EasyPassword = mockup.EasyPassword,
LastLoginDate = mockup.LastLoginDate,
LastActivityDate = mockup.LastActivityDate
};