Fixed: Prevent bulk add failure on single validation error for Lists

Fixes #3959
This commit is contained in:
Qstick 2020-09-15 15:52:42 -04:00 committed by GitHub
parent ae1881a68c
commit eb0bce8dbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 11 deletions

View File

@ -105,7 +105,7 @@ namespace NzbDrone.Core.Test.ImportListTests
Subject.Execute(new ImportListSyncCommand()); Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<IAddSeriesService>() Mocker.GetMock<IAddSeriesService>()
.Verify(v => v.AddSeries(It.Is<List<Series>>(t=>t.Count == 0))); .Verify(v => v.AddSeries(It.Is<List<Series>>(t=>t.Count == 0), It.IsAny<bool>()));
} }
[TestCase(MonitorTypes.None, false)] [TestCase(MonitorTypes.None, false)]
@ -118,7 +118,7 @@ namespace NzbDrone.Core.Test.ImportListTests
Subject.Execute(new ImportListSyncCommand()); Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<IAddSeriesService>() Mocker.GetMock<IAddSeriesService>()
.Verify(v => v.AddSeries(It.Is<List<Series>>(t => t.Count == 1 && t.First().Monitored == expectedSeriesMonitored))); .Verify(v => v.AddSeries(It.Is<List<Series>>(t => t.Count == 1 && t.First().Monitored == expectedSeriesMonitored), It.IsAny<bool>()));
} }
[Test] [Test]
@ -130,7 +130,7 @@ namespace NzbDrone.Core.Test.ImportListTests
Subject.Execute(new ImportListSyncCommand()); Subject.Execute(new ImportListSyncCommand());
Mocker.GetMock<IAddSeriesService>() Mocker.GetMock<IAddSeriesService>()
.Verify(v => v.AddSeries(It.Is<List<Series>>(t => t.Count == 0))); .Verify(v => v.AddSeries(It.Is<List<Series>>(t => t.Count == 0), It.IsAny<bool>()));
} }
} }
} }

View File

@ -136,7 +136,7 @@ namespace NzbDrone.Core.ImportLists
} }
} }
_addSeriesService.AddSeries(seriesToAdd); _addSeriesService.AddSeries(seriesToAdd, true);
var message = string.Format("Import List Sync Completed. Items found: {0}, Series added: {1}", reports.Count, seriesToAdd.Count); var message = string.Format("Import List Sync Completed. Items found: {0}, Series added: {1}", reports.Count, seriesToAdd.Count);

View File

@ -16,7 +16,7 @@ namespace NzbDrone.Core.Tv
public interface IAddSeriesService public interface IAddSeriesService
{ {
Series AddSeries(Series newSeries); Series AddSeries(Series newSeries);
List<Series> AddSeries(List<Series> newSeries); List<Series> AddSeries(List<Series> newSeries, bool ignoreErrors = false);
} }
public class AddSeriesService : IAddSeriesService public class AddSeriesService : IAddSeriesService
@ -53,19 +53,30 @@ namespace NzbDrone.Core.Tv
return newSeries; return newSeries;
} }
public List<Series> AddSeries(List<Series> newSeries) public List<Series> AddSeries(List<Series> newSeries, bool ignoreErrors = false)
{ {
var added = DateTime.UtcNow; var added = DateTime.UtcNow;
var seriesToAdd = new List<Series>(); var seriesToAdd = new List<Series>();
foreach (var s in newSeries) foreach (var s in newSeries)
{ {
// TODO: Verify if adding skyhook data will be slow try
{
var series = AddSkyhookData(s); var series = AddSkyhookData(s);
series = SetPropertiesAndValidate(series); series = SetPropertiesAndValidate(series);
series.Added = added; series.Added = added;
seriesToAdd.Add(series); seriesToAdd.Add(series);
} }
catch (ValidationException ex)
{
if (!ignoreErrors)
{
throw;
}
_logger.Debug("tvdbid {0} was not added due to validation failures. {1}", s.TvdbId, ex.Message);
}
}
return _seriesService.AddSeries(seriesToAdd); return _seriesService.AddSeries(seriesToAdd);
} }