diff --git a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs index f68dc6d6b..8300b7185 100644 --- a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs @@ -157,7 +157,7 @@ namespace NzbDrone.Core.Test.JobTests Mocker.Resolve().AutoIgnoreSeasons(seriesId); - Mocker.GetMock().Verify(p => p.SetSeasonIgnore(seriesId, It.IsAny(), It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, It.IsAny(), It.IsAny()), Times.Never()); } [Test] @@ -184,7 +184,7 @@ namespace NzbDrone.Core.Test.JobTests Mocker.Resolve().AutoIgnoreSeasons(seriesId); - Mocker.GetMock().Verify(p => p.SetSeasonIgnore(seriesId, 2, It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, 2, It.IsAny()), Times.Never()); } [Test] @@ -210,9 +210,9 @@ namespace NzbDrone.Core.Test.JobTests Mocker.Resolve().AutoIgnoreSeasons(seriesId); - Mocker.GetMock().Verify(p => p.SetSeasonIgnore(seriesId, 0, true), Times.Once()); - Mocker.GetMock().Verify(p => p.SetSeasonIgnore(seriesId, 1, true), Times.Never()); - Mocker.GetMock().Verify(p => p.SetSeasonIgnore(seriesId, 2, It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, 0, true), Times.Once()); + Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, 1, true), Times.Never()); + Mocker.GetMock().Verify(p => p.SetIgnore(seriesId, 2, It.IsAny()), Times.Never()); } } diff --git a/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs index cd8db4ffb..edc90d3ae 100644 --- a/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest.cs @@ -1020,122 +1020,6 @@ namespace NzbDrone.Core.Test.ProviderTests Mocker.VerifyAllMocks(); } - [Test] - public void IgnoreSeason_Ignore() - { - WithRealDb(); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.Ignored = false) - .Build().ToList(); - - episodes.ForEach(c => Db.Insert(c)); - - //Act - Mocker.Resolve().SetSeasonIgnore(10, 1, true); - - //Assert - var episodesInDb = Db.Fetch(@"SELECT * FROM Episodes"); - - episodesInDb.Should().HaveCount(4); - episodesInDb.Where(e => e.Ignored).Should().HaveCount(4); - - Mocker.VerifyAllMocks(); - } - - [Test] - public void IgnoreSeason_RemoveIgnore() - { - WithRealDb(); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.Ignored = true) - .Build().ToList(); - - episodes.ForEach(c => Db.Insert(c)); - - //Act - Mocker.Resolve().SetSeasonIgnore(10, 1, false); - - //Assert - var episodesInDb = Db.Fetch(@"SELECT * FROM Episodes"); - - episodesInDb.Should().HaveCount(4); - episodesInDb.Where(e => !e.Ignored).Should().HaveCount(4); - - Mocker.VerifyAllMocks(); - } - - [Test] - public void IgnoreSeason_Ignore_Half() - { - WithRealDb(); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.Ignored = true) - .TheFirst(2) - .With(c => c.Ignored = false) - .Build().ToList(); - - episodes.ForEach(c => Db.Insert(c)); - - //Act - Mocker.Resolve().SetSeasonIgnore(10, 1, true); - - //Assert - var episodesInDb = Db.Fetch(@"SELECT * FROM Episodes"); - - episodesInDb.Should().HaveCount(4); - episodesInDb.Where(e => e.Ignored).Should().HaveCount(4); - - Mocker.VerifyAllMocks(); - } - - [Test] - public void IgnoreSeason_should_call_SetIgnore_in_season_provider_one_time_only() - { - WithRealDb(); - - var episodes = Builder.CreateListOfSize(4) - .All() - .With(c => c.SeriesId = 10) - .With(c => c.SeasonNumber = 1) - .With(c => c.Ignored = false) - .Build().ToList(); - - var season = new Season - { - SeriesId = 10, - SeasonNumber = 1, - Ignored = false - }; - - Db.Insert(season); - Db.InsertMany(episodes); - - Mocker.GetMock().Setup(s => s.SetIgnore(10, 1, true)).Verifiable(); - - //Act - Mocker.Resolve().SetSeasonIgnore(10, 1, true); - - //Assert - var episodesInDb = Db.Fetch(@"SELECT * FROM Episodes"); - - episodesInDb.Should().HaveCount(4); - episodesInDb.Where(e => e.Ignored).Should().HaveCount(4); - - Mocker.GetMock().Verify(s => s.SetIgnore(10, 1, true), Times.Once()); - } - [Test] public void EpisodesWithoutFiles_no_specials() { diff --git a/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_DeleteInvalidEpisodes.cs b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_DeleteInvalidEpisodes.cs index f8873b2ed..c4f767a92 100644 --- a/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_DeleteInvalidEpisodes.cs +++ b/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_DeleteInvalidEpisodes.cs @@ -25,13 +25,11 @@ namespace NzbDrone.Core.Test.ProviderTests const int seriesId = 71663; const int episodeCount = 10; - var tvDbSeries = Builder.CreateNew().With( - c => c.Episodes = - new List(Builder.CreateListOfSize(episodeCount). + var tvDbSeries = Builder.CreateListOfSize(episodeCount). All() .With(l => l.Language = new TvdbLanguage(0, "eng", "a")) - .Build()) - ).With(c => c.Id = seriesId).Build(); + .Build(); + var fakeSeries = Builder.CreateNew() .With(c => c.SeriesId = seriesId) @@ -39,7 +37,7 @@ namespace NzbDrone.Core.Test.ProviderTests var fakeEpisode = Builder.CreateNew() .With(e => e.SeriesId = seriesId) - .With(e => e.TvDbEpisodeId = tvDbSeries.Episodes.First().Id) + .With(e => e.TvDbEpisodeId = tvDbSeries.First().Id) .Build(); @@ -65,13 +63,10 @@ namespace NzbDrone.Core.Test.ProviderTests const int seriesId = 71663; const int episodeCount = 10; - var tvDbSeries = Builder.CreateNew().With( - c => c.Episodes = - new List(Builder.CreateListOfSize(episodeCount). - All() - .With(l => l.Language = new TvdbLanguage(0, "eng", "a")) - .Build()) - ).With(c => c.Id = seriesId).Build(); + var tvDbSeries = Builder.CreateListOfSize(episodeCount). + All() + .With(l => l.Language = new TvdbLanguage(0, "eng", "a")) + .Build(); var fakeSeries = Builder.CreateNew() .With(c => c.SeriesId = seriesId) @@ -105,13 +100,10 @@ namespace NzbDrone.Core.Test.ProviderTests const int seriesId = 71663; const int episodeCount = 10; - var tvDbSeries = Builder.CreateNew().With( - c => c.Episodes = - new List(Builder.CreateListOfSize(episodeCount). - All() - .With(l => l.Language = new TvdbLanguage(0, "eng", "a")) - .Build()) - ).With(c => c.Id = seriesId).Build(); + var tvDbSeries = Builder.CreateListOfSize(episodeCount). + All() + .With(l => l.Language = new TvdbLanguage(0, "eng", "a")) + .Build(); var fakeSeries = Builder.CreateNew() .With(c => c.SeriesId = seriesId) @@ -145,13 +137,10 @@ namespace NzbDrone.Core.Test.ProviderTests const int seriesId = 71663; const int episodeCount = 10; - var tvDbSeries = Builder.CreateNew().With( - c => c.Episodes = - new List(Builder.CreateListOfSize(episodeCount). - All() - .With(l => l.Language = new TvdbLanguage(0, "eng", "a")) - .Build()) - ).With(c => c.Id = seriesId).Build(); + var tvDbSeries = Builder.CreateListOfSize(episodeCount). + All() + .With(l => l.Language = new TvdbLanguage(0, "eng", "a")) + .Build(); var fakeSeries = Builder.CreateNew() .With(c => c.SeriesId = seriesId) @@ -188,13 +177,10 @@ namespace NzbDrone.Core.Test.ProviderTests const int seriesId = 71663; const int episodeCount = 10; - var tvDbSeries = Builder.CreateNew().With( - c => c.Episodes = - new List(Builder.CreateListOfSize(episodeCount). - All() - .With(l => l.Language = new TvdbLanguage(0, "eng", "a")) - .Build()) - ).With(c => c.Id = seriesId).Build(); + var tvDbSeries = Builder.CreateListOfSize(episodeCount). + All() + .With(l => l.Language = new TvdbLanguage(0, "eng", "a")) + .Build(); var fakeSeries = Builder.CreateNew() .With(c => c.SeriesId = seriesId) @@ -236,5 +222,15 @@ namespace NzbDrone.Core.Test.ProviderTests var result = db.Fetch(); result.Should().HaveCount(1); } + + [Test] + public void should_not_do_anything_if_episode_list_is_empty() + { + WithStrictMocker(); + + var fakeSeries = Builder.CreateNew().Build(); + + Mocker.Resolve().DeleteEpisodesNotInTvdb(fakeSeries, new List()); + } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs index e61a19bfa..b27201320 100644 --- a/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/ReferenceDataProviderTest.cs @@ -1,8 +1,9 @@ using System; using System.Linq; - +using System.Net; using FizzWare.NBuilder; using FluentAssertions; +using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Providers; @@ -191,5 +192,20 @@ namespace NzbDrone.Core.Test.ProviderTests result.Where(s => s.IsDaily).Should().HaveCount(3); result.Where(s => !s.IsDaily).Should().HaveCount(2); } + + [Test] + public void broken_service_should_not_cause_this_call_to_fail() + { + WithRealDb(); + + Mocker.GetMock().Setup(s => s.DownloadString(It.IsAny())) + .Throws(new WebException()) + .Verifiable(); + + Mocker.Resolve().UpdateDailySeries(); + + ExceptionVerification.ExpectedWarns(1); + Mocker.VerifyAllMocks(); + } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/ProviderTests/SeasonProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/SeasonProviderTest.cs index 4a2ca931f..fa400ab90 100644 --- a/NzbDrone.Core.Test/ProviderTests/SeasonProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/SeasonProviderTest.cs @@ -1,5 +1,4 @@ // ReSharper disable RedundantUsingDirective - using System; using System.Collections.Generic; using System.Linq; @@ -25,89 +24,51 @@ namespace NzbDrone.Core.Test.ProviderTests // ReSharper disable InconsistentNaming public class SeasonProviderTest : CoreTest { - [Test] - public void AddSeason_should_insert_season_to_database_with_ignored_false() + [SetUp] + public void Setup() { WithRealDb(); - - var seriesId = 10; - var seasonNumber = 50; - - //Act - Mocker.Resolve().Add(seriesId, seasonNumber); - - //Assert - var result = Db.Fetch(); - result.Should().HaveCount(1); - result.First().SeriesId.Should().Be(seriesId); - result.First().SeasonNumber.Should().Be(seasonNumber); - result.First().Ignored.Should().BeFalse(); } + [TestCase(true)] [TestCase(false)] - public void AddSeason_should_insert_season_to_database_with_preset_ignored_status(bool isIgnored) + public void SetIgnore_should_update_ignored_status(bool ignoreFlag) { - WithRealDb(); - - var seriesId = 10; - var seasonNumber = 50; - - //Act - Mocker.Resolve().Add(seriesId, seasonNumber, isIgnored); - - //Assert - var result = Db.Fetch(); - result.Should().HaveCount(1); - result.First().SeriesId.Should().Be(seriesId); - result.First().SeasonNumber.Should().Be(seasonNumber); - result.First().Ignored.Should().Be(isIgnored); - } - - [Test] - public void DeleteSeason_should_remove_season_from_database() - { - WithRealDb(); - - var fakeSeason = Builder.CreateNew().Build(); - - Db.Insert(fakeSeason); - - //Act - Mocker.Resolve().Delete(fakeSeason.SeriesId, fakeSeason.SeasonNumber); - - //Assert - var result = Db.Fetch(); - result.Should().BeEmpty(); - } - - [Test] - public void SetIgnore_should_update_ignored_status() - { - WithRealDb(); - var fakeSeason = Builder.CreateNew() - .With(s => s.Ignored = false) + .With(s => s.Ignored = !ignoreFlag) .Build(); + var fakeEpisodes = Builder.CreateListOfSize(4) + .All() + .With(c => c.SeriesId = fakeSeason.SeriesId) + .With(c => c.SeasonNumber = fakeSeason.SeasonId) + .With(c => c.Ignored = !ignoreFlag) + .Build().ToList(); + + fakeEpisodes.ForEach(c => Db.Insert(c)); + var id = Db.Insert(fakeSeason); //Act - Mocker.Resolve().SetIgnore(fakeSeason.SeriesId, fakeSeason.SeasonNumber, true); + Mocker.Resolve().SetIgnore(fakeSeason.SeriesId, fakeSeason.SeasonNumber, ignoreFlag); //Assert - var result = Db.SingleOrDefault(id); - result.Ignored.Should().BeTrue(); + var season = Db.SingleOrDefault(id); + season.Ignored.Should().Be(ignoreFlag); + + var episodes = Db.Fetch(); + episodes.Should().HaveSameCount(fakeEpisodes); + episodes.Should().OnlyContain(c => c.Ignored == ignoreFlag); } - [Test] - public void IsIgnored_should_return_ignored_status_of_season() + [TestCase(true)] + [TestCase(false)] + public void IsIgnored_should_return_ignored_status_of_season(bool ignoreFlag) { - WithRealDb(); - //Setup var fakeSeason = Builder.CreateNew() - .With(s => s.Ignored = false) + .With(s => s.Ignored = ignoreFlag) .Build(); Db.Insert(fakeSeason); @@ -116,94 +77,13 @@ namespace NzbDrone.Core.Test.ProviderTests var result = Mocker.Resolve().IsIgnored(fakeSeason.SeriesId, fakeSeason.SeasonNumber); //Assert - result.Should().Be(fakeSeason.Ignored); - Db.Fetch().Count.Should().Be(1); + result.Should().Be(ignoreFlag); } [Test] - public void IsIgnored_should_return_true_if_not_in_db_and_is_season_zero() + public void IsIgnored_should_throw_an_exception_if_not_in_db() { - //Setup - WithRealDb(); - - //Act - var result = Mocker.Resolve().IsIgnored(10, 0); - - //Assert - result.Should().BeTrue(); - Db.Fetch().Should().HaveCount(1); - } - - [Test] - public void IsIgnored_should_return_false_if_not_in_db_and_is_season_one() - { - //Setup - WithRealDb(); - - //Act - var result = Mocker.Resolve().IsIgnored(10, 1); - - //Assert - result.Should().BeFalse(); - Db.Fetch().Should().HaveCount(1); - } - - [Test] - public void IsIgnored_should_return_false_if_not_in_db_and_previous_season_is_not_ignored() - { - //Setup - WithRealDb(); - - var lastSeason = Builder.CreateNew() - .With(s => s.SeriesId = 10) - .With(s => s.SeasonNumber = 4) - .With(s => s.Ignored = false) - .Build(); - - Db.Insert(lastSeason); - - //Act - var result = Mocker.Resolve().IsIgnored(10, 5); - - //Assert - result.Should().BeFalse(); - Db.Fetch().Should().HaveCount(2); - } - - [Test] - public void IsIgnored_should_return_true_if_not_in_db_and_previous_season_is_ignored() - { - //Setup - WithRealDb(); - - var lastSeason = Builder.CreateNew() - .With(s => s.SeriesId = 10) - .With(s => s.SeasonNumber = 4) - .With(s => s.Ignored = true) - .Build(); - - Db.Insert(lastSeason); - - //Act - var result = Mocker.Resolve().IsIgnored(10, 5); - - //Assert - result.Should().BeTrue(); - Db.Fetch().Should().HaveCount(2); - } - - [Test] - public void IsIgnored_should_return_false_if_not_in_db_and_previous_season_does_not_exist() - { - //Setup - WithRealDb(); - - //Act - var result = Mocker.Resolve().IsIgnored(10, 5); - - //Assert - result.Should().BeFalse(); - Db.Fetch().Should().HaveCount(1); + Assert.Throws(() => Mocker.Resolve().IsIgnored(10, 0)); } [Test] @@ -211,9 +91,6 @@ namespace NzbDrone.Core.Test.ProviderTests { const int seriesId = 10; - //Setup - WithRealDb(); - var season = Builder.CreateNew() .With(s => s.SeriesId = seriesId) .With(s => s.SeasonNumber = 4) @@ -272,10 +149,73 @@ namespace NzbDrone.Core.Test.ProviderTests //Assert result.Should().HaveCount(5); - foreach(var season in result) + foreach (var season in result) { season.Episodes.Count.Should().Be(2); + season.Episodes.Should().OnlyContain(c => c.SeasonNumber == season.SeasonNumber); } } + + [Test] + public void EnsureSeason_should_add_all_seasons_for_new_series() + { + var seasons = new[] { 0, 1, 2, 3, 4, 5 }; + Mocker.Resolve().EnsureSeasons(12, seasons); + + Mocker.Resolve().GetSeasons(12).SequenceEqual(seasons); + } + + [Test] + public void EnsureSeason_should_add_missing_seasons() + { + var seasonsA = new[] { 0, 1, 2, 3 }; + var seasonsB = new[] { 0, 1, 2, 3, 4, 5 }; + Mocker.Resolve().EnsureSeasons(12, seasonsA); + Mocker.Resolve().GetSeasons(12).SequenceEqual(seasonsA); + + Mocker.Resolve().EnsureSeasons(12, seasonsB); + Mocker.Resolve().GetSeasons(12).SequenceEqual(seasonsB); + } + + + [Test] + public void EnsureSeason_marks_season_zero_as_ignored() + { + var seasons = new[] { 0, 1, 2, 3 }; + + Mocker.Resolve().EnsureSeasons(12, seasons); + Db.Fetch().Should().Contain(c => c.SeasonNumber == 0 && c.Ignored); + } + + + [Test] + public void EnsureSeason_none_zero_seasons_arent_ignored() + { + var seasons = new[] { 1, 2, 3 }; + + Mocker.Resolve().EnsureSeasons(12, seasons); + Db.Fetch().Should().OnlyContain(c => c.Ignored == false); + } + + [Test] + public void GetSeason_should_return_seasons_for_specified_series_only() + { + var seriesA = new[] { 1, 2, 3 }; + var seriesB = new[] { 4, 5, 6 }; + + Mocker.Resolve().EnsureSeasons(1, seriesA); + Mocker.Resolve().EnsureSeasons(2, seriesB); + + Mocker.Resolve().GetSeasons(1).Should().Equal(seriesA); + Mocker.Resolve().GetSeasons(2).Should().Equal(seriesB); + } + + + [Test] + public void GetSeason_should_return_emptylist_if_series_doesnt_exist() + { + Mocker.Resolve().GetSeasons(1).Should().BeEmpty(); + } + } } diff --git a/NzbDrone.Core.Test/ProviderTests/SeriesProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/SeriesProviderTest.cs index 0ff6e830b..be827fee0 100644 --- a/NzbDrone.Core.Test/ProviderTests/SeriesProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/SeriesProviderTest.cs @@ -817,5 +817,19 @@ namespace NzbDrone.Core.Test.ProviderTests result.Last().Monitored.Should().Be(monitored); result.Last().SeasonFolder.Should().Be(seasonFolder); } + + [Test] + public void delete_series_should_delete_all_rows_related_to_the_series() + { + var fakeSeries = Builder.CreateListOfSize(3).Build(); + var fakeEpisodes = Builder.CreateListOfSize(30) + .TheFirst(10).With(c=>c.SeriesId = fakeSeries[0].SeriesId) + .TheNext(10).With(c=>c.SeriesId = fakeSeries[1].SeriesId) + .TheNext(10).With(c => c.SeriesId = fakeSeries[2].SeriesId) + .Build(); + + + + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Datastore/Migrations/Migration20120227.cs b/NzbDrone.Core/Datastore/Migrations/Migration20120227.cs new file mode 100644 index 000000000..016bf41d4 --- /dev/null +++ b/NzbDrone.Core/Datastore/Migrations/Migration20120227.cs @@ -0,0 +1,19 @@ +using Migrator.Framework; + +namespace NzbDrone.Core.Datastore.Migrations +{ + + [Migration(20120227)] + public class Migration20120227 : NzbDroneMigration + { + protected override void MainDbUpgrade() + { + Database.ExecuteNonQuery(@"DELETE FROM Seasons WHERE SeasonNumber NOT IN + ( + SELECT DISTINCT SeasonNumber + FROM Episodes + WHERE Seasons.SeriesId = Episodes.SeriesId + )"); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs b/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs index 6b3f72f2e..c6d0f66cb 100644 --- a/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs +++ b/NzbDrone.Core/Jobs/ImportNewSeriesJob.cs @@ -21,6 +21,7 @@ namespace NzbDrone.Core.Jobs private readonly UpdateInfoJob _updateInfoJob; private readonly DiskScanJob _diskScanJob; private readonly BannerDownloadJob _bannerDownloadJob; + private readonly SeasonProvider _seasonProvider; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); @@ -29,7 +30,7 @@ namespace NzbDrone.Core.Jobs [Inject] public ImportNewSeriesJob(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, MediaFileProvider mediaFileProvider, UpdateInfoJob updateInfoJob, - DiskScanJob diskScanJob, BannerDownloadJob bannerDownloadJob) + DiskScanJob diskScanJob, BannerDownloadJob bannerDownloadJob,SeasonProvider seasonProvider) { _seriesProvider = seriesProvider; _episodeProvider = episodeProvider; @@ -37,6 +38,7 @@ namespace NzbDrone.Core.Jobs _updateInfoJob = updateInfoJob; _diskScanJob = diskScanJob; _bannerDownloadJob = bannerDownloadJob; + _seasonProvider = seasonProvider; } public string Name @@ -105,7 +107,7 @@ namespace NzbDrone.Core.Jobs { if (season != currentSeasons && !episodeFiles.Any(e => e.SeasonNumber == season)) { - _episodeProvider.SetSeasonIgnore(seriesId, season, true); + _seasonProvider.SetIgnore(seriesId, season, true); } } } diff --git a/NzbDrone.Core/Jobs/SeriesSearchJob.cs b/NzbDrone.Core/Jobs/SeriesSearchJob.cs index 6886b4cb4..d14195fda 100644 --- a/NzbDrone.Core/Jobs/SeriesSearchJob.cs +++ b/NzbDrone.Core/Jobs/SeriesSearchJob.cs @@ -11,7 +11,7 @@ namespace NzbDrone.Core.Jobs private readonly SeasonSearchJob _seasonSearchJob; private readonly SeasonProvider _seasonProvider; - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger logger = LogManager.GetCurrentClassLogger(); public SeriesSearchJob(SeasonSearchJob seasonSearchJob, SeasonProvider seasonProvider) @@ -35,16 +35,15 @@ namespace NzbDrone.Core.Jobs if (targetId <= 0) throw new ArgumentOutOfRangeException("targetId"); - Logger.Debug("Getting seasons from database for series: {0}", targetId); + logger.Debug("Getting seasons from database for series: {0}", targetId); var seasons = _seasonProvider.GetSeasons(targetId).Where(s => s > 0); foreach (var season in seasons) { - //Skip ignored seasons - if (_seasonProvider.IsIgnored(targetId, season)) - continue; - - _seasonSearchJob.Start(notification, targetId, season); + if (!_seasonProvider.IsIgnored(targetId, season)) + { + _seasonSearchJob.Start(notification, targetId, season); + } } } } diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 5428703b6..a414324ef 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -222,6 +222,7 @@ + diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 7fb0e9768..08d3b8c16 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -272,24 +272,26 @@ namespace NzbDrone.Core.Providers public virtual void RefreshEpisodeInfo(Series series) { logger.Trace("Starting episode info refresh for series: {0}", series.Title.WithDefault(series.SeriesId)); - int successCount = 0; - int failCount = 0; - var tvDbSeriesInfo = _tvDbProvider.GetSeries(series.SeriesId, true); + var successCount = 0; + var failCount = 0; + + var tvdbEpisodes = _tvDbProvider.GetSeries(series.SeriesId, true) + .Episodes + .Where(episode => !string.IsNullOrWhiteSpace(episode.EpisodeName) || + (episode.FirstAired < DateTime.Now.AddDays(2) && episode.FirstAired.Year > 1900)) + .ToList(); var seriesEpisodes = GetEpisodeBySeries(series.SeriesId); var updateList = new List(); var newList = new List(); - foreach (var episode in tvDbSeriesInfo.Episodes.OrderBy(e => e.SeasonNumber).ThenBy(e => e.EpisodeNumber)) + _seasonProvider.EnsureSeasons(series.SeriesId, tvdbEpisodes.Select(c => c.SeasonNumber).Distinct()); + + foreach (var episode in tvdbEpisodes.OrderBy(e => e.SeasonNumber).ThenBy(e => e.EpisodeNumber)) { try { - //skip episodes that are too far in the future and have no title. - if ((episode.FirstAired > DateTime.Now.AddDays(2) || episode.FirstAired.Year < 1900) && - string.IsNullOrWhiteSpace(episode.EpisodeName)) - continue; - - logger.Trace("Updating info for [{0}] - S{1}E{2}", tvDbSeriesInfo.SeriesName, episode.SeasonNumber, episode.EpisodeNumber); + logger.Trace("Updating info for [{0}] - S{1:00}E{2:00}", series.Title, episode.SeasonNumber, episode.EpisodeNumber); //first check using tvdbId, this should cover cases when and episode number in a season is changed var episodeToUpdate = seriesEpisodes.SingleOrDefault(e => e.TvDbEpisodeId == episode.Id); @@ -300,18 +302,16 @@ namespace NzbDrone.Core.Providers episodeToUpdate = seriesEpisodes.SingleOrDefault(e => e.SeasonNumber == episode.SeasonNumber && e.EpisodeNumber == episode.EpisodeNumber); } - //Episode doesn't exist locally if (episodeToUpdate == null) { episodeToUpdate = new Episode(); newList.Add(episodeToUpdate); - //If it is Episode Zero Ignore it, since it is new - if (episode.EpisodeNumber == 0 && episode.SeasonNumber > 1) + //If it is Episode Zero Ignore it (specials, sneak peeks.) + if (episode.EpisodeNumber == 0 && episode.SeasonNumber != 1) { episodeToUpdate.Ignored = true; } - //Else we need to check if this episode should be ignored based on IsIgnored rules else { episodeToUpdate.Ignored = _seasonProvider.IsIgnored(series.SeriesId, episode.SeasonNumber); @@ -338,8 +338,7 @@ namespace NzbDrone.Core.Providers } catch (Exception e) { - logger.FatalException( - String.Format("An error has occurred while updating episode info for series {0}", tvDbSeriesInfo.SeriesName), e); + logger.FatalException(String.Format("An error has occurred while updating episode info for series {0}", series.Title), e); failCount++; } } @@ -350,14 +349,14 @@ namespace NzbDrone.Core.Providers if (failCount != 0) { logger.Info("Finished episode refresh for series: {0}. Successful: {1} - Failed: {2} ", - tvDbSeriesInfo.SeriesName, successCount, failCount); + series.Title, successCount, failCount); } else { - logger.Info("Finished episode refresh for series: {0}.", tvDbSeriesInfo.SeriesName); + logger.Info("Finished episode refresh for series: {0}.", series.Title); } - - DeleteEpisodesNotInTvdb(series, tvDbSeriesInfo); + + DeleteEpisodesNotInTvdb(series, tvdbEpisodes); } public virtual void UpdateEpisode(Episode episode) @@ -375,21 +374,6 @@ namespace NzbDrone.Core.Providers return _database.Fetch("SELECT EpisodeNumber FROM Episodes WHERE SeriesId=@0 AND SeasonNumber=@1", seriesId, seasonNumber).OrderBy(c => c).ToList(); } - public virtual void SetSeasonIgnore(int seriesId, int seasonNumber, bool isIgnored) - { - logger.Info("Setting ignore flag on Series:{0} Season:{1} to {2}", seriesId, seasonNumber, isIgnored); - - //Set the SeasonIgnore - _seasonProvider.SetIgnore(seriesId, seasonNumber, isIgnored); - - //Ignore all the episodes in the season - _database.Execute(@"UPDATE Episodes SET Ignored = @0 - WHERE SeriesId = @1 AND SeasonNumber = @2 AND Ignored = @3", - isIgnored, seriesId, seasonNumber, !isIgnored); - - logger.Info("Ignore flag for Series:{0} Season:{1} successfully set to {2}", seriesId, seasonNumber, isIgnored); - } - public virtual void SetEpisodeIgnore(int episodeId, bool isIgnored) { _database.Execute(@"UPDATE Episodes SET Ignored = @0 @@ -414,12 +398,14 @@ namespace NzbDrone.Core.Providers return false; } - public virtual void DeleteEpisodesNotInTvdb(Series series, TvdbSeries tvDbSeriesInfo) + public virtual void DeleteEpisodesNotInTvdb(Series series, IList tvdbEpisodes) { logger.Trace("Starting deletion of episodes that no longer exist in TVDB: {0}", series.Title.WithDefault(series.SeriesId)); + if (!tvdbEpisodes.Any()) return; + //Delete Episodes not matching TvDbIds for this series - var tvDbIds = tvDbSeriesInfo.Episodes.Select(e => e.Id); + var tvDbIds = tvdbEpisodes.Select(e => e.Id); var tvDbIdString = String.Join(", ", tvDbIds); var tvDbIdQuery = String.Format("DELETE FROM Episodes WHERE SeriesId = {0} AND TvDbEpisodeId > 0 AND TvDbEpisodeId NOT IN ({1})", diff --git a/NzbDrone.Core/Providers/ReferenceDataProvider.cs b/NzbDrone.Core/Providers/ReferenceDataProvider.cs index 95591490d..b4bc5f800 100644 --- a/NzbDrone.Core/Providers/ReferenceDataProvider.cs +++ b/NzbDrone.Core/Providers/ReferenceDataProvider.cs @@ -34,10 +34,13 @@ namespace NzbDrone.Core.Providers var seriesIds = GetDailySeriesIds(); - var dailySeriesString = String.Join(", ", seriesIds); - var sql = String.Format("UPDATE Series SET IsDaily = 1 WHERE SeriesId in ({0})", dailySeriesString); + if (seriesIds.Any()) + { + var dailySeriesString = String.Join(", ", seriesIds); + var sql = String.Format("UPDATE Series SET IsDaily = 1 WHERE SeriesId in ({0})", dailySeriesString); - _database.Execute(sql); + _database.Execute(sql); + } } public virtual bool IsSeriesDaily(int seriesId) diff --git a/NzbDrone.Core/Providers/SeasonProvider.cs b/NzbDrone.Core/Providers/SeasonProvider.cs index 2ce4148c3..ed233c68e 100644 Binary files a/NzbDrone.Core/Providers/SeasonProvider.cs and b/NzbDrone.Core/Providers/SeasonProvider.cs differ diff --git a/NzbDrone.Services/NzbDrone.Services.Service/Views/Shared/NoSeriesBanner.cshtml b/NzbDrone.Services/NzbDrone.Services.Service/Views/Shared/NoSeriesBanner.cshtml index 9886aab57..2c05f1859 100644 --- a/NzbDrone.Services/NzbDrone.Services.Service/Views/Shared/NoSeriesBanner.cshtml +++ b/NzbDrone.Services/NzbDrone.Services.Service/Views/Shared/NoSeriesBanner.cshtml @@ -1,2 +1,2 @@  -
It looks like you haven't added any series to NzbDrone. @Html.ActionLink("Click here to add one.", "Index", "AddSeries")
\ No newline at end of file +
It looks like you haven't added any series to NzbDrone. @*@Html.ActionLink("Click here to add one.", "Index", "AddSeries")*@
\ No newline at end of file diff --git a/NzbDrone.Web/Controllers/CommandController.cs b/NzbDrone.Web/Controllers/CommandController.cs index 3c7ebc30e..9a0926ef3 100644 --- a/NzbDrone.Web/Controllers/CommandController.cs +++ b/NzbDrone.Web/Controllers/CommandController.cs @@ -16,10 +16,11 @@ namespace NzbDrone.Web.Controllers private readonly TwitterProvider _twitterProvider; private readonly EpisodeProvider _episodeProvider; private readonly GrowlProvider _growlProvider; + private readonly SeasonProvider _seasonProvider; public CommandController(JobProvider jobProvider, SabProvider sabProvider, SmtpProvider smtpProvider, TwitterProvider twitterProvider, - EpisodeProvider episodeProvider, GrowlProvider growlProvider) + EpisodeProvider episodeProvider, GrowlProvider growlProvider, SeasonProvider seasonProvider) { _jobProvider = jobProvider; _sabProvider = sabProvider; @@ -27,6 +28,7 @@ namespace NzbDrone.Web.Controllers _twitterProvider = twitterProvider; _episodeProvider = episodeProvider; _growlProvider = growlProvider; + _seasonProvider = seasonProvider; } public JsonResult RssSync() @@ -114,7 +116,7 @@ namespace NzbDrone.Web.Controllers [HttpPost] public EmptyResult SaveSeasonIgnore(int seriesId, int seasonNumber, bool ignored) { - _episodeProvider.SetSeasonIgnore(seriesId, seasonNumber, ignored); + _seasonProvider.SetIgnore(seriesId, seasonNumber, ignored); return new EmptyResult(); }