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());
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)]
@ -118,7 +118,7 @@ namespace NzbDrone.Core.Test.ImportListTests
Subject.Execute(new ImportListSyncCommand());
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]
@ -130,7 +130,7 @@ namespace NzbDrone.Core.Test.ImportListTests
Subject.Execute(new ImportListSyncCommand());
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);

View File

@ -16,7 +16,7 @@ namespace NzbDrone.Core.Tv
public interface IAddSeriesService
{
Series AddSeries(Series newSeries);
List<Series> AddSeries(List<Series> newSeries);
List<Series> AddSeries(List<Series> newSeries, bool ignoreErrors = false);
}
public class AddSeriesService : IAddSeriesService
@ -53,18 +53,29 @@ namespace NzbDrone.Core.Tv
return newSeries;
}
public List<Series> AddSeries(List<Series> newSeries)
public List<Series> AddSeries(List<Series> newSeries, bool ignoreErrors = false)
{
var added = DateTime.UtcNow;
var seriesToAdd = new List<Series>();
foreach (var s in newSeries)
{
// TODO: Verify if adding skyhook data will be slow
var series = AddSkyhookData(s);
series = SetPropertiesAndValidate(series);
series.Added = added;
seriesToAdd.Add(series);
try
{
var series = AddSkyhookData(s);
series = SetPropertiesAndValidate(series);
series.Added = added;
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);