Fix issue where updating a movie during a refresh would reset the saved changes

#4807
pull/4848/head
nitsua 4 years ago committed by Qstick
parent 4726d9daad
commit 236cdc9c2a

@ -56,9 +56,13 @@ namespace NzbDrone.Core.Movies
_logger = logger; _logger = logger;
} }
private void RefreshMovieInfo(Movie movie) private Movie RefreshMovieInfo(int movieId)
{ {
_logger.ProgressInfo("Updating Info for {0}", movie.Title); // Get the movie before updating, that way any changes made to the movie after the refresh started,
// but before this movie was refreshed won't be lost.
var movie = _movieService.GetMovie(movieId);
_logger.ProgressInfo("Updating info for {0}", movie.Title);
Movie movieInfo; Movie movieInfo;
List<Credit> credits; List<Credit> credits;
@ -75,7 +79,7 @@ namespace NzbDrone.Core.Movies
{ {
movie.Status = MovieStatusType.Deleted; movie.Status = MovieStatusType.Deleted;
_movieService.UpdateMovie(movie); _movieService.UpdateMovie(movie);
_logger.Debug("Movie marked as deleted on tmdb for {0}", movie.Title); _logger.Debug("Movie marked as deleted on TMDb for {0}", movie.Title);
_eventAggregator.PublishEvent(new MovieUpdatedEvent(movie)); _eventAggregator.PublishEvent(new MovieUpdatedEvent(movie));
} }
@ -84,7 +88,7 @@ namespace NzbDrone.Core.Movies
if (movie.TmdbId != movieInfo.TmdbId) if (movie.TmdbId != movieInfo.TmdbId)
{ {
_logger.Warn("Movie '{0}' (Tmdbid {1}) was replaced with '{2}' (Tmdbid {3}), because the original was a duplicate.", movie.Title, movie.TmdbId, movieInfo.Title, movieInfo.TmdbId); _logger.Warn("Movie '{0}' (TMDb: {1}) was replaced with '{2}' (TMDb: {3}), because the original was a duplicate.", movie.Title, movie.TmdbId, movieInfo.Title, movieInfo.TmdbId);
movie.TmdbId = movieInfo.TmdbId; movie.TmdbId = movieInfo.TmdbId;
} }
@ -134,6 +138,8 @@ namespace NzbDrone.Core.Movies
_logger.Debug("Finished movie refresh for {0}", movie.Title); _logger.Debug("Finished movie refresh for {0}", movie.Title);
_eventAggregator.PublishEvent(new MovieUpdatedEvent(movie)); _eventAggregator.PublishEvent(new MovieUpdatedEvent(movie));
return movie;
} }
private void RescanMovie(Movie movie, bool isNew, CommandTrigger trigger) private void RescanMovie(Movie movie, bool isNew, CommandTrigger trigger)
@ -148,12 +154,12 @@ namespace NzbDrone.Core.Movies
} }
else if (rescanAfterRefresh == RescanAfterRefreshType.Never) else if (rescanAfterRefresh == RescanAfterRefreshType.Never)
{ {
_logger.Trace("Skipping rescan of {0}. Reason: never rescan after refresh", movie); _logger.Trace("Skipping rescan of {0}. Reason: Never rescan after refresh", movie);
shouldRescan = false; shouldRescan = false;
} }
else if (rescanAfterRefresh == RescanAfterRefreshType.AfterManual && trigger != CommandTrigger.Manual) else if (rescanAfterRefresh == RescanAfterRefreshType.AfterManual && trigger != CommandTrigger.Manual)
{ {
_logger.Trace("Skipping rescan of {0}. Reason: not after automatic scans", movie); _logger.Trace("Skipping rescan of {0}. Reason: Not after automatic scans", movie);
shouldRescan = false; shouldRescan = false;
} }
@ -186,12 +192,12 @@ namespace NzbDrone.Core.Movies
try try
{ {
RefreshMovieInfo(movie); movie = RefreshMovieInfo(movieId);
RescanMovie(movie, isNew, trigger); RescanMovie(movie, isNew, trigger);
} }
catch (MovieNotFoundException) catch (MovieNotFoundException)
{ {
_logger.Error("Movie '{0}' (imdbid {1}) was not found, it may have been removed from The Movie Database.", movie.Title, movie.ImdbId); _logger.Error("Movie '{0}' (TMDb {1}) was not found, it may have been removed from The Movie Database.", movie.Title, movie.TmdbId);
} }
catch (Exception e) catch (Exception e)
{ {
@ -214,28 +220,29 @@ namespace NzbDrone.Core.Movies
foreach (var movie in allMovie) foreach (var movie in allMovie)
{ {
var movieLocal = movie;
if ((updatedTMDBMovies.Count == 0 && _checkIfMovieShouldBeRefreshed.ShouldRefresh(movie)) || updatedTMDBMovies.Contains(movie.TmdbId) || message.Trigger == CommandTrigger.Manual) if ((updatedTMDBMovies.Count == 0 && _checkIfMovieShouldBeRefreshed.ShouldRefresh(movie)) || updatedTMDBMovies.Contains(movie.TmdbId) || message.Trigger == CommandTrigger.Manual)
{ {
try try
{ {
RefreshMovieInfo(movie); movieLocal = RefreshMovieInfo(movieLocal.Id);
} }
catch (MovieNotFoundException) catch (MovieNotFoundException)
{ {
_logger.Error("Movie '{0}' (imdbid {1}) was not found, it may have been removed from The Movie Database.", movie.Title, movie.ImdbId); _logger.Error("Movie '{0}' (TMDb {1}) was not found, it may have been removed from The Movie Database.", movieLocal.Title, movieLocal.TmdbId);
continue; continue;
} }
catch (Exception e) catch (Exception e)
{ {
_logger.Error(e, "Couldn't refresh info for {0}", movie); _logger.Error(e, "Couldn't refresh info for {0}", movieLocal);
} }
RescanMovie(movie, false, trigger); RescanMovie(movieLocal, false, trigger);
} }
else else
{ {
_logger.Info("Skipping refresh of movie: {0}", movie.Title); _logger.Info("Skipping refresh of movie: {0}", movieLocal.Title);
RescanMovie(movie, false, trigger); RescanMovie(movieLocal, false, trigger);
} }
} }
} }

Loading…
Cancel
Save