diff --git a/NzbDrone.Core/Providers/Jobs/DeleteSeriesJob.cs b/NzbDrone.Core/Providers/Jobs/DeleteSeriesJob.cs index 4ab634aa8..33584bdef 100644 --- a/NzbDrone.Core/Providers/Jobs/DeleteSeriesJob.cs +++ b/NzbDrone.Core/Providers/Jobs/DeleteSeriesJob.cs @@ -11,22 +11,12 @@ namespace NzbDrone.Core.Providers.Jobs public class DeleteSeriesJob : IJob { private readonly SeriesProvider _seriesProvider; - private readonly SeasonProvider _seasonProvider; - private readonly EpisodeProvider _episodeProvider; - private readonly MediaFileProvider _mediaFileProvider; - private readonly HistoryProvider _historyProvider; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public DeleteSeriesJob(SeriesProvider seriesProvider, SeasonProvider seasonProvider, - EpisodeProvider episodeProvider, MediaFileProvider mediaFileProvider, - HistoryProvider historyProvider) + public DeleteSeriesJob(SeriesProvider seriesProvider) { _seriesProvider = seriesProvider; - _seasonProvider = seasonProvider; - _episodeProvider = episodeProvider; - _mediaFileProvider = mediaFileProvider; - _historyProvider = historyProvider; } public string Name @@ -57,18 +47,6 @@ private void DeleteSeries(ProgressNotification notification, int seriesId) Logger.Debug("Deleting Series from DB {0}", series.Title); _seriesProvider.DeleteSeries(seriesId); - Logger.Debug("Deleting History Items from DB for Series: {0}", series.SeriesId); - series.Episodes.ForEach(e => _historyProvider.DeleteForEpisode(e.EpisodeId)); - - Logger.Debug("Deleting EpisodeFiles from DB for Series: {0}", series.SeriesId); - series.EpisodeFiles.ForEach(f => _mediaFileProvider.DeleteFromDb(f.EpisodeFileId)); - - Logger.Debug("Deleting Episodes from DB for Series: {0}", series.SeriesId); - series.Episodes.ForEach(e => _episodeProvider.DeleteEpisode(e.EpisodeId)); - - Logger.Debug("Deleting Seasons from DB for Series: {0}", series.SeriesId); - series.Seasons.ForEach(s => _seasonProvider.DeleteSeason(s.SeasonId)); - notification.CurrentMessage = String.Format("Successfully deleted Series: {0}", series.Title); Logger.Info("Successfully deleted Series [{0}]", seriesId); } diff --git a/NzbDrone.Core/Providers/SeriesProvider.cs b/NzbDrone.Core/Providers/SeriesProvider.cs index 9117b511f..b3a9b823f 100644 --- a/NzbDrone.Core/Providers/SeriesProvider.cs +++ b/NzbDrone.Core/Providers/SeriesProvider.cs @@ -119,7 +119,34 @@ public virtual void UpdateSeries(Series series) public virtual void DeleteSeries(int seriesId) { + Logger.Warn("Deleting Series [{0}]", seriesId); + var series = _repository.Single(seriesId); + + //Delete Files, Episdes, Seasons then the Series + //Can't use providers because episode provider needs series provider - Cyclic Dependency Injection, this will work + + //Delete History Items for any episodes that belong to this series + Logger.Debug("Deleting History Items from DB for Series: {0}", series.SeriesId); + var episodes = series.Episodes.Select(e => e.EpisodeId).ToList(); + episodes.ForEach(e => _repository.DeleteMany(h => h.EpisodeId == e)); + + //Delete all episode files from the DB for episodes in this series + Logger.Debug("Deleting EpisodeFiles from DB for Series: {0}", series.SeriesId); + _repository.DeleteMany(series.EpisodeFiles); + + //Delete all episodes for this series from the DB + Logger.Debug("Deleting Episodes from DB for Series: {0}", series.SeriesId); + _repository.DeleteMany(series.Episodes); + + //Delete seasons for this series from the DB + Logger.Debug("Deleting Seasons from DB for Series: {0}", series.SeriesId); + _repository.DeleteMany(series.Seasons); + + //Delete the Series + Logger.Debug("Deleting Series from DB {0}", series.Title); _repository.Delete(seriesId); + + Logger.Info("Successfully deleted Series [{0}]", seriesId); } public virtual bool SeriesPathExists(string cleanPath)