Fixed: SeasonPass didn't update Series monitored flag if only those were changed.

pull/4/head
Taloth Saldono 9 years ago
parent 97cdcb8b19
commit f7859c8eb5

@ -66,6 +66,18 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeMonitoredServiceTests
_series.Seasons = new List<Season>{new Season { Monitored = false, SeasonNumber = 0 }};
}
[Test]
public void should_be_able_to_monitor_series_without_changing_episodes()
{
Subject.SetEpisodeMonitoredStatus(_series, null);
Mocker.GetMock<ISeriesService>()
.Verify(v => v.UpdateSeries(It.IsAny<Series>()), Times.Once());
Mocker.GetMock<IEpisodeService>()
.Verify(v => v.UpdateEpisodes(It.IsAny<List<Episode>>()), Times.Never());
}
[Test]
public void should_be_able_to_monitor_all_episodes()
{

@ -26,72 +26,76 @@ namespace NzbDrone.Core.Tv
public void SetEpisodeMonitoredStatus(Series series, MonitoringOptions monitoringOptions)
{
_logger.Debug("[{0}] Setting episode monitored status.", series.Title);
var episodes = _episodeService.GetEpisodeBySeries(series.Id);
if (monitoringOptions.IgnoreEpisodesWithFiles)
if (monitoringOptions != null)
{
_logger.Debug("Ignoring Episodes with Files");
ToggleEpisodesMonitoredState(episodes.Where(e => e.HasFile), false);
}
_logger.Debug("[{0}] Setting episode monitored status.", series.Title);
else
{
_logger.Debug("Monitoring Episodes with Files");
ToggleEpisodesMonitoredState(episodes.Where(e => e.HasFile), true);
}
if (monitoringOptions.IgnoreEpisodesWithoutFiles)
{
_logger.Debug("Ignoring Episodes without Files");
ToggleEpisodesMonitoredState(episodes.Where(e => !e.HasFile && e.AirDateUtc.HasValue && e.AirDateUtc.Value.Before(DateTime.UtcNow)), false);
}
var episodes = _episodeService.GetEpisodeBySeries(series.Id);
else
{
_logger.Debug("Monitoring Episodes without Files");
ToggleEpisodesMonitoredState(episodes.Where(e => !e.HasFile && e.AirDateUtc.HasValue && e.AirDateUtc.Value.Before(DateTime.UtcNow)), true);
}
var lastSeason = series.Seasons.Select(s => s.SeasonNumber).MaxOrDefault();
if (monitoringOptions.IgnoreEpisodesWithFiles)
{
_logger.Debug("Ignoring Episodes with Files");
ToggleEpisodesMonitoredState(episodes.Where(e => e.HasFile), false);
}
foreach (var s in series.Seasons)
{
var season = s;
else
{
_logger.Debug("Monitoring Episodes with Files");
ToggleEpisodesMonitoredState(episodes.Where(e => e.HasFile), true);
}
if (season.Monitored)
if (monitoringOptions.IgnoreEpisodesWithoutFiles)
{
if (!monitoringOptions.IgnoreEpisodesWithFiles && !monitoringOptions.IgnoreEpisodesWithoutFiles)
{
ToggleEpisodesMonitoredState(episodes.Where(e => e.SeasonNumber == season.SeasonNumber), true);
}
_logger.Debug("Ignoring Episodes without Files");
ToggleEpisodesMonitoredState(episodes.Where(e => !e.HasFile && e.AirDateUtc.HasValue && e.AirDateUtc.Value.Before(DateTime.UtcNow)), false);
}
else
{
if (!monitoringOptions.IgnoreEpisodesWithFiles && !monitoringOptions.IgnoreEpisodesWithoutFiles)
_logger.Debug("Monitoring Episodes without Files");
ToggleEpisodesMonitoredState(episodes.Where(e => !e.HasFile && e.AirDateUtc.HasValue && e.AirDateUtc.Value.Before(DateTime.UtcNow)), true);
}
var lastSeason = series.Seasons.Select(s => s.SeasonNumber).MaxOrDefault();
foreach (var s in series.Seasons)
{
var season = s;
if (season.Monitored)
{
ToggleEpisodesMonitoredState(episodes.Where(e => e.SeasonNumber == season.SeasonNumber), false);
if (!monitoringOptions.IgnoreEpisodesWithFiles && !monitoringOptions.IgnoreEpisodesWithoutFiles)
{
ToggleEpisodesMonitoredState(episodes.Where(e => e.SeasonNumber == season.SeasonNumber), true);
}
}
else if (season.SeasonNumber == 0)
else
{
ToggleEpisodesMonitoredState(episodes.Where(e => e.SeasonNumber == season.SeasonNumber), false);
if (!monitoringOptions.IgnoreEpisodesWithFiles && !monitoringOptions.IgnoreEpisodesWithoutFiles)
{
ToggleEpisodesMonitoredState(episodes.Where(e => e.SeasonNumber == season.SeasonNumber), false);
}
else if (season.SeasonNumber == 0)
{
ToggleEpisodesMonitoredState(episodes.Where(e => e.SeasonNumber == season.SeasonNumber), false);
}
}
}
if (season.SeasonNumber < lastSeason)
{
if (episodes.Where(e => e.SeasonNumber == season.SeasonNumber).All(e => !e.Monitored))
if (season.SeasonNumber < lastSeason)
{
season.Monitored = false;
if (episodes.Where(e => e.SeasonNumber == season.SeasonNumber).All(e => !e.Monitored))
{
season.Monitored = false;
}
}
}
_episodeService.UpdateEpisodes(episodes);
}
_seriesService.UpdateSeries(series);
_episodeService.UpdateEpisodes(episodes);
}
private void ToggleEpisodesMonitoredState(IEnumerable<Episode> episodes, bool monitored)

Loading…
Cancel
Save