mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Cleanup episode metadata/image files that aren't properly attached to files
This commit is contained in:
parent
78ded70b39
commit
9c858445a3
@ -3,6 +3,7 @@
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Housekeeping.Housekeepers;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Metadata;
|
||||
using NzbDrone.Core.Metadata.Files;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
@ -81,5 +82,43 @@ public void should_not_delete_metadata_files_that_have_a_coresponding_episode_fi
|
||||
Subject.Clean();
|
||||
AllStoredModels.Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_episode_metadata_files_that_have_episodefileid_of_zero()
|
||||
{
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.BuildNew();
|
||||
|
||||
Db.Insert(series);
|
||||
|
||||
var metadataFile = Builder<MetadataFile>.CreateNew()
|
||||
.With(m => m.SeriesId = series.Id)
|
||||
.With(m => m.Type = MetadataType.EpisodeMetadata)
|
||||
.With(m => m.EpisodeFileId = 0)
|
||||
.BuildNew();
|
||||
|
||||
Db.Insert(metadataFile);
|
||||
Subject.Clean();
|
||||
AllStoredModels.Should().HaveCount(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_episode_image_files_that_have_episodefileid_of_zero()
|
||||
{
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.BuildNew();
|
||||
|
||||
Db.Insert(series);
|
||||
|
||||
var metadataFile = Builder<MetadataFile>.CreateNew()
|
||||
.With(m => m.SeriesId = series.Id)
|
||||
.With(m => m.Type = MetadataType.EpisodeImage)
|
||||
.With(m => m.EpisodeFileId = 0)
|
||||
.BuildNew();
|
||||
|
||||
Db.Insert(metadataFile);
|
||||
Subject.Clean();
|
||||
AllStoredModels.Should().HaveCount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ public void Clean()
|
||||
|
||||
DeleteOrphanedBySeries();
|
||||
DeleteOrphanedByEpisodeFile();
|
||||
DeleteWhereEpisodeFileIsZero();
|
||||
}
|
||||
|
||||
private void DeleteOrphanedBySeries()
|
||||
@ -46,5 +47,16 @@ LEFT OUTER JOIN EpisodeFiles
|
||||
WHERE MetadataFiles.EpisodeFileId > 0
|
||||
AND EpisodeFiles.Id IS NULL)");
|
||||
}
|
||||
|
||||
private void DeleteWhereEpisodeFileIsZero()
|
||||
{
|
||||
var mapper = _database.GetDataMapper();
|
||||
|
||||
mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles
|
||||
WHERE Id IN (
|
||||
SELECT Id FROM MetadataFiles
|
||||
WHERE Type IN (2, 5)
|
||||
AND EpisodeFileId = 0)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user