Fixed: Purge alt titles on movie delete (#2796)

Fixes #2542
pull/2/head
Qstick 7 years ago committed by Leonardo Galli
parent f058b8f364
commit f246fa87dd

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
@ -10,6 +10,7 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
{ {
AlternativeTitle FindBySourceId(int sourceId); AlternativeTitle FindBySourceId(int sourceId);
List<AlternativeTitle> FindBySourceIds(List<int> sourceIds); List<AlternativeTitle> FindBySourceIds(List<int> sourceIds);
List<AlternativeTitle> FindByMovieId(int movieId);
} }
public class AlternativeTitleRepository : BasicRepository<AlternativeTitle>, IAlternativeTitleRepository public class AlternativeTitleRepository : BasicRepository<AlternativeTitle>, IAlternativeTitleRepository
@ -31,5 +32,10 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
{ {
return Query.Where(t => t.SourceId.In(sourceIds)).ToList(); return Query.Where(t => t.SourceId.In(sourceIds)).ToList();
} }
public List<AlternativeTitle> FindByMovieId(int movieId)
{
return Query.Where(t => t.MovieId == movieId).ToList();
}
} }
} }

@ -1,31 +1,22 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NLog; using NLog;
using NzbDrone.Common.EnsureThat; using NzbDrone.Core.Configuration;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Organizer; using System.Collections.Generic;
using NzbDrone.Core.Movies; using System.Linq;
using NzbDrone.Core.Movies.Events; using NzbDrone.Core.Movies.Events;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Configuration;
namespace NzbDrone.Core.Movies.AlternativeTitles namespace NzbDrone.Core.Movies.AlternativeTitles
{ {
public interface IAlternativeTitleService public interface IAlternativeTitleService
{ {
List<AlternativeTitle> GetAllTitlesForMovie(Movie movie); List<AlternativeTitle> GetAllTitlesForMovie(int movieId);
AlternativeTitle AddAltTitle(AlternativeTitle title, Movie movie); AlternativeTitle AddAltTitle(AlternativeTitle title, Movie movie);
List<AlternativeTitle> AddAltTitles(List<AlternativeTitle> titles, Movie movie); List<AlternativeTitle> AddAltTitles(List<AlternativeTitle> titles, Movie movie);
AlternativeTitle GetById(int id); AlternativeTitle GetById(int id);
void DeleteNotEnoughVotes(List<AlternativeTitle> mappingsTitles); void DeleteNotEnoughVotes(List<AlternativeTitle> mappingsTitles);
} }
public class AlternativeTitleService : IAlternativeTitleService public class AlternativeTitleService : IAlternativeTitleService, IHandleAsync<MovieDeletedEvent>
{ {
private readonly IAlternativeTitleRepository _titleRepo; private readonly IAlternativeTitleRepository _titleRepo;
private readonly IConfigService _configService; private readonly IConfigService _configService;
@ -44,9 +35,9 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
_logger = logger; _logger = logger;
} }
public List<AlternativeTitle> GetAllTitlesForMovie(Movie movie) public List<AlternativeTitle> GetAllTitlesForMovie(int movieId)
{ {
return _titleRepo.All().ToList(); return _titleRepo.FindByMovieId(movieId).ToList();
} }
public AlternativeTitle AddAltTitle(AlternativeTitle title, Movie movie) public AlternativeTitle AddAltTitle(AlternativeTitle title, Movie movie)
@ -78,5 +69,12 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
var realT = _titleRepo.FindBySourceIds(toRemove.Select(t => t.SourceId).ToList()); var realT = _titleRepo.FindBySourceIds(toRemove.Select(t => t.SourceId).ToList());
_titleRepo.DeleteMany(realT); _titleRepo.DeleteMany(realT);
} }
public void HandleAsync(MovieDeletedEvent message)
{
var title = GetAllTitlesForMovie(message.Movie.Id);
_titleRepo.DeleteMany(title);
}
} }
} }

Loading…
Cancel
Save