diff options
| author | Patrick Barron <barronpm@gmail.com> | 2020-06-01 20:12:34 -0400 |
|---|---|---|
| committer | Patrick Barron <barronpm@gmail.com> | 2020-06-01 20:12:34 -0400 |
| commit | b0281b79fd8c6e103fa7a1cb183028541d280ed4 (patch) | |
| tree | 4fc0f99a130f1dfb27836c31bc59fdecd9b25b3d /Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs | |
| parent | d38adb95a727203b0d0dcee344f03b374b5d2b8f (diff) | |
Fix a bug where very old Emby databases didn't use proper Guid's
Diffstat (limited to 'Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs')
| -rw-r--r-- | Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs b/Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs index b3cc29708..270c36f85 100644 --- a/Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs +++ b/Jellyfin.Server/Migrations/Routines/MigrateActivityLogDb.cs @@ -64,6 +64,7 @@ namespace Jellyfin.Server.Migrations.Routines ConnectionFlags.ReadOnly, null)) { + using var userDbConnection = SQLite3.Open(Path.Combine(dataPath, "users.db"), ConnectionFlags.ReadOnly, null); _logger.LogWarning("Migrating the activity database may take a while, do not stop Jellyfin."); using var dbContext = _provider.CreateContext(); @@ -76,17 +77,38 @@ namespace Jellyfin.Server.Migrations.Routines dbContext.Database.ExecuteSqlRaw("UPDATE sqlite_sequence SET seq = 0 WHERE name = 'ActivityLog';"); dbContext.SaveChanges(); - var newEntries = queryResult.Select(entry => + var newEntries = new List<ActivityLog>(); + + foreach (var entry in queryResult) { if (!logLevelDictionary.TryGetValue(entry[8].ToString(), out var severity)) { severity = LogLevel.Trace; } + Guid guid; + if (entry[6].SQLiteType == SQLiteType.Null) + { + guid = Guid.Empty; + } + else if (!Guid.TryParse(entry[6].ToString(), out guid)) + { + // This is not a valid Guid, see if it is an internal ID from an old Emby schema + var userEntry = userDbConnection + .Query($"SELECT guid FROM LocalUsersv2 WHERE Id = {entry[6].ToString()}") + .FirstOrDefault(); + + if (userEntry.Count == 0 || !Guid.TryParse(userEntry[0].ToString(), out guid)) + { + // Give up, just use Guid.Empty + guid = Guid.Empty; + } + } + var newEntry = new ActivityLog( entry[1].ToString(), entry[4].ToString(), - entry[6].SQLiteType == SQLiteType.Null ? Guid.Empty : Guid.Parse(entry[6].ToString())) + guid) { DateCreated = entry[7].ReadDateTime(), LogSeverity = severity @@ -107,8 +129,8 @@ namespace Jellyfin.Server.Migrations.Routines newEntry.ItemId = entry[5].ToString(); } - return newEntry; - }); + newEntries.Add(newEntry); + } dbContext.ActivityLogs.AddRange(newEntries); dbContext.SaveChanges(); |
