Fixed: fixed an issue where season ignore check wasn't working correctly.

Fixed: unavailable nzbdrone service will no longer block series from being added.
This commit is contained in:
kay.one 2012-02-27 21:50:56 -08:00
parent ada0a3bfbc
commit c5df00cc87
15 changed files with 222 additions and 360 deletions

View File

@ -157,7 +157,7 @@ namespace NzbDrone.Core.Test.JobTests
Mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
Mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, It.IsAny<int>(), It.IsAny<Boolean>()), Times.Never());
Mocker.GetMock<SeasonProvider>().Verify(p => p.SetIgnore(seriesId, It.IsAny<int>(), It.IsAny<Boolean>()), Times.Never());
}
[Test]
@ -184,7 +184,7 @@ namespace NzbDrone.Core.Test.JobTests
Mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
Mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 2, It.IsAny<Boolean>()), Times.Never());
Mocker.GetMock<SeasonProvider>().Verify(p => p.SetIgnore(seriesId, 2, It.IsAny<Boolean>()), Times.Never());
}
[Test]
@ -210,9 +210,9 @@ namespace NzbDrone.Core.Test.JobTests
Mocker.Resolve<ImportNewSeriesJob>().AutoIgnoreSeasons(seriesId);
Mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 0, true), Times.Once());
Mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 1, true), Times.Never());
Mocker.GetMock<EpisodeProvider>().Verify(p => p.SetSeasonIgnore(seriesId, 2, It.IsAny<Boolean>()), Times.Never());
Mocker.GetMock<SeasonProvider>().Verify(p => p.SetIgnore(seriesId, 0, true), Times.Once());
Mocker.GetMock<SeasonProvider>().Verify(p => p.SetIgnore(seriesId, 1, true), Times.Never());
Mocker.GetMock<SeasonProvider>().Verify(p => p.SetIgnore(seriesId, 2, It.IsAny<Boolean>()), Times.Never());
}
}

View File

@ -1020,122 +1020,6 @@ namespace NzbDrone.Core.Test.ProviderTests
Mocker.VerifyAllMocks();
}
[Test]
public void IgnoreSeason_Ignore()
{
WithRealDb();
var episodes = Builder<Episode>.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<EpisodeProvider>().SetSeasonIgnore(10, 1, true);
//Assert
var episodesInDb = Db.Fetch<Episode>(@"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<Episode>.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<EpisodeProvider>().SetSeasonIgnore(10, 1, false);
//Assert
var episodesInDb = Db.Fetch<Episode>(@"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<Episode>.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<EpisodeProvider>().SetSeasonIgnore(10, 1, true);
//Assert
var episodesInDb = Db.Fetch<Episode>(@"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<Episode>.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<SeasonProvider>().Setup(s => s.SetIgnore(10, 1, true)).Verifiable();
//Act
Mocker.Resolve<EpisodeProvider>().SetSeasonIgnore(10, 1, true);
//Assert
var episodesInDb = Db.Fetch<Episode>(@"SELECT * FROM Episodes");
episodesInDb.Should().HaveCount(4);
episodesInDb.Where(e => e.Ignored).Should().HaveCount(4);
Mocker.GetMock<SeasonProvider>().Verify(s => s.SetIgnore(10, 1, true), Times.Once());
}
[Test]
public void EpisodesWithoutFiles_no_specials()
{

View File

@ -25,13 +25,11 @@ namespace NzbDrone.Core.Test.ProviderTests
const int seriesId = 71663;
const int episodeCount = 10;
var tvDbSeries = Builder<TvdbSeries>.CreateNew().With(
c => c.Episodes =
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
var tvDbSeries = Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
All()
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
.Build())
).With(c => c.Id = seriesId).Build();
.Build();
var fakeSeries = Builder<Series>.CreateNew()
.With(c => c.SeriesId = seriesId)
@ -39,7 +37,7 @@ namespace NzbDrone.Core.Test.ProviderTests
var fakeEpisode = Builder<Episode>.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<TvdbSeries>.CreateNew().With(
c => c.Episodes =
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
All()
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
.Build())
).With(c => c.Id = seriesId).Build();
var tvDbSeries = Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
All()
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
.Build();
var fakeSeries = Builder<Series>.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<TvdbSeries>.CreateNew().With(
c => c.Episodes =
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
All()
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
.Build())
).With(c => c.Id = seriesId).Build();
var tvDbSeries = Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
All()
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
.Build();
var fakeSeries = Builder<Series>.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<TvdbSeries>.CreateNew().With(
c => c.Episodes =
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
All()
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
.Build())
).With(c => c.Id = seriesId).Build();
var tvDbSeries = Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
All()
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
.Build();
var fakeSeries = Builder<Series>.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<TvdbSeries>.CreateNew().With(
c => c.Episodes =
new List<TvdbEpisode>(Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
All()
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
.Build())
).With(c => c.Id = seriesId).Build();
var tvDbSeries = Builder<TvdbEpisode>.CreateListOfSize(episodeCount).
All()
.With(l => l.Language = new TvdbLanguage(0, "eng", "a"))
.Build();
var fakeSeries = Builder<Series>.CreateNew()
.With(c => c.SeriesId = seriesId)
@ -236,5 +222,15 @@ namespace NzbDrone.Core.Test.ProviderTests
var result = db.Fetch<Episode>();
result.Should().HaveCount(1);
}
[Test]
public void should_not_do_anything_if_episode_list_is_empty()
{
WithStrictMocker();
var fakeSeries = Builder<Series>.CreateNew().Build();
Mocker.Resolve<EpisodeProvider>().DeleteEpisodesNotInTvdb(fakeSeries, new List<TvdbEpisode>());
}
}
}

