mirror of https://github.com/lidarr/Lidarr
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 FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Housekeeping.Housekeepers;
|
using NzbDrone.Core.Housekeeping.Housekeepers;
|
||||||
using NzbDrone.Core.MediaFiles;
|
using NzbDrone.Core.MediaFiles;
|
||||||
|
using NzbDrone.Core.Metadata;
|
||||||
using NzbDrone.Core.Metadata.Files;
|
using NzbDrone.Core.Metadata.Files;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Core.Tv;
|
using NzbDrone.Core.Tv;
|
||||||
|
@ -81,5 +82,43 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
||||||
Subject.Clean();
|
Subject.Clean();
|
||||||
AllStoredModels.Should().HaveCount(1);
|
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 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
|
|
||||||
DeleteOrphanedBySeries();
|
DeleteOrphanedBySeries();
|
||||||
DeleteOrphanedByEpisodeFile();
|
DeleteOrphanedByEpisodeFile();
|
||||||
|
DeleteWhereEpisodeFileIsZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DeleteOrphanedBySeries()
|
private void DeleteOrphanedBySeries()
|
||||||
|
@ -46,5 +47,16 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||||
WHERE MetadataFiles.EpisodeFileId > 0
|
WHERE MetadataFiles.EpisodeFileId > 0
|
||||||
AND EpisodeFiles.Id IS NULL)");
|
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