Ammend to previous commit.

Leonardo Galli 8 years ago
parent 0db27d9029
commit a25c056def

@ -2,24 +2,24 @@
namespace NzbDrone.Core.Housekeeping.Housekeepers namespace NzbDrone.Core.Housekeeping.Housekeepers
{ {
public class FixWronglyMatchedMovieFiles : IHousekeepingTask public class CleanupAdditionalUsers : IHousekeepingTask
{ {
private readonly IMainDatabase _database; private readonly IMainDatabase _database;
public FixWronglyMatchedMovieFiles(IMainDatabase database) public CleanupAdditionalUsers(IMainDatabase database)
{ {
_database = database; _database = database;
} }
public void Clean() public void Clean()
{ {
var mapper = _database.GetDataMapper(); var mapper = _database.GetDataMapper();
mapper.ExecuteNonQuery(@"UPDATE Movies mapper.ExecuteNonQuery(@"DELETE FROM Users
SET MovieFileId = WHERE ID NOT IN (
(Select Id FROM MovieFiles WHERE Movies.Id == MovieFiles.MovieId) SELECT ID FROM Users
WHERE MovieFileId != LIMIT 1)");
(SELECT Id FROM MovieFiles WHERE Movies.Id == MovieFiles.MovieId)"); }
} }
}
} }

@ -146,8 +146,12 @@ namespace NzbDrone.Core.MediaFiles
public MovieFile Add(MovieFile episodeFile) public MovieFile Add(MovieFile episodeFile)
{ {
var addedFile = _movieFileRepository.Insert(episodeFile); var addedFile = _movieFileRepository.Insert(episodeFile);
episodeFile.Movie.LazyLoad(); addedFile.Movie.LazyLoad();
_movieService.SetFileId(episodeFile.Movie.Value, episodeFile); //Should not be necessary, but sometimes below fails? if (addedFile.Movie == null || addedFile.Movie.Value == null)
{
_logger.Error("Movie is null for the file {0}. Please run the houskeeping command to ensure movies and files are linked correctly.");
}
_movieService.SetFileId(addedFile.Movie.Value, addedFile); //Should not be necessary, but sometimes below fails?
_eventAggregator.PublishEvent(new MovieFileAddedEvent(addedFile)); _eventAggregator.PublishEvent(new MovieFileAddedEvent(addedFile));
return addedFile; return addedFile;

Loading…
Cancel
Save