Returned series deletion back to SeriesProvider.

This commit is contained in:
Mark McDowall 2011-05-15 16:35:45 -07:00
parent 46e7c6f495
commit 13da5ff7f7
2 changed files with 28 additions and 23 deletions

View File

@ -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 @@ namespace NzbDrone.Core.Providers.Jobs
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);
}

View File

@ -119,7 +119,34 @@ namespace NzbDrone.Core.Providers
public virtual void DeleteSeries(int seriesId)
{
Logger.Warn("Deleting Series [{0}]", seriesId);
var series = _repository.Single<Series>(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<History>(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<Series>(seriesId);
Logger.Info("Successfully deleted Series [{0}]", seriesId);
}
public virtual bool SeriesPathExists(string cleanPath)