From b232cc308153178bef9fb37aecf7fa4b5917de77 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 20 Jul 2016 15:53:49 -0700 Subject: [PATCH] Fixed: Delete all history for series when series is removed from Sonarr --- src/NzbDrone.Core/History/HistoryRepository.cs | 6 ++++++ src/NzbDrone.Core/History/HistoryService.cs | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core/History/HistoryRepository.cs b/src/NzbDrone.Core/History/HistoryRepository.cs index c8bc10f04..35199a878 100644 --- a/src/NzbDrone.Core/History/HistoryRepository.cs +++ b/src/NzbDrone.Core/History/HistoryRepository.cs @@ -15,6 +15,7 @@ public interface IHistoryRepository : IBasicRepository History MostRecentForDownloadId(string downloadId); List FindByDownloadId(string downloadId); List FindDownloadHistory(int idSeriesId, QualityModel quality); + void DeleteForSeries(int seriesId); } public class HistoryRepository : BasicRepository, IHistoryRepository @@ -63,6 +64,11 @@ public List FindDownloadHistory(int idSeriesId, QualityModel quality) ).ToList(); } + public void DeleteForSeries(int seriesId) + { + Delete(c => c.SeriesId == seriesId); + } + protected override SortBuilder GetPagedQuery(QueryBuilder query, PagingSpec pagingSpec) { var baseQuery = query.Join(JoinType.Inner, h => h.Series, (h, s) => h.SeriesId == s.Id) diff --git a/src/NzbDrone.Core/History/HistoryService.cs b/src/NzbDrone.Core/History/HistoryService.cs index 1db2e7778..9459a4fcc 100644 --- a/src/NzbDrone.Core/History/HistoryService.cs +++ b/src/NzbDrone.Core/History/HistoryService.cs @@ -13,6 +13,7 @@ using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Profiles; using NzbDrone.Core.Qualities; +using NzbDrone.Core.Tv.Events; namespace NzbDrone.Core.History { @@ -31,7 +32,8 @@ public class HistoryService : IHistoryService, IHandle, IHandle, IHandle, - IHandle + IHandle, + IHandle { private readonly IHistoryRepository _historyRepository; private readonly Logger _logger; @@ -255,5 +257,10 @@ public void Handle(EpisodeFileDeletedEvent message) _historyRepository.Insert(history); } } + + public void Handle(SeriesDeletedEvent message) + { + _historyRepository.DeleteForSeries(message.Series.Id); + } } } \ No newline at end of file