mirror of
https://github.com/Radarr/Radarr
synced 2025-01-01 12:54:21 +00:00
Fixed: Prevent error on MovieFile Delete if no movie references movieFile
Fixes #4042
This commit is contained in:
parent
e70be7cf9e
commit
c060f9fd4d
1 changed files with 29 additions and 27 deletions
|
@ -35,7 +35,7 @@ public interface IMovieService
|
|||
Movie FindByPath(string path);
|
||||
List<string> AllMoviePaths();
|
||||
bool MovieExists(Movie movie);
|
||||
Movie GetMovieByFileId(int fileId);
|
||||
List<Movie> GetMoviesByFileId(int fileId);
|
||||
List<Movie> GetMoviesBetweenDates(DateTime start, DateTime end, bool includeUnmonitored);
|
||||
PagingSpec<Movie> MoviesWithoutFiles(PagingSpec<Movie> pagingSpec);
|
||||
void SetFileId(Movie movie, MovieFile movieFile);
|
||||
|
@ -358,39 +358,15 @@ public void RemoveAddOptions(Movie movie)
|
|||
_movieRepository.SetFields(movie, s => s.AddOptions);
|
||||
}
|
||||
|
||||
public void Handle(MovieFileAddedEvent message)
|
||||
{
|
||||
var movie = message.MovieFile.Movie;
|
||||
movie.MovieFileId = message.MovieFile.Id;
|
||||
_movieRepository.Update(movie);
|
||||
|
||||
//_movieRepository.SetFileId(message.MovieFile.Id, message.MovieFile.Movie.Value.Id);
|
||||
_logger.Info("Linking [{0}] > [{1}]", message.MovieFile.RelativePath, message.MovieFile.Movie);
|
||||
}
|
||||
|
||||
public void SetFileId(Movie movie, MovieFile movieFile)
|
||||
{
|
||||
_movieRepository.SetFileId(movieFile.Id, movie.Id);
|
||||
_logger.Info("Linking [{0}] > [{1}]", movieFile.RelativePath, movie);
|
||||
}
|
||||
|
||||
public void Handle(MovieFileDeletedEvent message)
|
||||
public List<Movie> GetMoviesByFileId(int fileId)
|
||||
{
|
||||
var movie = _movieRepository.GetMoviesByFileId(message.MovieFile.Id).First();
|
||||
movie.MovieFileId = 0;
|
||||
_logger.Debug("Detaching movie {0} from file.", movie.Id);
|
||||
|
||||
if (message.Reason != DeleteMediaFileReason.Upgrade && _configService.AutoUnmonitorPreviouslyDownloadedMovies)
|
||||
{
|
||||
movie.Monitored = false;
|
||||
}
|
||||
|
||||
UpdateMovie(movie);
|
||||
}
|
||||
|
||||
public Movie GetMovieByFileId(int fileId)
|
||||
{
|
||||
return _movieRepository.GetMoviesByFileId(fileId).First();
|
||||
return _movieRepository.GetMoviesByFileId(fileId);
|
||||
}
|
||||
|
||||
public Movie FindByTitleSlug(string slug)
|
||||
|
@ -469,5 +445,31 @@ public List<Movie> FilterExistingMovies(List<Movie> movies)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void Handle(MovieFileAddedEvent message)
|
||||
{
|
||||
var movie = message.MovieFile.Movie;
|
||||
movie.MovieFileId = message.MovieFile.Id;
|
||||
_movieRepository.Update(movie);
|
||||
|
||||
//_movieRepository.SetFileId(message.MovieFile.Id, message.MovieFile.Movie.Value.Id);
|
||||
_logger.Info("Linking [{0}] > [{1}]", message.MovieFile.RelativePath, message.MovieFile.Movie);
|
||||
}
|
||||
|
||||
public void Handle(MovieFileDeletedEvent message)
|
||||
{
|
||||
foreach (var movie in GetMoviesByFileId(message.MovieFile.Id))
|
||||
{
|
||||
_logger.Debug("Detaching movie {0} from file.", movie.Id);
|
||||
movie.MovieFileId = 0;
|
||||
|
||||
if (message.Reason != DeleteMediaFileReason.Upgrade && _configService.AutoUnmonitorPreviouslyDownloadedMovies)
|
||||
{
|
||||
movie.Monitored = false;
|
||||
}
|
||||
|
||||
UpdateMovie(movie);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue