2011-05-12 02:53:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Model.Notification;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using SubSonic.Repository;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers.Jobs
|
|
|
|
|
{
|
|
|
|
|
public class DeleteSeriesJob : IJob
|
|
|
|
|
{
|
|
|
|
|
private readonly SeriesProvider _seriesProvider;
|
2011-05-13 00:55:26 +00:00
|
|
|
|
private readonly SeasonProvider _seasonProvider;
|
|
|
|
|
private readonly EpisodeProvider _episodeProvider;
|
|
|
|
|
private readonly MediaFileProvider _mediaFileProvider;
|
|
|
|
|
private readonly HistoryProvider _historyProvider;
|
2011-05-12 02:53:19 +00:00
|
|
|
|
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2011-05-13 00:55:26 +00:00
|
|
|
|
public DeleteSeriesJob(SeriesProvider seriesProvider, SeasonProvider seasonProvider,
|
|
|
|
|
EpisodeProvider episodeProvider, MediaFileProvider mediaFileProvider,
|
|
|
|
|
HistoryProvider historyProvider)
|
2011-05-12 02:53:19 +00:00
|
|
|
|
{
|
|
|
|
|
_seriesProvider = seriesProvider;
|
2011-05-13 00:55:26 +00:00
|
|
|
|
_seasonProvider = seasonProvider;
|
|
|
|
|
_episodeProvider = episodeProvider;
|
|
|
|
|
_mediaFileProvider = mediaFileProvider;
|
|
|
|
|
_historyProvider = historyProvider;
|
2011-05-12 02:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "Delete Series"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int DefaultInterval
|
|
|
|
|
{
|
|
|
|
|
get { return 0; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Start(ProgressNotification notification, int targetId)
|
|
|
|
|
{
|
|
|
|
|
DeleteSeries(notification, targetId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DeleteSeries(ProgressNotification notification, int seriesId)
|
|
|
|
|
{
|
|
|
|
|
Logger.Warn("Deleting Series [{0}]", seriesId);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2011-05-13 00:55:26 +00:00
|
|
|
|
var series = _seriesProvider.GetSeries(seriesId);
|
2011-05-12 02:53:19 +00:00
|
|
|
|
|
|
|
|
|
notification.CurrentMessage = String.Format("Beginning Delete of Series: {0}", series.Title);
|
|
|
|
|
|
|
|
|
|
Logger.Debug("Deleting Series from DB {0}", series.Title);
|
2011-05-13 00:55:26 +00:00
|
|
|
|
_seriesProvider.DeleteSeries(seriesId);
|
2011-05-12 02:53:19 +00:00
|
|
|
|
|
|
|
|
|
Logger.Debug("Deleting History Items from DB for Series: {0}", series.SeriesId);
|
2011-05-13 00:55:26 +00:00
|
|
|
|
series.Episodes.ForEach(e => _historyProvider.DeleteForEpisode(e.EpisodeId));
|
2011-05-12 02:53:19 +00:00
|
|
|
|
|
|
|
|
|
Logger.Debug("Deleting EpisodeFiles from DB for Series: {0}", series.SeriesId);
|
2011-05-13 00:55:26 +00:00
|
|
|
|
series.EpisodeFiles.ForEach(f => _mediaFileProvider.DeleteFromDb(f.EpisodeFileId));
|
2011-05-12 02:53:19 +00:00
|
|
|
|
|
|
|
|
|
Logger.Debug("Deleting Episodes from DB for Series: {0}", series.SeriesId);
|
2011-05-13 00:55:26 +00:00
|
|
|
|
series.Episodes.ForEach(e => _episodeProvider.DeleteEpisode(e.EpisodeId));
|
2011-05-12 02:53:19 +00:00
|
|
|
|
|
|
|
|
|
Logger.Debug("Deleting Seasons from DB for Series: {0}", series.SeriesId);
|
2011-05-13 00:55:26 +00:00
|
|
|
|
series.Seasons.ForEach(s => _seasonProvider.DeleteSeason(s.SeasonId));
|
2011-05-12 02:53:19 +00:00
|
|
|
|
|
|
|
|
|
notification.CurrentMessage = String.Format("Successfully deleted Series: {0}", series.Title);
|
|
|
|
|
Logger.Info("Successfully deleted Series [{0}]", seriesId);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.ErrorException("An error has occurred while deleting series: " + seriesId, e);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|