Fixed: Prevent NullRef on Manual Import of unknown releases

This commit is contained in:
Qstick 2021-04-02 00:09:57 -04:00
parent c4a63f3746
commit 015d2b1396
3 changed files with 9 additions and 6 deletions

View File

@ -123,7 +123,7 @@ namespace NzbDrone.Core.Download
if (allTracksImported) if (allTracksImported)
{ {
trackedDownload.State = TrackedDownloadState.Imported; trackedDownload.State = TrackedDownloadState.Imported;
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload)); _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, trackedDownload.RemoteAlbum.Artist.Id));
return; return;
} }
@ -141,7 +141,7 @@ namespace NzbDrone.Core.Download
if (allTracksImportedInHistory) if (allTracksImportedInHistory)
{ {
trackedDownload.State = TrackedDownloadState.Imported; trackedDownload.State = TrackedDownloadState.Imported;
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload)); _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, trackedDownload.RemoteAlbum.Artist.Id));
return; return;
} }
} }

View File

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

View File

@ -370,6 +370,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Manual
foreach (var groupedTrackedDownload in importedTrackedDownload.GroupBy(i => i.TrackedDownload.DownloadItem.DownloadId).ToList()) foreach (var groupedTrackedDownload in importedTrackedDownload.GroupBy(i => i.TrackedDownload.DownloadItem.DownloadId).ToList())
{ {
var trackedDownload = groupedTrackedDownload.First().TrackedDownload; var trackedDownload = groupedTrackedDownload.First().TrackedDownload;
var importArtist = groupedTrackedDownload.First().ImportResult.ImportDecision.Item.Artist;
var outputPath = trackedDownload.ImportItem.OutputPath.FullPath; var outputPath = trackedDownload.ImportItem.OutputPath.FullPath;
@ -377,7 +378,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Manual
{ {
if (_downloadedTracksImportService.ShouldDeleteFolder( if (_downloadedTracksImportService.ShouldDeleteFolder(
_diskProvider.GetDirectoryInfo(outputPath), _diskProvider.GetDirectoryInfo(outputPath),
trackedDownload.RemoteAlbum.Artist) && trackedDownload.DownloadItem.CanMoveFiles) importArtist) && trackedDownload.DownloadItem.CanMoveFiles)
{ {
_diskProvider.DeleteFolder(outputPath, true); _diskProvider.DeleteFolder(outputPath, true);
} }
@ -386,7 +387,7 @@ namespace NzbDrone.Core.MediaFiles.TrackImport.Manual
if (groupedTrackedDownload.Select(c => c.ImportResult).Count(c => c.Result == ImportResultType.Imported) >= Math.Max(1, trackedDownload.RemoteAlbum.Albums.Count)) if (groupedTrackedDownload.Select(c => c.ImportResult).Count(c => c.Result == ImportResultType.Imported) >= Math.Max(1, trackedDownload.RemoteAlbum.Albums.Count))
{ {
trackedDownload.State = TrackedDownloadState.Imported; trackedDownload.State = TrackedDownloadState.Imported;
_eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload)); _eventAggregator.PublishEvent(new DownloadCompletedEvent(trackedDownload, importArtist.Id));
} }
} }
} }