Fixed: Manual import for unknown series items will properly mark as imported

Fixes: #277
(cherry picked from commit 3ffcf114682f9b1730f54706ecbf1bf237206bb1)
pull/1392/head
Mark McDowall 4 years ago committed by ta264
parent 842f80d567
commit 95d93dfa09

@ -23,6 +23,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests
public class ImportFixture : CoreTest<CompletedDownloadService>
{
private TrackedDownload _trackedDownload;
private Author _author;
[SetUp]
public void Setup()
@ -42,6 +43,9 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests
.With(c => c.RemoteBook = remoteBook)
.Build();
_author = Builder<Author>.CreateNew()
.Build();
Mocker.GetMock<IDownloadClient>()
.SetupGet(c => c.Definition)
.Returns(new DownloadClientDefinition { Id = 1, Name = "testClient" });
@ -190,8 +194,8 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Author>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(new ImportDecision<LocalBook>(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic() })),
new ImportResult(new ImportDecision<LocalBook>(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic() }), "Test Failure")
new ImportResult(new ImportDecision<LocalBook>(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic(), Author = _author })),
new ImportResult(new ImportDecision<LocalBook>(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic(), Author = _author }), "Test Failure")
});
Mocker.GetMock<IHistoryService>()
@ -286,11 +290,11 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests
{
new ImportResult(
new ImportDecision<LocalBook>(
new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic() })),
new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic(), Author = _author })),
new ImportResult(
new ImportDecision<LocalBook>(
new LocalBook { Path = @"C:\TestPath\Droned.S01E02.mkv".AsOsAgnostic() }))
new LocalBook { Path = @"C:\TestPath\Droned.S01E02.mkv".AsOsAgnostic(), Author = _author }))
});
Subject.Import(_trackedDownload);
@ -311,15 +315,18 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests
{
new ImportResult(
new ImportDecision<LocalBook>(
new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv", Book = books[0] })),
new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv", Book = books[0], Author = _author })),
new ImportResult(
new ImportDecision<LocalBook>(
new LocalBook { Path = @"C:\TestPath\Droned.S01E02.mkv", Book = books[1] }), "Test Failure")
new LocalBook { Path = @"C:\TestPath\Droned.S01E02.mkv", Book = books[1], Author = _author }), "Test Failure")
});
var history = Builder<EntityHistory>.CreateListOfSize(2)
.BuildList();
.All()
.With(x => x.EventType = EntityHistoryEventType.BookFileImported)
.With(x => x.AuthorId = 1)
.BuildList();
Mocker.GetMock<IHistoryService>()
.Setup(s => s.FindByDownloadId(It.IsAny<string>()))
@ -343,7 +350,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests
.Setup(v => v.ProcessPath(It.IsAny<string>(), It.IsAny<ImportMode>(), It.IsAny<Author>(), It.IsAny<DownloadClientItem>()))
.Returns(new List<ImportResult>
{
new ImportResult(new ImportDecision<LocalBook>(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic() }))
new ImportResult(new ImportDecision<LocalBook>(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic(), Author = _author }))
});
Subject.Import(_trackedDownload);

@ -130,7 +130,11 @@ namespace NzbDrone.Core.Download
if (allItemsImported)
{
trackedDownload.State = TrackedDownloadState.Imported;
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
var importedAuthorId = importResults.Where(x => x.Result == ImportResultType.Imported)
.Select(c => c.ImportDecision.Item.Author.Id)
.MostCommon();
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, trackedDownload.RemoteBook?.Author.Id ?? importedAuthorId));
return true;
}
@ -153,7 +157,11 @@ namespace NzbDrone.Core.Download
if (allEpisodesImportedInHistory)
{
trackedDownload.State = TrackedDownloadState.Imported;
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
var importedAuthorId = historyItems.Where(x => x.EventType == EntityHistoryEventType.BookFileImported)
.Select(x => x.AuthorId)
.MostCommon();
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, trackedDownload.RemoteBook?.Author.Id ?? importedAuthorId));
return true;
}
}

@ -1,4 +1,4 @@
using NzbDrone.Common.Messaging;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Download.TrackedDownloads;
namespace NzbDrone.Core.Download
@ -6,10 +6,12 @@ namespace NzbDrone.Core.Download
public class DownloadCompletedEvent : IEvent
{
public TrackedDownload TrackedDownload { get; private set; }
public int AuthorId { get; set; }
public DownloadCompletedEvent(TrackedDownload trackedDownload)
public DownloadCompletedEvent(TrackedDownload trackedDownload, int authorId)
{
TrackedDownload = trackedDownload;
AuthorId = authorId;
}
}
}

@ -40,7 +40,8 @@ namespace NzbDrone.Core.Download
foreach (var trackedDownload in trackedDownloads)
{
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload,
trackedDownload.RemoteBook.Author.Id));
}
}

@ -93,6 +93,12 @@ namespace NzbDrone.Core.Download.History
public void Handle(BookGrabbedEvent message)
{
// Don't store grabbed events for clients that don't download IDs
if (message.DownloadId.IsNullOrWhiteSpace())
{
return;
}
var history = new DownloadHistory
{
EventType = DownloadHistoryEventType.DownloadGrabbed,
@ -179,7 +185,7 @@ namespace NzbDrone.Core.Download.History
var history = new DownloadHistory
{
EventType = DownloadHistoryEventType.DownloadImported,
AuthorId = message.TrackedDownload.RemoteBook.Author.Id,
AuthorId = message.AuthorId,
DownloadId = message.TrackedDownload.DownloadItem.DownloadId,
SourceTitle = message.TrackedDownload.DownloadItem.OutputPath.ToString(),
Date = DateTime.UtcNow,

@ -389,7 +389,7 @@ namespace NzbDrone.Core.MediaFiles.BookImport.Manual
if (allItemsImported)
{
trackedDownload.State = TrackedDownloadState.Imported;
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload));
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, imported.First().ImportDecision.Item.Author.Id));
}
}
}

Loading…
Cancel
Save