From f246fa87dde5900d2a6fbc67e62e8475ede0db64 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 21 May 2018 04:41:59 -0400 Subject: [PATCH] Fixed: Purge alt titles on movie delete (#2796) Fixes #2542 --- .../AlternativeTitleRepository.cs | 8 ++++- .../AlternativeTitleService.cs | 32 +++++++++---------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/NzbDrone.Core/Movies/AlternativeTitles/AlternativeTitleRepository.cs b/src/NzbDrone.Core/Movies/AlternativeTitles/AlternativeTitleRepository.cs index 539e31d8e..1759adced 100644 --- a/src/NzbDrone.Core/Movies/AlternativeTitles/AlternativeTitleRepository.cs +++ b/src/NzbDrone.Core/Movies/AlternativeTitles/AlternativeTitleRepository.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using NzbDrone.Common.Extensions; using NzbDrone.Core.Datastore; @@ -10,6 +10,7 @@ public interface IAlternativeTitleRepository : IBasicRepository FindBySourceIds(List sourceIds); + List FindByMovieId(int movieId); } public class AlternativeTitleRepository : BasicRepository, IAlternativeTitleRepository @@ -31,5 +32,10 @@ public List FindBySourceIds(List sourceIds) { return Query.Where(t => t.SourceId.In(sourceIds)).ToList(); } + + public List FindByMovieId(int movieId) + { + return Query.Where(t => t.MovieId == movieId).ToList(); + } } } diff --git a/src/NzbDrone.Core/Movies/AlternativeTitles/AlternativeTitleService.cs b/src/NzbDrone.Core/Movies/AlternativeTitles/AlternativeTitleService.cs index cab0522dd..1d697ed12 100644 --- a/src/NzbDrone.Core/Movies/AlternativeTitles/AlternativeTitleService.cs +++ b/src/NzbDrone.Core/Movies/AlternativeTitles/AlternativeTitleService.cs @@ -1,31 +1,22 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; using NLog; -using NzbDrone.Common.EnsureThat; -using NzbDrone.Common.Extensions; -using NzbDrone.Core.Messaging.Events; -using NzbDrone.Core.Organizer; -using NzbDrone.Core.Movies; -using NzbDrone.Core.Movies.Events; -using NzbDrone.Core.MediaFiles; -using NzbDrone.Core.MediaFiles.Events; -using NzbDrone.Core.Datastore; using NzbDrone.Core.Configuration; +using NzbDrone.Core.Messaging.Events; +using System.Collections.Generic; +using System.Linq; +using NzbDrone.Core.Movies.Events; namespace NzbDrone.Core.Movies.AlternativeTitles { public interface IAlternativeTitleService { - List GetAllTitlesForMovie(Movie movie); + List GetAllTitlesForMovie(int movieId); AlternativeTitle AddAltTitle(AlternativeTitle title, Movie movie); List AddAltTitles(List titles, Movie movie); AlternativeTitle GetById(int id); void DeleteNotEnoughVotes(List mappingsTitles); } - public class AlternativeTitleService : IAlternativeTitleService + public class AlternativeTitleService : IAlternativeTitleService, IHandleAsync { private readonly IAlternativeTitleRepository _titleRepo; private readonly IConfigService _configService; @@ -44,9 +35,9 @@ public AlternativeTitleService(IAlternativeTitleRepository titleRepo, _logger = logger; } - public List GetAllTitlesForMovie(Movie movie) + public List GetAllTitlesForMovie(int movieId) { - return _titleRepo.All().ToList(); + return _titleRepo.FindByMovieId(movieId).ToList(); } public AlternativeTitle AddAltTitle(AlternativeTitle title, Movie movie) @@ -78,5 +69,12 @@ public void DeleteNotEnoughVotes(List mappingsTitles) var realT = _titleRepo.FindBySourceIds(toRemove.Select(t => t.SourceId).ToList()); _titleRepo.DeleteMany(realT); } + + public void HandleAsync(MovieDeletedEvent message) + { + var title = GetAllTitlesForMovie(message.Movie.Id); + _titleRepo.DeleteMany(title); + + } } }