2013-09-18 05:28:05 +00:00
|
|
|
|
using NLog;
|
2013-09-19 00:28:25 +00:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
2013-09-18 05:28:05 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|
|
|
|
{
|
|
|
|
|
public class CleanupOrphanedEpisodes : IHousekeepingTask
|
|
|
|
|
{
|
2013-09-19 00:28:25 +00:00
|
|
|
|
private readonly IDatabase _database;
|
2013-09-18 05:28:05 +00:00
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
2013-09-19 00:28:25 +00:00
|
|
|
|
public CleanupOrphanedEpisodes(IDatabase database, Logger logger)
|
2013-09-18 05:28:05 +00:00
|
|
|
|
{
|
2013-09-19 00:28:25 +00:00
|
|
|
|
_database = database;
|
2013-09-18 05:28:05 +00:00
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clean()
|
|
|
|
|
{
|
|
|
|
|
_logger.Trace("Running orphaned episodes cleanup");
|
2013-09-19 00:28:25 +00:00
|
|
|
|
|
|
|
|
|
var mapper = _database.GetDataMapper();
|
|
|
|
|
|
|
|
|
|
mapper.ExecuteNonQuery(@"DELETE FROM Episodes
|
|
|
|
|
WHERE Id IN (
|
|
|
|
|
SELECT Episodes.Id FROM Episodes
|
|
|
|
|
LEFT OUTER JOIN Series
|
|
|
|
|
ON Episodes.SeriesId = Series.Id
|
|
|
|
|
WHERE Series.Id IS NULL)");
|
2013-09-18 05:28:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|