mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-10 13:02:47 +01:00
Fixed: Errors in queue after Movie deleted
Fixes #5899 Fixes RADARR-17A
This commit is contained in:
parent
3e7c136a7f
commit
35d43480bf
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
@ -7,6 +8,7 @@
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Movies.Events;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
@ -83,5 +85,123 @@ public void should_track_downloads_using_the_source_title_if_it_cannot_be_found_
|
||||
trackedDownload.RemoteMovie.Movie.Should().NotBeNull();
|
||||
trackedDownload.RemoteMovie.Movie.Id.Should().Be(3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_unmap_tracked_download_if_movie_deleted()
|
||||
{
|
||||
GivenDownloadHistory();
|
||||
|
||||
var remoteMovie = new RemoteMovie
|
||||
{
|
||||
Movie = new Movie() { Id = 3 },
|
||||
|
||||
ParsedMovieInfo = new ParsedMovieInfo()
|
||||
{
|
||||
MovieTitle = "A Movie",
|
||||
Year = 1998
|
||||
}
|
||||
};
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Setup(s => s.Map(It.IsAny<ParsedMovieInfo>(), It.IsAny<string>(), null))
|
||||
.Returns(new MappingResult { RemoteMovie = remoteMovie });
|
||||
|
||||
Mocker.GetMock<IHistoryService>()
|
||||
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
|
||||
.Returns(new List<MovieHistory>());
|
||||
|
||||
ParseMovieTitle();
|
||||
|
||||
var client = new DownloadClientDefinition()
|
||||
{
|
||||
Id = 1,
|
||||
Protocol = DownloadProtocol.Torrent
|
||||
};
|
||||
|
||||
var item = new DownloadClientItem()
|
||||
{
|
||||
Title = "A Movie 1998",
|
||||
DownloadId = "12345",
|
||||
DownloadClientInfo = new DownloadClientItemClientInfo
|
||||
{
|
||||
Id = 1,
|
||||
Type = "Blackhole",
|
||||
Name = "Blackhole Client",
|
||||
Protocol = DownloadProtocol.Torrent
|
||||
}
|
||||
};
|
||||
|
||||
Subject.TrackDownload(client, item);
|
||||
Subject.GetTrackedDownloads().Should().HaveCount(1);
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Setup(s => s.Map(It.IsAny<ParsedMovieInfo>(), It.IsAny<string>(), null))
|
||||
.Returns(new MappingResult { MappingResultType = MappingResultType.Unknown });
|
||||
|
||||
Subject.Handle(new MoviesDeletedEvent(new List<Movie> { remoteMovie.Movie }, false, false));
|
||||
|
||||
var trackedDownloads = Subject.GetTrackedDownloads();
|
||||
trackedDownloads.Should().HaveCount(1);
|
||||
trackedDownloads.First().RemoteMovie.Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_throw_when_processing_deleted_movie()
|
||||
{
|
||||
GivenDownloadHistory();
|
||||
|
||||
var remoteMovie = new RemoteMovie
|
||||
{
|
||||
Movie = new Movie() { Id = 3 },
|
||||
|
||||
ParsedMovieInfo = new ParsedMovieInfo()
|
||||
{
|
||||
MovieTitle = "A Movie",
|
||||
Year = 1998
|
||||
}
|
||||
};
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Setup(s => s.Map(It.IsAny<ParsedMovieInfo>(), It.IsAny<string>(), null))
|
||||
.Returns(new MappingResult { MappingResultType = MappingResultType.Unknown });
|
||||
|
||||
Mocker.GetMock<IHistoryService>()
|
||||
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
|
||||
.Returns(new List<MovieHistory>());
|
||||
|
||||
ParseMovieTitle();
|
||||
|
||||
var client = new DownloadClientDefinition()
|
||||
{
|
||||
Id = 1,
|
||||
Protocol = DownloadProtocol.Torrent
|
||||
};
|
||||
|
||||
var item = new DownloadClientItem()
|
||||
{
|
||||
Title = "A Movie 1998",
|
||||
DownloadId = "12345",
|
||||
DownloadClientInfo = new DownloadClientItemClientInfo
|
||||
{
|
||||
Id = 1,
|
||||
Type = "Blackhole",
|
||||
Name = "Blackhole Client",
|
||||
Protocol = DownloadProtocol.Torrent
|
||||
}
|
||||
};
|
||||
|
||||
Subject.TrackDownload(client, item);
|
||||
Subject.GetTrackedDownloads().Should().HaveCount(1);
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Setup(s => s.Map(It.IsAny<ParsedMovieInfo>(), It.IsAny<string>(), null))
|
||||
.Returns(new MappingResult { MappingResultType = MappingResultType.Unknown });
|
||||
|
||||
Subject.Handle(new MoviesDeletedEvent(new List<Movie> { remoteMovie.Movie }, false, false));
|
||||
|
||||
var trackedDownloads = Subject.GetTrackedDownloads();
|
||||
trackedDownloads.Should().HaveCount(1);
|
||||
trackedDownloads.First().RemoteMovie.Should().BeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
using NzbDrone.Core.Download.History;
|
||||
using NzbDrone.Core.History;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Movies.Events;
|
||||
using NzbDrone.Core.Parser;
|
||||
|
||||
namespace NzbDrone.Core.Download.TrackedDownloads
|
||||
@ -23,7 +24,8 @@ public interface ITrackedDownloadService
|
||||
void UpdateTrackable(List<TrackedDownload> trackedDownloads);
|
||||
}
|
||||
|
||||
public class TrackedDownloadService : ITrackedDownloadService
|
||||
public class TrackedDownloadService : ITrackedDownloadService,
|
||||
IHandle<MoviesDeletedEvent>
|
||||
{
|
||||
private readonly IParsingService _parsingService;
|
||||
private readonly IHistoryService _historyService;
|
||||
@ -185,6 +187,13 @@ public void UpdateTrackable(List<TrackedDownload> trackedDownloads)
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCachedItem(TrackedDownload trackedDownload)
|
||||
{
|
||||
var parsedMovieInfo = Parser.Parser.ParseMovieTitle(trackedDownload.DownloadItem.Title);
|
||||
|
||||
trackedDownload.RemoteMovie = parsedMovieInfo == null ? null : _parsingService.Map(parsedMovieInfo, "", null).RemoteMovie;
|
||||
}
|
||||
|
||||
private static TrackedDownloadState GetStateFromHistory(DownloadHistoryEventType eventType)
|
||||
{
|
||||
switch (eventType)
|
||||
@ -217,5 +226,20 @@ private void LogItemChange(TrackedDownload trackedDownload, DownloadClientItem e
|
||||
downloadItem.OutputPath);
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(MoviesDeletedEvent message)
|
||||
{
|
||||
var cachedItems = _cache.Values.Where(t =>
|
||||
t.RemoteMovie?.Movie != null &&
|
||||
message.Movies.Any(m => m.Id == t.RemoteMovie.Movie.Id))
|
||||
.ToList();
|
||||
|
||||
if (cachedItems.Any())
|
||||
{
|
||||
cachedItems.ForEach(UpdateCachedItem);
|
||||
|
||||
_eventAggregator.PublishEvent(new TrackedDownloadRefreshedEvent(GetTrackedDownloads()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user