From 4cbd3c4b5a117329968fedc373b444d3cc7a13a0 Mon Sep 17 00:00:00 2001 From: Jendrik Weise Date: Sat, 4 Nov 2023 20:59:28 +0100 Subject: [PATCH] Also potentially update language and tags --- ...e_titles_from_existing_subtitle_filesFixture.cs | 5 ++++- ...98_parse_titles_from_existing_subtitle_files.cs | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core.Test/Datastore/Migration/198_parse_titles_from_existing_subtitle_filesFixture.cs b/src/NzbDrone.Core.Test/Datastore/Migration/198_parse_titles_from_existing_subtitle_filesFixture.cs index 5702cd7f8..332a2f165 100644 --- a/src/NzbDrone.Core.Test/Datastore/Migration/198_parse_titles_from_existing_subtitle_filesFixture.cs +++ b/src/NzbDrone.Core.Test/Datastore/Migration/198_parse_titles_from_existing_subtitle_filesFixture.cs @@ -53,7 +53,8 @@ namespace NzbDrone.Core.Test.Datastore.Migration Added = now, LastUpdated = now, Extension = Path.GetExtension(subtitlePath), - Language = 1 + Language = 10, + LanguageTags = new List { "sdh" }.ToJson() }); c.Insert.IntoTable("EpisodeFiles").Row(new @@ -75,6 +76,8 @@ namespace NzbDrone.Core.Test.Datastore.Migration files.First().Title.Should().Be(title); files.First().Copy.Should().Be(copy); + files.First().LanguageTags.Should().NotContain("sdh"); + files.First().Language.Should().NotBe(10); } } diff --git a/src/NzbDrone.Core/Datastore/Migration/198_parse_titles_from_existing_subtitle_files.cs b/src/NzbDrone.Core/Datastore/Migration/198_parse_titles_from_existing_subtitle_files.cs index 0b691fe6a..e7d2020c4 100644 --- a/src/NzbDrone.Core/Datastore/Migration/198_parse_titles_from_existing_subtitle_files.cs +++ b/src/NzbDrone.Core/Datastore/Migration/198_parse_titles_from_existing_subtitle_files.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; using System.Data; +using System.Text.Json; +using System.Text.Json.Serialization; using Dapper; using FluentMigrator; using NzbDrone.Core.Datastore.Migration.Framework; @@ -49,7 +51,17 @@ namespace NzbDrone.Core.Datastore.Migration } } - var updateSubtitleFilesSql = "UPDATE \"SubtitleFiles\" SET \"Title\" = @Title, \"Copy\" = @Copy, \"LastUpdated\" = CURRENT_TIMESTAMP WHERE \"Id\" = @Id"; + var serializerSettings = new JsonSerializerOptions + { + AllowTrailingCommas = true, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + PropertyNameCaseInsensitive = true, + DictionaryKeyPolicy = JsonNamingPolicy.CamelCase, + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + WriteIndented = true + }; + + var updateSubtitleFilesSql = "UPDATE \"SubtitleFiles\" SET \"Title\" = @Title, \"Copy\" = @Copy, \"Language\" = @Language, \"LanguageTags\" = @LanguageTags, \"LastUpdated\" = CURRENT_TIMESTAMP WHERE \"Id\" = @Id"; conn.Execute(updateSubtitleFilesSql, updates, transaction: tran); } }