From 3a4b01cf6f7b11745c94327938ad4daaf9ef1e81 Mon Sep 17 00:00:00 2001 From: Leonardo Galli Date: Sat, 25 Feb 2017 13:50:12 +0100 Subject: [PATCH] Maybe fix issue with imported files not being linked to the movie? --- src/NzbDrone.Core/MediaFiles/MediaFileService.cs | 7 ++++++- src/NzbDrone.Core/Tv/MovieService.cs | 7 +++++++ src/UI/Navbar/Search.js | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Core/MediaFiles/MediaFileService.cs b/src/NzbDrone.Core/MediaFiles/MediaFileService.cs index 3faff167a..db7fc1687 100644 --- a/src/NzbDrone.Core/MediaFiles/MediaFileService.cs +++ b/src/NzbDrone.Core/MediaFiles/MediaFileService.cs @@ -39,12 +39,15 @@ namespace NzbDrone.Core.MediaFiles private readonly IEventAggregator _eventAggregator; private readonly IMediaFileRepository _mediaFileRepository; private readonly IMovieFileRepository _movieFileRepository; + private readonly IMovieService _movieService; private readonly Logger _logger; - public MediaFileService(IMediaFileRepository mediaFileRepository, IMovieFileRepository movieFileRepository, IEventAggregator eventAggregator, Logger logger) + public MediaFileService(IMediaFileRepository mediaFileRepository, IMovieFileRepository movieFileRepository, IMovieService movieService, + IEventAggregator eventAggregator, Logger logger) { _mediaFileRepository = mediaFileRepository; _eventAggregator = eventAggregator; + _movieService = movieService; _movieFileRepository = movieFileRepository; _logger = logger; } @@ -143,7 +146,9 @@ namespace NzbDrone.Core.MediaFiles public MovieFile Add(MovieFile episodeFile) { var addedFile = _movieFileRepository.Insert(episodeFile); + _movieService.SetFileId(episodeFile.Movie.Value, episodeFile); //Should not be necessary, but sometimes below fails? _eventAggregator.PublishEvent(new MovieFileAddedEvent(addedFile)); + return addedFile; } diff --git a/src/NzbDrone.Core/Tv/MovieService.cs b/src/NzbDrone.Core/Tv/MovieService.cs index 41acb3d07..d6d47f0e6 100644 --- a/src/NzbDrone.Core/Tv/MovieService.cs +++ b/src/NzbDrone.Core/Tv/MovieService.cs @@ -34,6 +34,7 @@ namespace NzbDrone.Core.Tv List GetMoviesBetweenDates(DateTime start, DateTime end, bool includeUnmonitored); PagingSpec MoviesWithoutFiles(PagingSpec pagingSpec); void DeleteMovie(int movieId, bool deleteFiles); + void SetFileId(Movie movie, MovieFile movieFile); List GetAllMovies(); Movie UpdateMovie(Movie movie); List UpdateMovie(List movie); @@ -299,6 +300,12 @@ namespace NzbDrone.Core.Tv _logger.Debug("Linking [{0}] > [{1}]", message.MovieFile.RelativePath, message.MovieFile.Movie.Value); } + public void SetFileId(Movie movie, MovieFile movieFile) + { + _movieRepository.SetFileId(movieFile.Id, movie.Id); + _logger.Debug("Linking [{0}] > [{1}]", movieFile.RelativePath, movie); + } + public void Handle(MovieFileDeletedEvent message) { diff --git a/src/UI/Navbar/Search.js b/src/UI/Navbar/Search.js index bf601d870..91d1bfaa8 100644 --- a/src/UI/Navbar/Search.js +++ b/src/UI/Navbar/Search.js @@ -2,7 +2,7 @@ var _ = require('underscore'); var $ = require('jquery'); var vent = require('vent'); var Backbone = require('backbone'); -var SeriesCollection = require('../Movies/FullMovieCollection'); +var FullMovieCollection = require('../Movies/FullMovieCollection'); require('typeahead'); vent.on(vent.Hotkeys.NavbarSearch, function() { @@ -11,7 +11,7 @@ vent.on(vent.Hotkeys.NavbarSearch, function() { var substringMatcher = function() { return function findMatches (q, cb) { - var matches = _.select(SeriesCollection.toJSON(), function(series) { + var matches = _.select(FullMovieCollection.toJSON(), function(series) { return series.title.toLowerCase().indexOf(q.toLowerCase()) > -1; }); cb(matches);