diff --git a/src/NzbDrone.Core.Test/TvTests/SeriesTitleNormalizerFixture.cs b/src/NzbDrone.Core.Test/TvTests/SeriesTitleNormalizerFixture.cs index f64d73aec..afc334895 100644 --- a/src/NzbDrone.Core.Test/TvTests/SeriesTitleNormalizerFixture.cs +++ b/src/NzbDrone.Core.Test/TvTests/SeriesTitleNormalizerFixture.cs @@ -8,9 +8,6 @@ namespace NzbDrone.Core.Test.TvTests public class SeriesTitleNormalizerFixture { [TestCase("A to Z", 281588, "a to z")] - [TestCase("A.D. The Bible Continues", 289260, "ad bible continues")] - [TestCase("A.P. Bio", 328534, "ap bio")] - [TestCase("The A-Team", 77904, "ateam")] public void should_use_precomputed_title(string title, int tvdbId, string expected) { SeriesTitleNormalizer.Normalize(title, tvdbId).Should().Be(expected); @@ -23,6 +20,12 @@ namespace NzbDrone.Core.Test.TvTests [TestCase("The Good Wife", "good wife")] [TestCase("The Newsroom (2012)", "newsroom 2012")] [TestCase("Special Agent Oso", "special agent oso")] + [TestCase("A.N.T. Farm", "ant farm")] + [TestCase("A.I.C.O. -Incarnation-", "aico incarnation")] + [TestCase("A.D. The Bible Continues", "ad the bible continues")] + [TestCase("A.P. Bio", "ap bio")] + [TestCase("The A-Team", "ateam")] + [TestCase("And Just Like That", "and just like that")] public void should_normalize_title(string title, string expected) { SeriesTitleNormalizer.Normalize(title, 0).Should().Be(expected); diff --git a/src/NzbDrone.Core/Datastore/Migration/166_update_series_sort_title.cs b/src/NzbDrone.Core/Datastore/Migration/166_update_series_sort_title.cs new file mode 100644 index 000000000..0f72b980f --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/166_update_series_sort_title.cs @@ -0,0 +1,46 @@ +using System.Data; +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; +using NzbDrone.Core.Tv; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(166)] + public class update_series_sort_title : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Execute.WithConnection(UpdateSortTitles); + } + + private void UpdateSortTitles(IDbConnection conn, IDbTransaction tran) + { + using (IDbCommand getSeriesCmd = conn.CreateCommand()) + { + getSeriesCmd.Transaction = tran; + getSeriesCmd.CommandText = @"SELECT Id, TvdbId, Title FROM Series"; + using (IDataReader seriesReader = getSeriesCmd.ExecuteReader()) + { + while (seriesReader.Read()) + { + var id = seriesReader.GetInt32(0); + var tvdbId = seriesReader.GetInt32(1); + var title = seriesReader.GetString(2); + + var sortTitle = SeriesTitleNormalizer.Normalize(title, tvdbId); + + using (IDbCommand updateCmd = conn.CreateCommand()) + { + updateCmd.Transaction = tran; + updateCmd.CommandText = "UPDATE Series SET SortTitle = ? WHERE Id = ?"; + updateCmd.AddParameter(sortTitle); + updateCmd.AddParameter(id); + + updateCmd.ExecuteNonQuery(); + } + } + } + } + } + } +} diff --git a/src/NzbDrone.Core/Parser/Parser.cs b/src/NzbDrone.Core/Parser/Parser.cs index 19f307fdf..4df8339ff 100644 --- a/src/NzbDrone.Core/Parser/Parser.cs +++ b/src/NzbDrone.Core/Parser/Parser.cs @@ -472,9 +472,8 @@ namespace NzbDrone.Core.Parser private static readonly Regex TitleComponentsRegex = new Regex(@"^(?:(?