1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-21 01:49:57 +02:00
Sonarr/NzbDrone.Core/Housekeeping/Housekeepers/CleanupOrphanedEpisodes.cs
2013-09-18 22:49:36 -07:00

33 lines
985 B
C#

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