View File

@ -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<HttpProvider>().Setup(s => s.DownloadString(It.IsAny<string>()))
.Throws(new WebException())
.Verifiable();
Mocker.Resolve<ReferenceDataProvider>().UpdateDailySeries();
ExceptionVerification.ExpectedWarns(1);
Mocker.VerifyAllMocks();
}
}
}

View File

@ -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<SeasonProvider>().Add(seriesId, seasonNumber);
//Assert
var result = Db.Fetch<Season>();
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<SeasonProvider>().Add(seriesId, seasonNumber, isIgnored);
//Assert
var result = Db.Fetch<Season>();
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<Season>.CreateNew().Build();
Db.Insert(fakeSeason);
//Act
Mocker.Resolve<SeasonProvider>().Delete(fakeSeason.SeriesId, fakeSeason.SeasonNumber);
//Assert
var result = Db.Fetch<Season>();
result.Should().BeEmpty();
}
[Test]
public void SetIgnore_should_update_ignored_status()
{
WithRealDb();
var fakeSeason = Builder<Season>.CreateNew()
.With(s => s.Ignored = false)
.With(s => s.Ignored = !ignoreFlag)
.Build();
var fakeEpisodes = Builder<Episode>.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<SeasonProvider>().SetIgnore(fakeSeason.SeriesId, fakeSeason.SeasonNumber, true);
Mocker.Resolve<SeasonProvider>().SetIgnore(fakeSeason.SeriesId, fakeSeason.SeasonNumber, ignoreFlag);
//Assert
var result = Db.SingleOrDefault<Season>(id);
result.Ignored.Should().BeTrue();
var season = Db.SingleOrDefault<Season>(id);
season.Ignored.Should().Be(ignoreFlag);
var episodes = Db.Fetch<Episode>();
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<Season>.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<SeasonProvider>().IsIgnored(fakeSeason.SeriesId, fakeSeason.SeasonNumber);
//Assert
result.Should().Be(fakeSeason.Ignored);
Db.Fetch<Season>().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<SeasonProvider>().IsIgnored(10, 0);
//Assert
result.Should().BeTrue();
Db.Fetch<Season>().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<SeasonProvider>().IsIgnored(10, 1);
//Assert
result.Should().BeFalse();
Db.Fetch<Season>().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<Season>.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<SeasonProvider>().IsIgnored(10, 5);
//Assert
result.Should().BeFalse();
Db.Fetch<Season>().Should().HaveCount(2);
}
[Test]
public void IsIgnored_should_return_true_if_not_in_db_and_previous_season_is_ignored()
{
//Setup
WithRealDb();
var lastSeason = Builder<Season>.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<SeasonProvider>().IsIgnored(10, 5);
//Assert
result.Should().BeTrue();
Db.Fetch<Season>().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<SeasonProvider>().IsIgnored(10, 5);
//Assert
result.Should().BeFalse();
Db.Fetch<Season>().Should().HaveCount(1);
Assert.Throws<InvalidOperationException>(() => Mocker.Resolve<SeasonProvider>().IsIgnored(10, 0));
}
[Test]
@ -211,9 +91,6 @@ namespace NzbDrone.Core.Test.ProviderTests
{
const int seriesId = 10;
//Setup
WithRealDb();
var season = Builder<Season>.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<SeasonProvider>().EnsureSeasons(12, seasons);
Mocker.Resolve<SeasonProvider>().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<SeasonProvider>().EnsureSeasons(12, seasonsA);
Mocker.Resolve<SeasonProvider>().GetSeasons(12).SequenceEqual(seasonsA);
Mocker.Resolve<SeasonProvider>().EnsureSeasons(12, seasonsB);
Mocker.Resolve<SeasonProvider>().GetSeasons(12).SequenceEqual(seasonsB);
}
[Test]
public void EnsureSeason_marks_season_zero_as_ignored()
{
var seasons = new[] { 0, 1, 2, 3 };
Mocker.Resolve<SeasonProvider>().EnsureSeasons(12, seasons);
Db.Fetch<Season>().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<SeasonProvider>().EnsureSeasons(12, seasons);
Db.Fetch<Season>().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<SeasonProvider>().EnsureSeasons(1, seriesA);
Mocker.Resolve<SeasonProvider>().EnsureSeasons(2, seriesB);
Mocker.Resolve<SeasonProvider>().GetSeasons(1).Should().Equal(seriesA);
Mocker.Resolve<SeasonProvider>().GetSeasons(2).Should().Equal(seriesB);
}
[Test]
public void GetSeason_should_return_emptylist_if_series_doesnt_exist()
{
Mocker.Resolve<SeasonProvider>().GetSeasons(1).Should().BeEmpty();
}
}
}

View File

@ -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<Series>.CreateListOfSize(3).Build();
var fakeEpisodes = Builder<Episode>.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();
}
}
}

View File

@ -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
)");
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}
}

View File

@ -222,6 +222,7 @@
<Compile Include="Datastore\MigrationLogger.cs" />
<Compile Include="Datastore\MigrationsHelper.cs" />
<Compile Include="Datastore\CustomeMapper.cs" />
<Compile Include="Datastore\Migrations\Migration20120227.cs" />
<Compile Include="Datastore\Migrations\Migration20120220.cs" />
<Compile Include="Datastore\Migrations\Migration20120123.cs" />
<Compile Include="Datastore\Migrations\Migration20120118.cs" />

View File

@ -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<Episode>();
var newList = new List<Episode>();
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<int>("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<TvdbEpisode> 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})",

View File

@ -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)

View File

@ -1,2 +1,2 @@

<div class="infoBox">It looks like you haven't added any series to NzbDrone. @Html.ActionLink("Click here to add one.", "Index", "AddSeries")</div>
<div class="infoBox">It looks like you haven't added any series to NzbDrone. @*@Html.ActionLink("Click here to add one.", "Index", "AddSeries")*@</div>

View File

@ -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();
}