2013-09-18 08:28:05 +03:00
|
|
|
using NLog;
|
2013-09-19 03:28:25 +03:00
|
|
|
using NzbDrone.Core.Datastore;
|
2013-09-18 08:28:05 +03:00
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Housekeeping.Housekeepers
|
|
|
|
{
|
|
|
|
public class CleanupOrphanedEpisodes : IHousekeepingTask
|
|
|
|
{
|
2013-09-19 03:28:25 +03:00
|
|
|
private readonly IDatabase _database;
|
2013-09-18 08:28:05 +03:00
|
|
|
private readonly Logger _logger;
|
|
|
|
|
2013-09-19 03:28:25 +03:00
|
|
|
public CleanupOrphanedEpisodes(IDatabase database, Logger logger)
|
2013-09-18 08:28:05 +03:00
|
|
|
{
|
2013-09-19 03:28:25 +03:00
|
|
|
_database = database;
|
2013-09-18 08:28:05 +03:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Clean()
|
|
|
|
{
|
|
|
|
_logger.Trace("Running orphaned episodes cleanup");
|
2013-09-19 03:28:25 +03: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 08:28:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|