DeleteSeriesJob now uses the providers properly.

This commit is contained in:
Mark McDowall 2011-05-12 17:55:26 -07:00
parent c5ea0dee17
commit 3cc052e9b6
3 changed files with 28 additions and 42 deletions

View File

@ -55,5 +55,15 @@ namespace NzbDrone.Core.Providers
Logger.Debug("Episode not in History. ID:{0} Q:{1} Proper:{2}", episodeId, quality, proper); Logger.Debug("Episode not in History. ID:{0} Q:{1} Proper:{2}", episodeId, quality, proper);
return false; return false;
} }
public virtual void Delete(int historyId)
{
_repository.Delete<History>(historyId);
}
public virtual void DeleteForEpisode(int episodeId)
{
_repository.DeleteMany<History>(h => h.EpisodeId == episodeId);
}
} }
} }

View File

@ -11,14 +11,22 @@ namespace NzbDrone.Core.Providers.Jobs
public class DeleteSeriesJob : IJob public class DeleteSeriesJob : IJob
{ {
private readonly SeriesProvider _seriesProvider; private readonly SeriesProvider _seriesProvider;
private readonly IRepository _repository; private readonly SeasonProvider _seasonProvider;
private readonly EpisodeProvider _episodeProvider;
private readonly MediaFileProvider _mediaFileProvider;
private readonly HistoryProvider _historyProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public DeleteSeriesJob(IRepository repository, SeriesProvider seriesProvider) public DeleteSeriesJob(SeriesProvider seriesProvider, SeasonProvider seasonProvider,
EpisodeProvider episodeProvider, MediaFileProvider mediaFileProvider,
HistoryProvider historyProvider)
{ {
_repository = repository;
_seriesProvider = seriesProvider; _seriesProvider = seriesProvider;
_seasonProvider = seasonProvider;
_episodeProvider = episodeProvider;
_mediaFileProvider = mediaFileProvider;
_historyProvider = historyProvider;
} }
public string Name public string Name
@ -42,25 +50,24 @@ namespace NzbDrone.Core.Providers.Jobs
try try
{ {
var series = _repository.Single<Series>(seriesId); var series = _seriesProvider.GetSeries(seriesId);
notification.CurrentMessage = String.Format("Beginning Delete of Series: {0}", series.Title); notification.CurrentMessage = String.Format("Beginning Delete of Series: {0}", series.Title);
Logger.Debug("Deleting Series from DB {0}", series.Title); Logger.Debug("Deleting Series from DB {0}", series.Title);
_repository.Delete<Series>(seriesId); _seriesProvider.DeleteSeries(seriesId);
Logger.Debug("Deleting History Items from DB for Series: {0}", series.SeriesId); Logger.Debug("Deleting History Items from DB for Series: {0}", series.SeriesId);
var episodes = series.Episodes.Select(e => e.EpisodeId).ToList(); series.Episodes.ForEach(e => _historyProvider.DeleteForEpisode(e.EpisodeId));
episodes.ForEach(e => _repository.DeleteMany<History>(h => h.EpisodeId == e));
Logger.Debug("Deleting EpisodeFiles from DB for Series: {0}", series.SeriesId); Logger.Debug("Deleting EpisodeFiles from DB for Series: {0}", series.SeriesId);
_repository.DeleteMany(series.EpisodeFiles); series.EpisodeFiles.ForEach(f => _mediaFileProvider.DeleteFromDb(f.EpisodeFileId));
Logger.Debug("Deleting Episodes from DB for Series: {0}", series.SeriesId); Logger.Debug("Deleting Episodes from DB for Series: {0}", series.SeriesId);
_repository.DeleteMany(series.Episodes); series.Episodes.ForEach(e => _episodeProvider.DeleteEpisode(e.EpisodeId));
Logger.Debug("Deleting Seasons from DB for Series: {0}", series.SeriesId); Logger.Debug("Deleting Seasons from DB for Series: {0}", series.SeriesId);
_repository.DeleteMany(series.Seasons); series.Seasons.ForEach(s => _seasonProvider.DeleteSeason(s.SeasonId));
notification.CurrentMessage = String.Format("Successfully deleted Series: {0}", series.Title); notification.CurrentMessage = String.Format("Successfully deleted Series: {0}", series.Title);
Logger.Info("Successfully deleted Series [{0}]", seriesId); Logger.Info("Successfully deleted Series [{0}]", seriesId);

View File

@ -119,38 +119,7 @@ namespace NzbDrone.Core.Providers
public virtual void DeleteSeries(int seriesId) public virtual void DeleteSeries(int seriesId)
{ {
Logger.Warn("Deleting Series [{0}]", seriesId); _repository.Delete<Series>(seriesId);
try
{
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
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));
Logger.Debug("Deleting EpisodeFiles from DB for Series: {0}", series.SeriesId);
_repository.DeleteMany(series.EpisodeFiles);
Logger.Debug("Deleting Episodes from DB for Series: {0}", series.SeriesId);
_repository.DeleteMany(series.Episodes);
Logger.Debug("Deleting Seasons from DB for Series: {0}", series.SeriesId);
_repository.DeleteMany(series.Seasons);
Logger.Debug("Deleting Series from DB {0}", series.Title);
_repository.Delete<Series>(seriesId);
Logger.Info("Successfully deleted Series [{0}]", seriesId);
}
catch (Exception e)
{
Logger.ErrorException("An error has occurred while deleting series.", e);
throw;
}
} }
public virtual bool SeriesPathExists(string cleanPath) public virtual bool SeriesPathExists(string cleanPath)