diff --git a/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedEpisodesFixture.cs b/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedEpisodesFixture.cs deleted file mode 100644 index 03f8b395e..000000000 --- a/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedEpisodesFixture.cs +++ /dev/null @@ -1,43 +0,0 @@ -using FizzWare.NBuilder; -using FluentAssertions; -using NUnit.Framework; -using NzbDrone.Core.Housekeeping.Housekeepers; -using NzbDrone.Core.Test.Framework; -using NzbDrone.Core.Tv; - -namespace NzbDrone.Core.Test.Housekeeping.Housekeepers -{ - [TestFixture] - public class CleanupOrphanedEpisodesFixture : DbTest - { - [Test] - public void should_delete_orphaned_episodes() - { - var episode = Builder.CreateNew() - .BuildNew(); - - Db.Insert(episode); - Subject.Clean(); - AllStoredModels.Should().BeEmpty(); - } - - [Test] - public void should_not_delete_unorphaned_episodes() - { - var series = Builder.CreateNew() - .BuildNew(); - - Db.Insert(series); - - var episodes = Builder.CreateListOfSize(2) - .TheFirst(1) - .With(e => e.SeriesId = series.Id) - .BuildListOfNew(); - - Db.InsertMany(episodes); - Subject.Clean(); - AllStoredModels.Should().HaveCount(1); - AllStoredModels.Should().Contain(e => e.SeriesId == series.Id); - } - } -} diff --git a/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedEpisodeFilesFixture.cs b/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedMovieFilesFixture.cs similarity index 71% rename from src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedEpisodeFilesFixture.cs rename to src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedMovieFilesFixture.cs index b09def40c..a8b4d1d3f 100644 --- a/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedEpisodeFilesFixture.cs +++ b/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedMovieFilesFixture.cs @@ -11,12 +11,12 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers { [TestFixture] - public class CleanupOrphanedEpisodeFilesFixture : DbTest + public class CleanupOrphanedMovieFilesFixture : DbTest { [Test] public void should_delete_orphaned_episode_files() { - var episodeFile = Builder.CreateNew() + var episodeFile = Builder.CreateNew() .With(h => h.Quality = new QualityModel()) .BuildNew(); @@ -28,22 +28,22 @@ public void should_delete_orphaned_episode_files() [Test] public void should_not_delete_unorphaned_episode_files() { - var episodeFiles = Builder.CreateListOfSize(2) + var episodeFiles = Builder.CreateListOfSize(2) .All() .With(h => h.Quality = new QualityModel()) .BuildListOfNew(); Db.InsertMany(episodeFiles); - var episode = Builder.CreateNew() - .With(e => e.EpisodeFileId = episodeFiles.First().Id) + var episode = Builder.CreateNew() + .With(e => e.MovieFileId = episodeFiles.First().Id) .BuildNew(); Db.Insert(episode); Subject.Clean(); AllStoredModels.Should().HaveCount(1); - Db.All().Should().Contain(e => e.EpisodeFileId == AllStoredModels.First().Id); + Db.All().Should().Contain(e => e.MovieFileId == AllStoredModels.First().Id); } } } diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 2f50a8cf2..b5d9383a6 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -230,8 +230,7 @@ - - + diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupDuplicateMetadataFiles.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupDuplicateMetadataFiles.cs index e65a117a1..bf611fb71 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupDuplicateMetadataFiles.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupDuplicateMetadataFiles.cs @@ -13,48 +13,48 @@ public CleanupDuplicateMetadataFiles(IMainDatabase database) public void Clean() { - DeleteDuplicateSeriesMetadata(); - DeleteDuplicateEpisodeMetadata(); - DeleteDuplicateEpisodeImages(); + //DeleteDuplicateSeriesMetadata(); + //DeleteDuplicateEpisodeMetadata(); + //DeleteDuplicateEpisodeImages(); } - private void DeleteDuplicateSeriesMetadata() - { - var mapper = _database.GetDataMapper(); + //private void DeleteDuplicateSeriesMetadata() + //{ + // var mapper = _database.GetDataMapper(); - mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles - WHERE Id IN ( - SELECT Id FROM MetadataFiles - WHERE Type = 1 - GROUP BY SeriesId, Consumer - HAVING COUNT(SeriesId) > 1 - )"); - } + // mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles + // WHERE Id IN ( + // SELECT Id FROM MetadataFiles + // WHERE Type = 1 + // GROUP BY SeriesId, Consumer + // HAVING COUNT(SeriesId) > 1 + // )"); + //} - private void DeleteDuplicateEpisodeMetadata() - { - var mapper = _database.GetDataMapper(); + //private void DeleteDuplicateEpisodeMetadata() + //{ + // var mapper = _database.GetDataMapper(); - mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles - WHERE Id IN ( - SELECT Id FROM MetadataFiles - WHERE Type = 2 - GROUP BY EpisodeFileId, Consumer - HAVING COUNT(EpisodeFileId) > 1 - )"); - } + // mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles + // WHERE Id IN ( + // SELECT Id FROM MetadataFiles + // WHERE Type = 2 + // GROUP BY EpisodeFileId, Consumer + // HAVING COUNT(EpisodeFileId) > 1 + // )"); + //} - private void DeleteDuplicateEpisodeImages() - { - var mapper = _database.GetDataMapper(); + //private void DeleteDuplicateEpisodeImages() + //{ + // var mapper = _database.GetDataMapper(); - mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles - WHERE Id IN ( - SELECT Id FROM MetadataFiles - WHERE Type = 5 - GROUP BY EpisodeFileId, Consumer - HAVING COUNT(EpisodeFileId) > 1 - )"); - } + // mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles + // WHERE Id IN ( + // SELECT Id FROM MetadataFiles + // WHERE Type = 5 + // GROUP BY EpisodeFileId, Consumer + // HAVING COUNT(EpisodeFileId) > 1 + // )"); + //} } } diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodeFiles.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodeFiles.cs deleted file mode 100644 index 79f186a37..000000000 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodeFiles.cs +++ /dev/null @@ -1,26 +0,0 @@ -using NzbDrone.Core.Datastore; - -namespace NzbDrone.Core.Housekeeping.Housekeepers -{ - public class CleanupOrphanedEpisodeFiles : IHousekeepingTask - { - private readonly IMainDatabase _database; - - public CleanupOrphanedEpisodeFiles(IMainDatabase database) - { - _database = database; - } - - public void Clean() - { - var mapper = _database.GetDataMapper(); - - mapper.ExecuteNonQuery(@"DELETE FROM EpisodeFiles - WHERE Id IN ( - SELECT EpisodeFiles.Id FROM EpisodeFiles - LEFT OUTER JOIN Episodes - ON EpisodeFiles.Id = Episodes.EpisodeFileId - WHERE Episodes.Id IS NULL)"); - } - } -} diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodes.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodes.cs deleted file mode 100644 index 6d9d208c9..000000000 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodes.cs +++ /dev/null @@ -1,26 +0,0 @@ -using NzbDrone.Core.Datastore; - -namespace NzbDrone.Core.Housekeeping.Housekeepers -{ - public class CleanupOrphanedEpisodes : IHousekeepingTask - { - private readonly IMainDatabase _database; - - public CleanupOrphanedEpisodes(IMainDatabase database) - { - _database = database; - } - - public void Clean() - { - var mapper = _database.GetDataMapper(); - - mapper.ExecuteNonQuery(@"DELETE FROM Episodes - WHERE Id IN ( - SELECT Episodes.Id FROM Episodes - LEFT OUTER JOIN Series - ON Episodes.SeriesId = Series.Id - WHERE Series.Id IS NULL)"); - } - } -} diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedHistoryItems.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedHistoryItems.cs index e8ee88d68..fec0597e2 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedHistoryItems.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedHistoryItems.cs @@ -13,23 +13,9 @@ public CleanupOrphanedHistoryItems(IMainDatabase database) public void Clean() { - //CleanupOrphanedBySeries(); - //CleanupOrphanedByEpisode(); CleanupOrphanedByMovie(); } - private void CleanupOrphanedBySeries() - { - var mapper = _database.GetDataMapper(); - - mapper.ExecuteNonQuery(@"DELETE FROM History - WHERE Id IN ( - SELECT History.Id FROM History - LEFT OUTER JOIN Series - ON History.SeriesId = Series.Id - WHERE Series.Id IS NULL)"); - } - private void CleanupOrphanedByMovie() { var mapper = _database.GetDataMapper(); @@ -41,17 +27,5 @@ LEFT OUTER JOIN Movies ON History.MovieId = Movies.Id WHERE Movies.Id IS NULL)"); } - - private void CleanupOrphanedByEpisode() - { - var mapper = _database.GetDataMapper(); - - mapper.ExecuteNonQuery(@"DELETE FROM History - WHERE Id IN ( - SELECT History.Id FROM History - LEFT OUTER JOIN Episodes - ON History.EpisodeId = Episodes.Id - WHERE Episodes.Id IS NULL)"); - } } } diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMetadataFiles.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMetadataFiles.cs index 05ab54ea1..aef0d275c 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMetadataFiles.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMetadataFiles.cs @@ -13,45 +13,45 @@ public CleanupOrphanedMetadataFiles(IMainDatabase database) public void Clean() { - DeleteOrphanedBySeries(); - DeleteOrphanedByEpisodeFile(); - DeleteWhereEpisodeFileIsZero(); + //DeleteOrphanedBySeries(); + //DeleteOrphanedByEpisodeFile(); + //DeleteWhereEpisodeFileIsZero(); } - private void DeleteOrphanedBySeries() - { - var mapper = _database.GetDataMapper(); + //private void DeleteOrphanedBySeries() + //{ + // var mapper = _database.GetDataMapper(); - mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles - WHERE Id IN ( - SELECT MetadataFiles.Id FROM MetadataFiles - LEFT OUTER JOIN Series - ON MetadataFiles.SeriesId = Series.Id - WHERE Series.Id IS NULL)"); - } + // mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles + // WHERE Id IN ( + // SELECT MetadataFiles.Id FROM MetadataFiles + // LEFT OUTER JOIN Series + // ON MetadataFiles.SeriesId = Series.Id + // WHERE Series.Id IS NULL)"); + //} - private void DeleteOrphanedByEpisodeFile() - { - var mapper = _database.GetDataMapper(); + //private void DeleteOrphanedByEpisodeFile() + //{ + // var mapper = _database.GetDataMapper(); - mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles - WHERE Id IN ( - SELECT MetadataFiles.Id FROM MetadataFiles - LEFT OUTER JOIN EpisodeFiles - ON MetadataFiles.EpisodeFileId = EpisodeFiles.Id - WHERE MetadataFiles.EpisodeFileId > 0 - AND EpisodeFiles.Id IS NULL)"); - } + // mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles + // WHERE Id IN ( + // SELECT MetadataFiles.Id FROM MetadataFiles + // LEFT OUTER JOIN EpisodeFiles + // ON MetadataFiles.EpisodeFileId = EpisodeFiles.Id + // WHERE MetadataFiles.EpisodeFileId > 0 + // AND EpisodeFiles.Id IS NULL)"); + //} - private void DeleteWhereEpisodeFileIsZero() - { - var mapper = _database.GetDataMapper(); + //private void DeleteWhereEpisodeFileIsZero() + //{ + // var mapper = _database.GetDataMapper(); - mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles - WHERE Id IN ( - SELECT Id FROM MetadataFiles - WHERE Type IN (2, 5) - AND EpisodeFileId = 0)"); - } + // mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles + // WHERE Id IN ( + // SELECT Id FROM MetadataFiles + // WHERE Type IN (2, 5) + // AND EpisodeFileId = 0)"); + //} } } diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMovieFiles.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMovieFiles.cs new file mode 100644 index 000000000..8b27b81c1 --- /dev/null +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedMovieFiles.cs @@ -0,0 +1,26 @@ +using NzbDrone.Core.Datastore; + +namespace NzbDrone.Core.Housekeeping.Housekeepers +{ + public class CleanupOrphanedMovieFiles : IHousekeepingTask + { + private readonly IMainDatabase _database; + + public CleanupOrphanedMovieFiles(IMainDatabase database) + { + _database = database; + } + + public void Clean() + { + var mapper = _database.GetDataMapper(); + + mapper.ExecuteNonQuery(@"DELETE FROM MovieFiles + WHERE Id IN ( + SELECT MovieFiles.Id FROM MovieFiles + LEFT OUTER JOIN Movies + ON MovieFiles.Id = Movies.MovieFileId + WHERE Movies.Id IS NULL)"); + } + } +} diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs index 63debb4b7..fb913e0a0 100644 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/CleanupUnusedTags.cs @@ -19,7 +19,7 @@ public void Clean() { var mapper = _database.GetDataMapper(); - var usedTags = new[] { "Series", "Notifications", "DelayProfiles", "Restrictions" } + var usedTags = new[] { "Movies", "Series", "Notifications", "DelayProfiles", "Restrictions" } .SelectMany(v => GetUsedTags(v, mapper)) .Distinct() .ToArray(); diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/UpdateCleanTitleForMovies.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/UpdateCleanTitleForMovies.cs new file mode 100644 index 000000000..5fb39ce4c --- /dev/null +++ b/src/NzbDrone.Core/Housekeeping/Housekeepers/UpdateCleanTitleForMovies.cs @@ -0,0 +1,27 @@ +using System.Linq; +using NzbDrone.Core.Parser; +using NzbDrone.Core.Tv; + +namespace NzbDrone.Core.Housekeeping.Housekeepers +{ + public class UpdateCleanTitleForMovies : IHousekeepingTask + { + private readonly IMovieRepository _movieRepository; + + public UpdateCleanTitleForMovies(IMovieRepository movieRepository) + { + _movieRepository = movieRepository; + } + + public void Clean() + { + var movies = _movieRepository.All().ToList(); + + movies.ForEach(s => + { + s.CleanTitle = s.CleanTitle.CleanSeriesTitle(); + _movieRepository.Update(s); + }); + } + } +} diff --git a/src/NzbDrone.Core/Housekeeping/Housekeepers/UpdateCleanTitleForSeries.cs b/src/NzbDrone.Core/Housekeeping/Housekeepers/UpdateCleanTitleForSeries.cs deleted file mode 100644 index 16b19c505..000000000 --- a/src/NzbDrone.Core/Housekeeping/Housekeepers/UpdateCleanTitleForSeries.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Linq; -using NzbDrone.Core.Parser; -using NzbDrone.Core.Tv; - -namespace NzbDrone.Core.Housekeeping.Housekeepers -{ - public class UpdateCleanTitleForSeries : IHousekeepingTask - { - private readonly ISeriesRepository _seriesRepository; - - public UpdateCleanTitleForSeries(ISeriesRepository seriesRepository) - { - _seriesRepository = seriesRepository; - } - - public void Clean() - { - var series = _seriesRepository.All().ToList(); - - series.ForEach(s => - { - s.CleanTitle = s.CleanTitle.CleanSeriesTitle(); - _seriesRepository.Update(s); - }); - } - } -} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 2c6e5e0e2..6f0d33ec4 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -639,8 +639,7 @@ - - + @@ -649,7 +648,7 @@ - + @@ -1347,4 +1346,4 @@ --> - + \ No newline at end of file