From d5504043c59dce152274a9f7406ac3259f26c588 Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Wed, 11 Jan 2017 19:06:08 -0500 Subject: [PATCH] Movies in list don't sort correctly #174 --- .../Migration/115_update_movie_sorttitle.cs | 45 +++++++++++++++++++ .../MetadataSource/SkyHook/SkyHookProxy.cs | 2 +- src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + src/UI/Movies/MoviesCollection.js | 6 +-- 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/115_update_movie_sorttitle.cs diff --git a/src/NzbDrone.Core/Datastore/Migration/115_update_movie_sorttitle.cs b/src/NzbDrone.Core/Datastore/Migration/115_update_movie_sorttitle.cs new file mode 100644 index 000000000..593665455 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/115_update_movie_sorttitle.cs @@ -0,0 +1,45 @@ +using System.Data; +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(115)] + public class update_movie_sorttitle : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + // Create.Column("SortTitle").OnTable("Series").AsString().Nullable(); + Execute.WithConnection(SetSortTitles); + } + + private void SetSortTitles(IDbConnection conn, IDbTransaction tran) + { + using (IDbCommand getSeriesCmd = conn.CreateCommand()) + { + getSeriesCmd.Transaction = tran; + getSeriesCmd.CommandText = @"SELECT Id, Title FROM Movies"; + using (IDataReader seriesReader = getSeriesCmd.ExecuteReader()) + { + while (seriesReader.Read()) + { + var id = seriesReader.GetInt32(0); + var title = seriesReader.GetString(1); + + var sortTitle = Parser.Parser.NormalizeTitle(title).ToLower(); + + using (IDbCommand updateCmd = conn.CreateCommand()) + { + updateCmd.Transaction = tran; + updateCmd.CommandText = "UPDATE Movies SET SortTitle = ? WHERE Id = ?"; + updateCmd.AddParameter(sortTitle); + updateCmd.AddParameter(id); + + updateCmd.ExecuteNonQuery(); + } + } + } + } + } + } +} diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index 4eb97e1ab..2d8248638 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -327,7 +327,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook imdbMovie.TmdbId = result.id; try { - imdbMovie.SortTitle = result.title; + imdbMovie.SortTitle = Parser.Parser.NormalizeTitle(result.title); imdbMovie.Title = result.title; string titleSlug = result.title; imdbMovie.TitleSlug = titleSlug.ToLower().Replace(" ", "-"); diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 3ea6a0a76..cd482bd90 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -183,6 +183,7 @@ + diff --git a/src/UI/Movies/MoviesCollection.js b/src/UI/Movies/MoviesCollection.js index 44957debd..bc97e360d 100644 --- a/src/UI/Movies/MoviesCollection.js +++ b/src/UI/Movies/MoviesCollection.js @@ -15,10 +15,10 @@ var Collection = PageableCollection.extend({ tableName : 'movie', state : { - sortKey : 'title', + sortKey : 'sortTitle', order : 1, pageSize : 100000, - secondarySortKey : 'title', + secondarySortKey : 'sortTitle', secondarySortOrder : -1 }, @@ -73,7 +73,7 @@ var Collection = PageableCollection.extend({ sortMappings : { title : { - sortKey : 'title' + sortKey : 'sortTitle' }, nextAiring : {