mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 20:12:41 +02:00
Fixed: Housekeeper for Credits (Left behind from deleted caused later add issues)
This commit is contained in:
parent
ba6ba06d9b
commit
3e5626f894
@ -0,0 +1,46 @@
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Housekeeping.Housekeepers;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Movies.Credits;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
|
||||
{
|
||||
[TestFixture]
|
||||
public class CleanupOrphanedCreditsFixture : DbTest<CleanupOrphanedCredits, Credit>
|
||||
{
|
||||
[Test]
|
||||
public void should_delete_orphaned_credit_items()
|
||||
{
|
||||
var credit = Builder<Credit>.CreateNew()
|
||||
.With(h => h.MovieId = default)
|
||||
.With(h => h.Name = "Some Credit")
|
||||
.BuildNew();
|
||||
|
||||
Db.Insert(credit);
|
||||
Subject.Clean();
|
||||
AllStoredModels.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_delete_unorphaned_credit_items()
|
||||
{
|
||||
var movie = Builder<Movie>.CreateNew().BuildNew();
|
||||
|
||||
Db.Insert(movie);
|
||||
|
||||
var credit = Builder<Credit>.CreateNew()
|
||||
.With(h => h.MovieId = default)
|
||||
.With(h => h.Name = "Some Credit")
|
||||
.With(b => b.MovieId = movie.Id)
|
||||
.BuildNew();
|
||||
|
||||
Db.Insert(credit);
|
||||
|
||||
Subject.Clean();
|
||||
AllStoredModels.Should().HaveCount(1);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using Dapper;
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.Housekeeping.Housekeepers
|
||||
{
|
||||
public class CleanupOrphanedCredits : IHousekeepingTask
|
||||
{
|
||||
private readonly IMainDatabase _database;
|
||||
|
||||
public CleanupOrphanedCredits(IMainDatabase database)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
using (var mapper = _database.OpenConnection())
|
||||
{
|
||||
mapper.Execute(@"DELETE FROM Credits
|
||||
WHERE Id IN (
|
||||
SELECT Credits.Id FROM Credits
|
||||
LEFT OUTER JOIN Movies
|
||||
ON Credits.MovieId = Movies.Id
|
||||
WHERE Movies.Id IS NULL)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user