diff --git a/frontend/src/Activity/History/HistoryEventTypeCell.js b/frontend/src/Activity/History/HistoryEventTypeCell.js index 4aae64a53..f4ef33056 100644 --- a/frontend/src/Activity/History/HistoryEventTypeCell.js +++ b/frontend/src/Activity/History/HistoryEventTypeCell.js @@ -23,8 +23,6 @@ function getIconName(eventType) { return icons.RETAG; case 'bookImportIncomplete': return icons.DOWNLOADED; - case 'downloadImported': - return icons.DOWNLOADED; case 'downloadIgnored': return icons.IGNORE; default: @@ -61,8 +59,6 @@ function getTooltip(eventType, data) { return 'Book file tags updated'; case 'bookImportIncomplete': return 'Files downloaded but not all could be imported'; - case 'downloadImported': - return 'Download completed and successfully imported'; case 'downloadIgnored': return 'Book Download Ignored'; default: diff --git a/frontend/src/Store/Actions/historyActions.js b/frontend/src/Store/Actions/historyActions.js index 64ae28bed..8b7b91299 100644 --- a/frontend/src/Store/Actions/historyActions.js +++ b/frontend/src/Store/Actions/historyActions.js @@ -131,17 +131,6 @@ export const defaultState = { } ] }, - { - key: 'downloadImported', - label: 'Download Imported', - filters: [ - { - key: 'eventType', - value: '8', - type: filterTypes.EQUAL - } - ] - }, { key: 'deleted', label: 'Deleted', diff --git a/src/NzbDrone.Core.Test/Datastore/DatabaseRelationshipFixture.cs b/src/NzbDrone.Core.Test/Datastore/DatabaseRelationshipFixture.cs index b30b8b946..1996386ec 100644 --- a/src/NzbDrone.Core.Test/Datastore/DatabaseRelationshipFixture.cs +++ b/src/NzbDrone.Core.Test/Datastore/DatabaseRelationshipFixture.cs @@ -4,6 +4,7 @@ using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Books; +using NzbDrone.Core.History; using NzbDrone.Core.Qualities; using NzbDrone.Core.Test.Framework; @@ -29,21 +30,21 @@ namespace NzbDrone.Core.Test.Datastore { var quality = new QualityModel { Quality = Quality.MP3, Revision = new Revision(version: 2) }; - var history = Builder.CreateNew() + var history = Builder.CreateNew() .With(c => c.Id = 0) .With(c => c.Quality = quality) .Build(); Db.Insert(history); - var loadedQuality = Db.Single().Quality; + var loadedQuality = Db.Single().Quality; loadedQuality.Should().Be(quality); } [Test] public void embedded_list_of_document_with_json() { - var history = Builder.CreateListOfSize(2) + var history = Builder.CreateListOfSize(2) .All().With(c => c.Id = 0) .Build().ToList(); @@ -52,7 +53,7 @@ namespace NzbDrone.Core.Test.Datastore Db.InsertMany(history); - var returnedHistory = Db.All(); + var returnedHistory = Db.All(); returnedHistory[0].Quality.Quality.Should().Be(Quality.MP3); } diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/AlreadyImportedSpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/AlreadyImportedSpecificationFixture.cs index 6f2e3a82a..44d665cfb 100644 --- a/src/NzbDrone.Core.Test/DecisionEngineTests/AlreadyImportedSpecificationFixture.cs +++ b/src/NzbDrone.Core.Test/DecisionEngineTests/AlreadyImportedSpecificationFixture.cs @@ -26,7 +26,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests private QualityModel _mp3; private QualityModel _flac; private RemoteBook _remoteBook; - private List _history; + private List _history; private BookFile _firstFile; [SetUp] @@ -58,7 +58,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests .Build() }; - _history = new List(); + _history = new List(); Mocker.GetMock() .SetupGet(s => s.EnableCompletedDownloadHandling) @@ -80,9 +80,9 @@ namespace NzbDrone.Core.Test.DecisionEngineTests .Returns(false); } - private void GivenHistoryItem(string downloadId, string sourceTitle, QualityModel quality, HistoryEventType eventType) + private void GivenHistoryItem(string downloadId, string sourceTitle, QualityModel quality, EntityHistoryEventType eventType) { - _history.Add(new History.History + _history.Add(new EntityHistory { DownloadId = downloadId, SourceTitle = sourceTitle, @@ -119,7 +119,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void should_be_accepted_if_book_does_not_have_imported_event() { - GivenHistoryItem(Guid.NewGuid().ToString().ToUpper(), TITLE, _mp3, HistoryEventType.Grabbed); + GivenHistoryItem(Guid.NewGuid().ToString().ToUpper(), TITLE, _mp3, EntityHistoryEventType.Grabbed); Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeTrue(); } @@ -129,8 +129,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests { var downloadId = Guid.NewGuid().ToString().ToUpper(); - GivenHistoryItem(downloadId, TITLE, _mp3, HistoryEventType.Grabbed); - GivenHistoryItem(downloadId, TITLE, _mp3, HistoryEventType.DownloadImported); + GivenHistoryItem(downloadId, TITLE, _mp3, EntityHistoryEventType.Grabbed); + GivenHistoryItem(downloadId, TITLE, _mp3, EntityHistoryEventType.BookFileImported); Subject.IsSatisfiedBy(_remoteBook, null).Accepted.Should().BeTrue(); } @@ -140,8 +140,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests { var downloadId = Guid.NewGuid().ToString().ToUpper(); - GivenHistoryItem(downloadId, TITLE, _mp3, HistoryEventType.Grabbed); - GivenHistoryItem(downloadId, TITLE, _flac, HistoryEventType.DownloadImported); + GivenHistoryItem(downloadId, TITLE, _mp3, EntityHistoryEventType.Grabbed); + GivenHistoryItem(downloadId, TITLE, _flac, EntityHistoryEventType.BookFileImported); _remoteBook.Release = Builder.CreateNew() .With(t => t.DownloadProtocol = DownloadProtocol.Torrent) @@ -156,8 +156,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests { var downloadId = Guid.NewGuid().ToString().ToUpper(); - GivenHistoryItem(downloadId, TITLE, _mp3, HistoryEventType.Grabbed); - GivenHistoryItem(downloadId, TITLE, _flac, HistoryEventType.DownloadImported); + GivenHistoryItem(downloadId, TITLE, _mp3, EntityHistoryEventType.Grabbed); + GivenHistoryItem(downloadId, TITLE, _flac, EntityHistoryEventType.BookFileImported); _remoteBook.Release = Builder.CreateNew() .With(t => t.DownloadProtocol = DownloadProtocol.Torrent) @@ -170,8 +170,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void should_be_accepted_if_release_torrent_hash_is_null_and_downloadId_is_null() { - GivenHistoryItem(null, TITLE, _mp3, HistoryEventType.Grabbed); - GivenHistoryItem(null, TITLE, _flac, HistoryEventType.DownloadImported); + GivenHistoryItem(null, TITLE, _mp3, EntityHistoryEventType.Grabbed); + GivenHistoryItem(null, TITLE, _flac, EntityHistoryEventType.BookFileImported); _remoteBook.Release = Builder.CreateNew() .With(t => t.DownloadProtocol = DownloadProtocol.Torrent) @@ -186,8 +186,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests { var downloadId = Guid.NewGuid().ToString().ToUpper(); - GivenHistoryItem(downloadId, TITLE, _mp3, HistoryEventType.Grabbed); - GivenHistoryItem(downloadId, TITLE, _flac, HistoryEventType.DownloadImported); + GivenHistoryItem(downloadId, TITLE, _mp3, EntityHistoryEventType.Grabbed); + GivenHistoryItem(downloadId, TITLE, _flac, EntityHistoryEventType.BookFileImported); _remoteBook.Release = Builder.CreateNew() .With(t => t.DownloadProtocol = DownloadProtocol.Torrent) diff --git a/src/NzbDrone.Core.Test/DecisionEngineTests/HistorySpecificationFixture.cs b/src/NzbDrone.Core.Test/DecisionEngineTests/HistorySpecificationFixture.cs index 6b4848a2e..6e7ce32ee 100644 --- a/src/NzbDrone.Core.Test/DecisionEngineTests/HistorySpecificationFixture.cs +++ b/src/NzbDrone.Core.Test/DecisionEngineTests/HistorySpecificationFixture.cs @@ -76,10 +76,10 @@ namespace NzbDrone.Core.Test.DecisionEngineTests .Returns(true); } - private void GivenMostRecentForBook(int bookId, string downloadId, QualityModel quality, DateTime date, HistoryEventType eventType) + private void GivenMostRecentForBook(int bookId, string downloadId, QualityModel quality, DateTime date, EntityHistoryEventType eventType) { Mocker.GetMock().Setup(s => s.MostRecentForBook(bookId)) - .Returns(new History.History { DownloadId = downloadId, Quality = quality, Date = date, EventType = eventType }); + .Returns(new EntityHistory { DownloadId = downloadId, Quality = quality, Date = date, EventType = eventType }); } private void GivenCdhDisabled() @@ -98,66 +98,66 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void should_return_true_if_latest_history_item_is_null() { - Mocker.GetMock().Setup(s => s.MostRecentForBook(It.IsAny())).Returns((History.History)null); + Mocker.GetMock().Setup(s => s.MostRecentForBook(It.IsAny())).Returns((EntityHistory)null); _upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue(); } [Test] public void should_return_true_if_latest_history_item_is_not_grabbed() { - GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.DownloadFailed); + GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, EntityHistoryEventType.DownloadFailed); _upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue(); } // [Test] // public void should_return_true_if_latest_history_has_a_download_id_and_cdh_is_enabled() // { - // GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed); + // GivenMostRecentForEpisode(FIRST_EPISODE_ID, "test", _notupgradableQuality, DateTime.UtcNow, EpisodeHistoryEventType.Grabbed); // _upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue(); // } [Test] public void should_return_true_if_latest_history_item_is_older_than_twelve_hours() { - GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-12).AddMilliseconds(-1), HistoryEventType.Grabbed); + GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-12).AddMilliseconds(-1), EntityHistoryEventType.Grabbed); _upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue(); } [Test] public void should_be_upgradable_if_only_book_is_upgradable() { - GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed); + GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed); _upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue(); } [Test] public void should_be_upgradable_if_both_books_are_upgradable() { - GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed); - GivenMostRecentForBook(SECOND_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed); + GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed); + GivenMostRecentForBook(SECOND_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed); _upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue(); } [Test] public void should_not_be_upgradable_if_both_books_are_not_upgradable() { - GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed); - GivenMostRecentForBook(SECOND_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed); + GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed); + GivenMostRecentForBook(SECOND_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed); _upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse(); } [Test] public void should_be_not_upgradable_if_only_first_books_is_upgradable() { - GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed); - GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed); + GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed); + GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed); _upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse(); } [Test] public void should_be_not_upgradable_if_only_second_books_is_upgradable() { - GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed); - GivenMostRecentForBook(SECOND_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed); + GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed); + GivenMostRecentForBook(SECOND_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed); _upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse(); } @@ -168,7 +168,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests _parseResultSingle.ParsedBookInfo.Quality = new QualityModel(Quality.MP3, new Revision(version: 1)); _upgradableQuality = new QualityModel(Quality.MP3, new Revision(version: 1)); - GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed); + GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed); _upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse(); } @@ -180,7 +180,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests _parseResultSingle.ParsedBookInfo.Quality = new QualityModel(Quality.MP3, new Revision(version: 1)); _upgradableQuality = new QualityModel(Quality.MP3, new Revision(version: 1)); - GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, HistoryEventType.Grabbed); + GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _upgradableQuality, DateTime.UtcNow, EntityHistoryEventType.Grabbed); _upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse(); } @@ -188,7 +188,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void should_return_false_if_latest_history_item_is_only_one_hour_old() { - GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-1), HistoryEventType.Grabbed); + GivenMostRecentForBook(FIRST_ALBUM_ID, string.Empty, _notupgradableQuality, DateTime.UtcNow.AddHours(-1), EntityHistoryEventType.Grabbed); _upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse(); } @@ -196,7 +196,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests public void should_return_false_if_latest_history_has_a_download_id_and_cdh_is_disabled() { GivenCdhDisabled(); - GivenMostRecentForBook(FIRST_ALBUM_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed); + GivenMostRecentForBook(FIRST_ALBUM_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), EntityHistoryEventType.Grabbed); _upgradeHistory.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue(); } @@ -208,7 +208,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests _parseResultSingle.ParsedBookInfo.Quality = new QualityModel(Quality.MP3, new Revision(version: 1)); _upgradableQuality = new QualityModel(Quality.MP3, new Revision(version: 1)); - GivenMostRecentForBook(FIRST_ALBUM_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed); + GivenMostRecentForBook(FIRST_ALBUM_ID, "test", _upgradableQuality, DateTime.UtcNow.AddDays(-100), EntityHistoryEventType.Grabbed); _upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse(); } @@ -217,7 +217,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests public void should_return_false_if_only_book_is_not_upgradable_and_cdh_is_disabled() { GivenCdhDisabled(); - GivenMostRecentForBook(FIRST_ALBUM_ID, "test", _notupgradableQuality, DateTime.UtcNow.AddDays(-100), HistoryEventType.Grabbed); + GivenMostRecentForBook(FIRST_ALBUM_ID, "test", _notupgradableQuality, DateTime.UtcNow.AddDays(-100), EntityHistoryEventType.Grabbed); _upgradeHistory.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse(); } } diff --git a/src/NzbDrone.Core.Test/Download/CompletedDownloadServiceTests/ImportFixture.cs b/src/NzbDrone.Core.Test/Download/CompletedDownloadServiceTests/ImportFixture.cs index 52201b5e5..e2471358a 100644 --- a/src/NzbDrone.Core.Test/Download/CompletedDownloadServiceTests/ImportFixture.cs +++ b/src/NzbDrone.Core.Test/Download/CompletedDownloadServiceTests/ImportFixture.cs @@ -52,7 +52,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests Mocker.GetMock() .Setup(s => s.MostRecentForDownloadId(_trackedDownload.DownloadItem.DownloadId)) - .Returns(new History.History()); + .Returns(new EntityHistory()); Mocker.GetMock() .Setup(s => s.GetAuthor("Drone.S01E01.HDTV")) @@ -83,7 +83,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests _trackedDownload.DownloadItem.Title = "Droned Pilot"; // Set a badly named download Mocker.GetMock() .Setup(s => s.MostRecentForDownloadId(It.Is(i => i == "1234"))) - .Returns(new History.History() { SourceTitle = "Droned S01E01" }); + .Returns(new EntityHistory() { SourceTitle = "Droned S01E01" }); Mocker.GetMock() .Setup(s => s.GetAuthor(It.IsAny())) @@ -194,6 +194,10 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests new ImportResult(new ImportDecision(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic() }), "Test Failure") }); + Mocker.GetMock() + .Setup(s => s.FindByDownloadId(It.IsAny())) + .Returns(new List()); + Subject.Import(_trackedDownload); AssertImported(); @@ -220,7 +224,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests new ImportResult(new ImportDecision(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv".AsOsAgnostic() }), "Test Failure") }); - var history = Builder.CreateListOfSize(2) + var history = Builder.CreateListOfSize(2) .BuildList(); Mocker.GetMock() @@ -252,7 +256,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests new ImportResult(new ImportDecision(new LocalBook { Path = @"C:\TestPath\Droned.S01E01.mkv" }), "Test Failure") }); - var history = Builder.CreateListOfSize(2) + var history = Builder.CreateListOfSize(2) .BuildList(); Mocker.GetMock() @@ -260,7 +264,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests .Returns(history); Mocker.GetMock() - .Setup(s => s.IsImported(It.IsAny(), It.IsAny>())) + .Setup(s => s.IsImported(It.IsAny(), It.IsAny>())) .Returns(false); Subject.Import(_trackedDownload); @@ -314,7 +318,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests new LocalBook { Path = @"C:\TestPath\Droned.S01E02.mkv", Book = books[1] }), "Test Failure") }); - var history = Builder.CreateListOfSize(2) + var history = Builder.CreateListOfSize(2) .BuildList(); Mocker.GetMock() @@ -322,7 +326,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests .Returns(history); Mocker.GetMock() - .Setup(s => s.IsImported(It.IsAny(), It.IsAny>())) + .Setup(s => s.IsImported(It.IsAny(), It.IsAny>())) .Returns(true); Subject.Import(_trackedDownload); diff --git a/src/NzbDrone.Core.Test/Download/CompletedDownloadServiceTests/ProcessFixture.cs b/src/NzbDrone.Core.Test/Download/CompletedDownloadServiceTests/ProcessFixture.cs index da05e0ee5..1dc3b18cc 100644 --- a/src/NzbDrone.Core.Test/Download/CompletedDownloadServiceTests/ProcessFixture.cs +++ b/src/NzbDrone.Core.Test/Download/CompletedDownloadServiceTests/ProcessFixture.cs @@ -51,7 +51,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests Mocker.GetMock() .Setup(s => s.MostRecentForDownloadId(_trackedDownload.DownloadItem.DownloadId)) - .Returns(new History.History()); + .Returns(new EntityHistory()); Mocker.GetMock() .Setup(s => s.GetAuthor("Drone.S01E01.HDTV")) @@ -71,7 +71,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests { Mocker.GetMock() .Setup(s => s.MostRecentForDownloadId(_trackedDownload.DownloadItem.DownloadId)) - .Returns((History.History)null); + .Returns((EntityHistory)null); } private void GivenAuthorMatch() @@ -87,7 +87,7 @@ namespace NzbDrone.Core.Test.Download.CompletedDownloadServiceTests _trackedDownload.DownloadItem.Title = "Droned Pilot"; // Set a badly named download Mocker.GetMock() .Setup(s => s.MostRecentForDownloadId(It.Is(i => i == "1234"))) - .Returns(new History.History() { SourceTitle = "Droned S01E01" }); + .Returns(new EntityHistory() { SourceTitle = "Droned S01E01" }); Mocker.GetMock() .Setup(s => s.GetAuthor(It.IsAny())) diff --git a/src/NzbDrone.Core.Test/Download/FailedDownloadServiceTests/ProcessFailedFixture.cs b/src/NzbDrone.Core.Test/Download/FailedDownloadServiceTests/ProcessFailedFixture.cs index 5736f9abb..9655c982d 100644 --- a/src/NzbDrone.Core.Test/Download/FailedDownloadServiceTests/ProcessFailedFixture.cs +++ b/src/NzbDrone.Core.Test/Download/FailedDownloadServiceTests/ProcessFailedFixture.cs @@ -19,7 +19,7 @@ namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests public class ProcessFailedFixture : CoreTest { private TrackedDownload _trackedDownload; - private List _grabHistory; + private List _grabHistory; [SetUp] public void Setup() @@ -30,7 +30,7 @@ namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests .With(h => h.Title = "Drone.S01E01.HDTV") .Build(); - _grabHistory = Builder.CreateListOfSize(2).BuildList(); + _grabHistory = Builder.CreateListOfSize(2).BuildList(); var remoteBook = new RemoteBook { @@ -45,7 +45,7 @@ namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests .Build(); Mocker.GetMock() - .Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed)) + .Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, EntityHistoryEventType.Grabbed)) .Returns(_grabHistory); } diff --git a/src/NzbDrone.Core.Test/Download/FailedDownloadServiceTests/ProcessFixture.cs b/src/NzbDrone.Core.Test/Download/FailedDownloadServiceTests/ProcessFixture.cs index e84ea00e0..f7a8a1a3c 100644 --- a/src/NzbDrone.Core.Test/Download/FailedDownloadServiceTests/ProcessFixture.cs +++ b/src/NzbDrone.Core.Test/Download/FailedDownloadServiceTests/ProcessFixture.cs @@ -19,7 +19,7 @@ namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests public class ProcessFixture : CoreTest { private TrackedDownload _trackedDownload; - private List _grabHistory; + private List _grabHistory; [SetUp] public void Setup() @@ -30,7 +30,7 @@ namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests .With(h => h.Title = "Drone.DroneTheBook.FLAC") .Build(); - _grabHistory = Builder.CreateListOfSize(2).BuildList(); + _grabHistory = Builder.CreateListOfSize(2).BuildList(); var remoteBook = new RemoteBook { @@ -45,15 +45,15 @@ namespace NzbDrone.Core.Test.Download.FailedDownloadServiceTests .Build(); Mocker.GetMock() - .Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed)) + .Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, EntityHistoryEventType.Grabbed)) .Returns(_grabHistory); } private void GivenNoGrabbedHistory() { Mocker.GetMock() - .Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed)) - .Returns(new List()); + .Setup(s => s.Find(_trackedDownload.DownloadItem.DownloadId, EntityHistoryEventType.Grabbed)) + .Returns(new List()); } [Test] diff --git a/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadAlreadyImportedFixture.cs b/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadAlreadyImportedFixture.cs index b8117cc96..72563fba0 100644 --- a/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadAlreadyImportedFixture.cs +++ b/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadAlreadyImportedFixture.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; @@ -15,7 +15,7 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads { private List _books; private TrackedDownload _trackedDownload; - private List _historyItems; + private List _historyItems; [SetUp] public void Setup() @@ -30,7 +30,7 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads .With(t => t.RemoteBook = remoteBook) .Build(); - _historyItems = new List(); + _historyItems = new List(); } public void GivenEpisodes(int count) @@ -39,12 +39,12 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads .BuildList()); } - public void GivenHistoryForEpisode(Book episode, params HistoryEventType[] eventTypes) + public void GivenHistoryForEpisode(Book episode, params EntityHistoryEventType[] eventTypes) { foreach (var eventType in eventTypes) { _historyItems.Add( - Builder.CreateNew() + Builder.CreateNew() .With(h => h.BookId = episode.Id) .With(h => h.EventType = eventType) .Build()); @@ -66,7 +66,7 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads { GivenEpisodes(1); - GivenHistoryForEpisode(_books[0], HistoryEventType.Grabbed); + GivenHistoryForEpisode(_books[0], EntityHistoryEventType.Grabbed); Subject.IsImported(_trackedDownload, _historyItems) .Should() @@ -78,8 +78,8 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads { GivenEpisodes(2); - GivenHistoryForEpisode(_books[0], HistoryEventType.Grabbed); - GivenHistoryForEpisode(_books[1], HistoryEventType.Grabbed); + GivenHistoryForEpisode(_books[0], EntityHistoryEventType.Grabbed); + GivenHistoryForEpisode(_books[1], EntityHistoryEventType.Grabbed); Subject.IsImported(_trackedDownload, _historyItems) .Should() @@ -91,8 +91,8 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads { GivenEpisodes(2); - GivenHistoryForEpisode(_books[0], HistoryEventType.DownloadImported, HistoryEventType.Grabbed); - GivenHistoryForEpisode(_books[1], HistoryEventType.Grabbed); + GivenHistoryForEpisode(_books[0], EntityHistoryEventType.BookFileImported, EntityHistoryEventType.Grabbed); + GivenHistoryForEpisode(_books[1], EntityHistoryEventType.Grabbed); Subject.IsImported(_trackedDownload, _historyItems) .Should() @@ -104,7 +104,7 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads { GivenEpisodes(1); - GivenHistoryForEpisode(_books[0], HistoryEventType.DownloadImported, HistoryEventType.Grabbed); + GivenHistoryForEpisode(_books[0], EntityHistoryEventType.BookFileImported, EntityHistoryEventType.Grabbed); Subject.IsImported(_trackedDownload, _historyItems) .Should() @@ -116,8 +116,8 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads { GivenEpisodes(2); - GivenHistoryForEpisode(_books[0], HistoryEventType.DownloadImported, HistoryEventType.Grabbed); - GivenHistoryForEpisode(_books[1], HistoryEventType.DownloadImported, HistoryEventType.Grabbed); + GivenHistoryForEpisode(_books[0], EntityHistoryEventType.BookFileImported, EntityHistoryEventType.Grabbed); + GivenHistoryForEpisode(_books[1], EntityHistoryEventType.BookFileImported, EntityHistoryEventType.Grabbed); Subject.IsImported(_trackedDownload, _historyItems) .Should() diff --git a/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadServiceFixture.cs b/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadServiceFixture.cs index ca61e9e29..a35125562 100644 --- a/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Download/TrackedDownloads/TrackedDownloadServiceFixture.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using FluentAssertions; using Moq; @@ -22,15 +22,15 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads { Mocker.GetMock() .Setup(s => s.FindByDownloadId(It.Is(sr => sr == "35238"))) - .Returns(new List() + .Returns(new List() { - new History.History() - { - DownloadId = "35238", - SourceTitle = "Audio Author - Audio Book [2018 - FLAC]", - AuthorId = 5, - BookId = 4, - } + new EntityHistory() + { + DownloadId = "35238", + SourceTitle = "Audio Author - Audio Book [2018 - FLAC]", + AuthorId = 5, + BookId = 4, + } }); } diff --git a/src/NzbDrone.Core.Test/HealthCheck/Checks/RemotePathMappingCheckFixture.cs b/src/NzbDrone.Core.Test/HealthCheck/Checks/RemotePathMappingCheckFixture.cs index d8f4df611..1bf02cc08 100644 --- a/src/NzbDrone.Core.Test/HealthCheck/Checks/RemotePathMappingCheckFixture.cs +++ b/src/NzbDrone.Core.Test/HealthCheck/Checks/RemotePathMappingCheckFixture.cs @@ -71,6 +71,10 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks .Setup(s => s.GetDownloadClients()) .Returns(new IDownloadClient[] { _downloadClient.Object }); + Mocker.GetMock() + .Setup(s => s.Get(It.IsAny())) + .Returns(_downloadClient.Object); + Mocker.GetMock() .Setup(s => s.EnableCompletedDownloadHandling) .Returns(true); diff --git a/src/NzbDrone.Core.Test/HistoryTests/HistoryRepositoryFixture.cs b/src/NzbDrone.Core.Test/HistoryTests/HistoryRepositoryFixture.cs index b10506cb7..da0e38768 100644 --- a/src/NzbDrone.Core.Test/HistoryTests/HistoryRepositoryFixture.cs +++ b/src/NzbDrone.Core.Test/HistoryTests/HistoryRepositoryFixture.cs @@ -8,12 +8,12 @@ using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.HistoryTests { [TestFixture] - public class HistoryRepositoryFixture : DbTest + public class HistoryRepositoryFixture : DbTest { [Test] public void should_read_write_dictionary() { - var history = Builder.CreateNew() + var history = Builder.CreateNew() .With(c => c.Quality = new QualityModel()) .BuildNew(); @@ -28,16 +28,16 @@ namespace NzbDrone.Core.Test.HistoryTests [Test] public void should_get_download_history() { - var historyBluray = Builder.CreateNew() + var historyBluray = Builder.CreateNew() .With(c => c.Quality = new QualityModel(Quality.MP3)) .With(c => c.AuthorId = 12) - .With(c => c.EventType = HistoryEventType.Grabbed) + .With(c => c.EventType = EntityHistoryEventType.Grabbed) .BuildNew(); - var historyDvd = Builder.CreateNew() + var historyDvd = Builder.CreateNew() .With(c => c.Quality = new QualityModel(Quality.AZW3)) .With(c => c.AuthorId = 12) - .With(c => c.EventType = HistoryEventType.Grabbed) + .With(c => c.EventType = EntityHistoryEventType.Grabbed) .BuildNew(); Subject.Insert(historyBluray); diff --git a/src/NzbDrone.Core.Test/HistoryTests/HistoryServiceFixture.cs b/src/NzbDrone.Core.Test/HistoryTests/HistoryServiceFixture.cs index 1a24cc848..462b9575d 100644 --- a/src/NzbDrone.Core.Test/HistoryTests/HistoryServiceFixture.cs +++ b/src/NzbDrone.Core.Test/HistoryTests/HistoryServiceFixture.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.IO; -using System.Linq; using FizzWare.NBuilder; using Moq; using NUnit.Framework; @@ -69,7 +68,7 @@ namespace NzbDrone.Core.Test.HistoryTests Subject.Handle(new TrackImportedEvent(localTrack, trackFile, new List(), true, downloadClientItem)); Mocker.GetMock() - .Verify(v => v.Insert(It.Is(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localTrack.Path)))); + .Verify(v => v.Insert(It.Is(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localTrack.Path)))); } } } diff --git a/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedHistoryItemsFixture.cs b/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedHistoryItemsFixture.cs index 41d5c633f..6ae56e596 100644 --- a/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedHistoryItemsFixture.cs +++ b/src/NzbDrone.Core.Test/Housekeeping/Housekeepers/CleanupOrphanedHistoryItemsFixture.cs @@ -1,7 +1,8 @@ -using FizzWare.NBuilder; +using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Books; +using NzbDrone.Core.History; using NzbDrone.Core.Housekeeping.Housekeepers; using NzbDrone.Core.Qualities; using NzbDrone.Core.Test.Framework; @@ -9,7 +10,7 @@ using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.Housekeeping.Housekeepers { [TestFixture] - public class CleanupOrphanedHistoryItemsFixture : DbTest + public class CleanupOrphanedHistoryItemsFixture : DbTest { private Author _author; private Book _book; @@ -39,7 +40,7 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers { GivenBook(); - var history = Builder.CreateNew() + var history = Builder.CreateNew() .With(h => h.Quality = new QualityModel()) .With(h => h.BookId = _book.Id) .BuildNew(); @@ -54,7 +55,7 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers { GivenAuthor(); - var history = Builder.CreateNew() + var history = Builder.CreateNew() .With(h => h.Quality = new QualityModel()) .With(h => h.AuthorId = _author.Id) .BuildNew(); @@ -70,7 +71,7 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers GivenAuthor(); GivenBook(); - var history = Builder.CreateListOfSize(2) + var history = Builder.CreateListOfSize(2) .All() .With(h => h.Quality = new QualityModel()) .With(h => h.BookId = _book.Id) @@ -91,7 +92,7 @@ namespace NzbDrone.Core.Test.Housekeeping.Housekeepers GivenAuthor(); GivenBook(); - var history = Builder.CreateListOfSize(2) + var history = Builder.CreateListOfSize(2) .All() .With(h => h.Quality = new QualityModel()) .With(h => h.AuthorId = _author.Id) diff --git a/src/NzbDrone.Core.Test/MusicTests/RefreshArtistServiceFixture.cs b/src/NzbDrone.Core.Test/MusicTests/RefreshArtistServiceFixture.cs index 474e24a2f..230e8463d 100644 --- a/src/NzbDrone.Core.Test/MusicTests/RefreshArtistServiceFixture.cs +++ b/src/NzbDrone.Core.Test/MusicTests/RefreshArtistServiceFixture.cs @@ -73,8 +73,8 @@ namespace NzbDrone.Core.Test.MusicTests .Returns(new List()); Mocker.GetMock() - .Setup(x => x.GetByAuthor(It.IsAny(), It.IsAny())) - .Returns(new List()); + .Setup(x => x.GetByAuthor(It.IsAny(), It.IsAny())) + .Returns(new List()); Mocker.GetMock() .Setup(x => x.FindByForeignId(It.IsAny>())) diff --git a/src/NzbDrone.Core.Test/QueueTests/QueueServiceFixture.cs b/src/NzbDrone.Core.Test/QueueTests/QueueServiceFixture.cs index 64959f8d7..5bc9584f2 100644 --- a/src/NzbDrone.Core.Test/QueueTests/QueueServiceFixture.cs +++ b/src/NzbDrone.Core.Test/QueueTests/QueueServiceFixture.cs @@ -51,12 +51,12 @@ namespace NzbDrone.Core.Test.QueueTests .Build() .ToList(); - var historyItem = Builder.CreateNew() + var historyItem = Builder.CreateNew() .Build(); Mocker.GetMock() - .Setup(c => c.Find(It.IsAny(), HistoryEventType.Grabbed)).Returns( - new List { historyItem }); + .Setup(c => c.Find(It.IsAny(), EntityHistoryEventType.Grabbed)).Returns( + new List { historyItem }); } [Test] diff --git a/src/NzbDrone.Core/Analytics/AnalyticsService.cs b/src/NzbDrone.Core/Analytics/AnalyticsService.cs index c622bc088..f22d3d908 100644 --- a/src/NzbDrone.Core/Analytics/AnalyticsService.cs +++ b/src/NzbDrone.Core/Analytics/AnalyticsService.cs @@ -30,7 +30,7 @@ namespace NzbDrone.Core.Analytics { get { - var lastRecord = _historyService.Paged(new PagingSpec() { Page = 0, PageSize = 1, SortKey = "date", SortDirection = SortDirection.Descending }); + var lastRecord = _historyService.Paged(new PagingSpec() { Page = 0, PageSize = 1, SortKey = "date", SortDirection = SortDirection.Descending }); var monthAgo = DateTime.UtcNow.AddMonths(-1); return lastRecord.Records.Any(v => v.Date > monthAgo); diff --git a/src/NzbDrone.Core/Datastore/Migration/020_add_download_history.cs b/src/NzbDrone.Core/Datastore/Migration/020_add_download_history.cs new file mode 100644 index 000000000..e6a422585 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/020_add_download_history.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Data; +using FluentMigrator; +using NzbDrone.Common.Serializer; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(20)] + public class AddDownloadHistory : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Create.TableForModel("DownloadHistory") + .WithColumn("EventType").AsInt32().NotNullable() + .WithColumn("AuthorId").AsInt32().NotNullable() + .WithColumn("DownloadId").AsString().NotNullable() + .WithColumn("SourceTitle").AsString().NotNullable() + .WithColumn("Date").AsDateTime().NotNullable() + .WithColumn("Protocol").AsInt32().Nullable() + .WithColumn("IndexerId").AsInt32().Nullable() + .WithColumn("DownloadClientId").AsInt32().Nullable() + .WithColumn("Release").AsString().Nullable() + .WithColumn("Data").AsString().Nullable(); + + Create.Index().OnTable("DownloadHistory").OnColumn("EventType"); + Create.Index().OnTable("DownloadHistory").OnColumn("SeriesId"); + Create.Index().OnTable("DownloadHistory").OnColumn("DownloadId"); + + Execute.WithConnection(InitialImportedDownloadHistory); + + Execute.Sql("DELETE From History where EventType = 8;"); + } + + private static readonly Dictionary EventTypeMap = new Dictionary() + { + // EpisodeHistoryType.Grabbed -> DownloadHistoryType.Grabbed + { 1, 1 }, + + // EpisodeHistoryType.DownloadFolderImported -> DownloadHistoryType.DownloadImported + { 8, 2 }, + + // EpisodeHistoryType.DownloadFailed -> DownloadHistoryType.DownloadFailed + { 4, 3 }, + + // EpisodeHistoryType.DownloadIgnored -> DownloadHistoryType.DownloadIgnored + { 10, 4 }, + + // EpisodeHistoryType.DownloadImportIncomplete -> DownloadHistoryType.DownloadImportIncomplete + { 7, 6 } + }; + + private void InitialImportedDownloadHistory(IDbConnection conn, IDbTransaction tran) + { + using (var cmd = conn.CreateCommand()) + { + cmd.Transaction = tran; + cmd.CommandText = "SELECT AuthorId, DownloadId, EventType, SourceTitle, Date, Data FROM History WHERE DownloadId IS NOT NULL AND EventType IN (1, 8, 4, 10, 7) GROUP BY EventType, DownloadId"; + + using (var reader = cmd.ExecuteReader()) + { + while (reader.Read()) + { + var seriesId = reader.GetInt32(0); + var downloadId = reader.GetString(1); + var eventType = reader.GetInt32(2); + var sourceTitle = reader.GetString(3); + var date = reader.GetDateTime(4); + var rawData = reader.GetString(5); + var data = Json.Deserialize>(rawData); + + var downloadHistoryEventType = EventTypeMap[eventType]; + var protocol = data.ContainsKey("protocol") ? Convert.ToInt32(data["protocol"]) : (int?)null; + var downloadHistoryData = new Dictionary(); + + if (data.ContainsKey("indexer")) + { + downloadHistoryData.Add("indexer", data["indexer"]); + } + + if (data.ContainsKey("downloadClient")) + { + downloadHistoryData.Add("downloadClient", data["downloadClient"]); + } + + using (var updateCmd = conn.CreateCommand()) + { + updateCmd.Transaction = tran; + updateCmd.CommandText = @"INSERT INTO DownloadHistory (EventType, AuthorId, DownloadId, SourceTitle, Date, Protocol, Data) VALUES (?, ?, ?, ?, ?, ?, ?)"; + updateCmd.AddParameter(downloadHistoryEventType); + updateCmd.AddParameter(seriesId); + updateCmd.AddParameter(downloadId); + updateCmd.AddParameter(sourceTitle); + updateCmd.AddParameter(date); + updateCmd.AddParameter(protocol); + updateCmd.AddParameter(downloadHistoryData.ToJson()); + + updateCmd.ExecuteNonQuery(); + } + } + } + } + } + } +} diff --git a/src/NzbDrone.Core/Datastore/TableMapping.cs b/src/NzbDrone.Core/Datastore/TableMapping.cs index 94cfbfa43..0c9e83d0e 100644 --- a/src/NzbDrone.Core/Datastore/TableMapping.cs +++ b/src/NzbDrone.Core/Datastore/TableMapping.cs @@ -10,10 +10,12 @@ using NzbDrone.Core.Configuration; using NzbDrone.Core.CustomFilters; using NzbDrone.Core.Datastore.Converters; using NzbDrone.Core.Download; +using NzbDrone.Core.Download.History; using NzbDrone.Core.Download.Pending; using NzbDrone.Core.Extras.Metadata; using NzbDrone.Core.Extras.Metadata.Files; using NzbDrone.Core.Extras.Others; +using NzbDrone.Core.History; using NzbDrone.Core.Http; using NzbDrone.Core.ImportLists; using NzbDrone.Core.ImportLists.Exclusions; @@ -93,7 +95,7 @@ namespace NzbDrone.Core.Datastore .Ignore(d => d.Protocol) .Ignore(d => d.Tags); - Mapper.Entity("History").RegisterModel(); + Mapper.Entity("History").RegisterModel(); Mapper.Entity("Authors") .Ignore(s => s.RootFolderPath) @@ -195,6 +197,8 @@ namespace NzbDrone.Core.Datastore Mapper.Entity("ImportListExclusions").RegisterModel(); Mapper.Entity("HttpResponse").RegisterModel(); + + Mapper.Entity("DownloadHistory").RegisterModel(); } private static void RegisterMappers() diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/AlreadyImportedSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/AlreadyImportedSpecification.cs index 093be0366..8dfa64697 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/AlreadyImportedSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/AlreadyImportedSpecification.cs @@ -53,7 +53,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications } var historyForBook = _historyService.GetByBook(book.Id, null); - var lastGrabbed = historyForBook.FirstOrDefault(h => h.EventType == HistoryEventType.Grabbed); + var lastGrabbed = historyForBook.FirstOrDefault(h => h.EventType == EntityHistoryEventType.Grabbed); if (lastGrabbed == null) { @@ -61,7 +61,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications } var imported = historyForBook.FirstOrDefault(h => - h.EventType == HistoryEventType.DownloadImported && + h.EventType == EntityHistoryEventType.BookFileImported && h.DownloadId == lastGrabbed.DownloadId); if (imported == null) diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/HistorySpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/HistorySpecification.cs index 0c5557362..b23b0db36 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/HistorySpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/RssSync/HistorySpecification.cs @@ -51,7 +51,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync _logger.Debug("Checking current status of book [{0}] in history", book.Id); var mostRecent = _historyService.MostRecentForBook(book.Id); - if (mostRecent != null && mostRecent.EventType == HistoryEventType.Grabbed) + if (mostRecent != null && mostRecent.EventType == EntityHistoryEventType.Grabbed) { var recent = mostRecent.Date.After(DateTime.UtcNow.AddHours(-12)); diff --git a/src/NzbDrone.Core/Download/AlbumGrabbedEvent.cs b/src/NzbDrone.Core/Download/BookGrabbedEvent.cs similarity index 72% rename from src/NzbDrone.Core/Download/AlbumGrabbedEvent.cs rename to src/NzbDrone.Core/Download/BookGrabbedEvent.cs index 4dca3b527..f8e7445e1 100644 --- a/src/NzbDrone.Core/Download/AlbumGrabbedEvent.cs +++ b/src/NzbDrone.Core/Download/BookGrabbedEvent.cs @@ -1,4 +1,4 @@ -using NzbDrone.Common.Messaging; +using NzbDrone.Common.Messaging; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Download @@ -6,7 +6,9 @@ namespace NzbDrone.Core.Download public class BookGrabbedEvent : IEvent { public RemoteBook Book { get; private set; } + public int DownloadClientId { get; set; } public string DownloadClient { get; set; } + public string DownloadClientName { get; set; } public string DownloadId { get; set; } public BookGrabbedEvent(RemoteBook book) diff --git a/src/NzbDrone.Core/Download/DownloadService.cs b/src/NzbDrone.Core/Download/DownloadService.cs index 6355f1aac..9a28fa84e 100644 --- a/src/NzbDrone.Core/Download/DownloadService.cs +++ b/src/NzbDrone.Core/Download/DownloadService.cs @@ -102,6 +102,8 @@ namespace NzbDrone.Core.Download var bookGrabbedEvent = new BookGrabbedEvent(remoteBook); bookGrabbedEvent.DownloadClient = downloadClient.Name; + bookGrabbedEvent.DownloadClientId = downloadClient.Definition.Id; + bookGrabbedEvent.DownloadClientName = downloadClient.Definition.Name; if (!string.IsNullOrWhiteSpace(downloadClientId)) { diff --git a/src/NzbDrone.Core/Download/FailedDownloadService.cs b/src/NzbDrone.Core/Download/FailedDownloadService.cs index 9dde73210..7d9dbbcfc 100644 --- a/src/NzbDrone.Core/Download/FailedDownloadService.cs +++ b/src/NzbDrone.Core/Download/FailedDownloadService.cs @@ -18,12 +18,15 @@ namespace NzbDrone.Core.Download public class FailedDownloadService : IFailedDownloadService { private readonly IHistoryService _historyService; + private readonly ITrackedDownloadService _trackedDownloadService; private readonly IEventAggregator _eventAggregator; public FailedDownloadService(IHistoryService historyService, + ITrackedDownloadService trackedDownloadService, IEventAggregator eventAggregator) { _historyService = historyService; + _trackedDownloadService = trackedDownloadService; _eventAggregator = eventAggregator; } @@ -34,22 +37,24 @@ namespace NzbDrone.Core.Download var downloadId = history.DownloadId; if (downloadId.IsNullOrWhiteSpace()) { - PublishDownloadFailedEvent(new List { history }, "Manually marked as failed", skipReDownload: skipReDownload); + PublishDownloadFailedEvent(new List { history }, "Manually marked as failed", skipReDownload: skipReDownload); } else { - var grabbedHistory = _historyService.Find(downloadId, HistoryEventType.Grabbed).ToList(); + var grabbedHistory = _historyService.Find(downloadId, EntityHistoryEventType.Grabbed).ToList(); PublishDownloadFailedEvent(grabbedHistory, "Manually marked as failed"); } } public void MarkAsFailed(string downloadId, bool skipReDownload = false) { - var history = _historyService.Find(downloadId, HistoryEventType.Grabbed); + var history = _historyService.Find(downloadId, EntityHistoryEventType.Grabbed); if (history.Any()) { - PublishDownloadFailedEvent(history, "Manually marked as failed", skipReDownload: skipReDownload); + var trackedDownload = _trackedDownloadService.Find(downloadId); + + PublishDownloadFailedEvent(history, "Manually marked as failed", trackedDownload, skipReDownload); } } @@ -65,7 +70,7 @@ namespace NzbDrone.Core.Download trackedDownload.DownloadItem.Status == DownloadItemStatus.Failed) { var grabbedItems = _historyService - .Find(trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed) + .Find(trackedDownload.DownloadItem.DownloadId, EntityHistoryEventType.Grabbed) .ToList(); if (grabbedItems.Empty()) @@ -86,7 +91,7 @@ namespace NzbDrone.Core.Download } var grabbedItems = _historyService - .Find(trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed) + .Find(trackedDownload.DownloadItem.DownloadId, EntityHistoryEventType.Grabbed) .ToList(); if (grabbedItems.Empty()) @@ -109,7 +114,7 @@ namespace NzbDrone.Core.Download PublishDownloadFailedEvent(grabbedItems, failure, trackedDownload); } - private void PublishDownloadFailedEvent(List historyItems, string message, TrackedDownload trackedDownload = null, bool skipReDownload = false) + private void PublishDownloadFailedEvent(List historyItems, string message, TrackedDownload trackedDownload = null, bool skipReDownload = false) { var historyItem = historyItems.First(); @@ -119,7 +124,7 @@ namespace NzbDrone.Core.Download BookIds = historyItems.Select(h => h.BookId).ToList(), Quality = historyItem.Quality, SourceTitle = historyItem.SourceTitle, - DownloadClient = historyItem.Data.GetValueOrDefault(History.History.DOWNLOAD_CLIENT), + DownloadClient = historyItem.Data.GetValueOrDefault(EntityHistory.DOWNLOAD_CLIENT), DownloadId = historyItem.DownloadId, Message = message, Data = historyItem.Data, diff --git a/src/NzbDrone.Core/Download/History/DownloadHistory.cs b/src/NzbDrone.Core/Download/History/DownloadHistory.cs new file mode 100644 index 000000000..e61ca4f59 --- /dev/null +++ b/src/NzbDrone.Core/Download/History/DownloadHistory.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using NzbDrone.Core.Datastore; +using NzbDrone.Core.Indexers; +using NzbDrone.Core.Parser.Model; + +namespace NzbDrone.Core.Download.History +{ + public class DownloadHistory : ModelBase + { + public DownloadHistoryEventType EventType { get; set; } + public int AuthorId { get; set; } + public string DownloadId { get; set; } + public string SourceTitle { get; set; } + public DateTime Date { get; set; } + public DownloadProtocol Protocol { get; set; } + public int IndexerId { get; set; } + public int DownloadClientId { get; set; } + public ReleaseInfo Release { get; set; } + public Dictionary Data { get; set; } + public DownloadHistory() + { + Data = new Dictionary(); + } + } + + public enum DownloadHistoryEventType + { + DownloadGrabbed = 1, + DownloadImported = 2, + DownloadFailed = 3, + DownloadIgnored = 4, + FileImported = 5, + DownloadImportIncomplete = 6 + } +} diff --git a/src/NzbDrone.Core/Download/History/DownloadHistoryRepository.cs b/src/NzbDrone.Core/Download/History/DownloadHistoryRepository.cs new file mode 100644 index 000000000..6e1892e8f --- /dev/null +++ b/src/NzbDrone.Core/Download/History/DownloadHistoryRepository.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; +using System.Linq; +using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging.Events; + +namespace NzbDrone.Core.Download.History +{ + public interface IDownloadHistoryRepository : IBasicRepository + { + List FindByDownloadId(string downloadId); + void DeleteByAuthorId(int authorId); + } + + public class DownloadHistoryRepository : BasicRepository, IDownloadHistoryRepository + { + public DownloadHistoryRepository(IMainDatabase database, IEventAggregator eventAggregator) + : base(database, eventAggregator) + { + } + + public List FindByDownloadId(string downloadId) + { + return Query(h => h.DownloadId == downloadId) + .OrderByDescending(h => h.Date) + .ToList(); + } + + public void DeleteByAuthorId(int authorId) + { + Delete(r => r.AuthorId == authorId); + } + } +} diff --git a/src/NzbDrone.Core/Download/History/DownloadHistoryService.cs b/src/NzbDrone.Core/Download/History/DownloadHistoryService.cs new file mode 100644 index 000000000..b479adece --- /dev/null +++ b/src/NzbDrone.Core/Download/History/DownloadHistoryService.cs @@ -0,0 +1,240 @@ +using System; +using System.IO; +using NzbDrone.Common.Extensions; +using NzbDrone.Common.Serializer; +using NzbDrone.Core.Books.Events; +using NzbDrone.Core.History; +using NzbDrone.Core.MediaFiles.Events; +using NzbDrone.Core.Messaging.Events; + +namespace NzbDrone.Core.Download.History +{ + public interface IDownloadHistoryService + { + bool DownloadAlreadyImported(string downloadId); + DownloadHistory GetLatestDownloadHistoryItem(string downloadId); + } + + public class DownloadHistoryService : IDownloadHistoryService, + IHandle, + IHandle, + IHandle, + IHandle, + IHandle, + IHandle, + IHandle + { + private readonly IDownloadHistoryRepository _repository; + private readonly IHistoryService _historyService; + + public DownloadHistoryService(IDownloadHistoryRepository repository, IHistoryService historyService) + { + _repository = repository; + _historyService = historyService; + } + + public bool DownloadAlreadyImported(string downloadId) + { + var events = _repository.FindByDownloadId(downloadId); + + // Events are ordered by date descending, if a grabbed event comes before an imported event then it was never imported + // or grabbed again after importing and should be reprocessed. + foreach (var e in events) + { + if (e.EventType == DownloadHistoryEventType.DownloadGrabbed) + { + return false; + } + + if (e.EventType == DownloadHistoryEventType.DownloadImported) + { + return true; + } + } + + return false; + } + + public DownloadHistory GetLatestDownloadHistoryItem(string downloadId) + { + var events = _repository.FindByDownloadId(downloadId); + + // Events are ordered by date descending. We'll return the most recent expected event. + foreach (var e in events) + { + if (e.EventType == DownloadHistoryEventType.DownloadGrabbed) + { + return e; + } + + if (e.EventType == DownloadHistoryEventType.DownloadImported) + { + return e; + } + + if (e.EventType == DownloadHistoryEventType.DownloadFailed) + { + return e; + } + + if (e.EventType == DownloadHistoryEventType.DownloadImportIncomplete) + { + return e; + } + } + + return null; + } + + public void Handle(BookGrabbedEvent message) + { + var history = new DownloadHistory + { + EventType = DownloadHistoryEventType.DownloadGrabbed, + AuthorId = message.Book.Author.Id, + DownloadId = message.DownloadId, + SourceTitle = message.Book.Release.Title, + Date = DateTime.UtcNow, + Protocol = message.Book.Release.DownloadProtocol, + IndexerId = message.Book.Release.IndexerId, + DownloadClientId = message.DownloadClientId, + Release = message.Book.Release + }; + + history.Data.Add("Indexer", message.Book.Release.Indexer); + history.Data.Add("DownloadClient", message.DownloadClient); + history.Data.Add("DownloadClientName", message.DownloadClientName); + history.Data.Add("PreferredWordScore", message.Book.PreferredWordScore.ToString()); + + _repository.Insert(history); + } + + public void Handle(TrackImportedEvent message) + { + if (!message.NewDownload) + { + return; + } + + var downloadId = message.DownloadId; + + // Try to find the downloadId if the user used manual import (from wanted: missing) or the + // API to import and downloadId wasn't provided. + if (downloadId.IsNullOrWhiteSpace()) + { + downloadId = _historyService.FindDownloadId(message); + } + + if (downloadId.IsNullOrWhiteSpace()) + { + return; + } + + var history = new DownloadHistory + { + EventType = DownloadHistoryEventType.FileImported, + AuthorId = message.BookInfo.Author.Id, + DownloadId = downloadId, + SourceTitle = message.BookInfo.Path, + Date = DateTime.UtcNow, + Protocol = message.DownloadClientInfo.Protocol, + DownloadClientId = message.DownloadClientInfo.Id + }; + + history.Data.Add("DownloadClient", message.DownloadClientInfo.Type); + history.Data.Add("DownloadClientName", message.DownloadClientInfo.Name); + history.Data.Add("SourcePath", message.BookInfo.Path); + history.Data.Add("DestinationPath", message.ImportedBook.Path); + + _repository.Insert(history); + } + + public void Handle(BookImportIncompleteEvent message) + { + var history = new DownloadHistory + { + EventType = DownloadHistoryEventType.DownloadImportIncomplete, + AuthorId = message.TrackedDownload.RemoteBook?.Author.Id ?? 0, + DownloadId = message.TrackedDownload.DownloadItem.DownloadId, + SourceTitle = message.TrackedDownload.DownloadItem.OutputPath.ToString(), + Date = DateTime.UtcNow, + Protocol = message.TrackedDownload.Protocol, + DownloadClientId = message.TrackedDownload.DownloadClient + }; + + history.Data.Add("DownloadClient", message.TrackedDownload.DownloadItem.DownloadClientInfo.Type); + history.Data.Add("DownloadClientName", message.TrackedDownload.DownloadItem.DownloadClientInfo.Name); + history.Data.Add("StatusMessages", message.TrackedDownload.StatusMessages.ToJson()); + + _repository.Insert(history); + } + + public void Handle(DownloadCompletedEvent message) + { + var history = new DownloadHistory + { + EventType = DownloadHistoryEventType.DownloadImported, + AuthorId = message.TrackedDownload.RemoteBook.Author.Id, + DownloadId = message.TrackedDownload.DownloadItem.DownloadId, + SourceTitle = message.TrackedDownload.DownloadItem.OutputPath.ToString(), + Date = DateTime.UtcNow, + Protocol = message.TrackedDownload.Protocol, + DownloadClientId = message.TrackedDownload.DownloadClient + }; + + history.Data.Add("DownloadClient", message.TrackedDownload.DownloadItem.DownloadClientInfo.Type); + history.Data.Add("DownloadClientName", message.TrackedDownload.DownloadItem.DownloadClientInfo.Name); + + _repository.Insert(history); + } + + public void Handle(DownloadFailedEvent message) + { + // Don't track failed download for an unknown download + if (message.TrackedDownload == null) + { + return; + } + + var history = new DownloadHistory + { + EventType = DownloadHistoryEventType.DownloadFailed, + AuthorId = message.AuthorId, + DownloadId = message.DownloadId, + SourceTitle = message.SourceTitle, + Date = DateTime.UtcNow, + Protocol = message.TrackedDownload.Protocol, + DownloadClientId = message.TrackedDownload.DownloadClient + }; + + history.Data.Add("DownloadClient", message.TrackedDownload.DownloadItem.DownloadClientInfo.Type); + history.Data.Add("DownloadClientName", message.TrackedDownload.DownloadItem.DownloadClientInfo.Name); + + _repository.Insert(history); + } + + public void Handle(DownloadIgnoredEvent message) + { + var history = new DownloadHistory + { + EventType = DownloadHistoryEventType.DownloadIgnored, + AuthorId = message.AuthorId, + DownloadId = message.DownloadId, + SourceTitle = message.SourceTitle, + Date = DateTime.UtcNow, + Protocol = message.DownloadClientInfo.Protocol, + DownloadClientId = message.DownloadClientInfo.Id + }; + + history.Data.Add("DownloadClient", message.DownloadClientInfo.Type); + history.Data.Add("DownloadClientName", message.DownloadClientInfo.Name); + + _repository.Insert(history); + } + + public void Handle(AuthorDeletedEvent message) + { + _repository.DeleteByAuthorId(message.Author.Id); + } + } +} diff --git a/src/NzbDrone.Core/Download/IDownloadClient.cs b/src/NzbDrone.Core/Download/IDownloadClient.cs index 93c7a1cbb..11537a86e 100644 --- a/src/NzbDrone.Core/Download/IDownloadClient.cs +++ b/src/NzbDrone.Core/Download/IDownloadClient.cs @@ -8,7 +8,6 @@ namespace NzbDrone.Core.Download public interface IDownloadClient : IProvider { DownloadProtocol Protocol { get; } - string Download(RemoteBook remoteBook); IEnumerable GetItems(); DownloadClientItem GetImportItem(DownloadClientItem item, DownloadClientItem previousImportAttempt); diff --git a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadAlreadyImported.cs b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadAlreadyImported.cs index f5b6ba04c..10108325b 100644 --- a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadAlreadyImported.cs +++ b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadAlreadyImported.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using NzbDrone.Common.Extensions; using NzbDrone.Core.History; @@ -7,12 +7,12 @@ namespace NzbDrone.Core.Download.TrackedDownloads { public interface ITrackedDownloadAlreadyImported { - bool IsImported(TrackedDownload trackedDownload, List historyItems); + bool IsImported(TrackedDownload trackedDownload, List historyItems); } public class TrackedDownloadAlreadyImported : ITrackedDownloadAlreadyImported { - public bool IsImported(TrackedDownload trackedDownload, List historyItems) + public bool IsImported(TrackedDownload trackedDownload, List historyItems) { if (historyItems.Empty()) { @@ -33,7 +33,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads return false; } - return new[] { HistoryEventType.DownloadImported, HistoryEventType.BookFileImported }.Contains(lastHistoryItem.EventType); + return lastHistoryItem.EventType == EntityHistoryEventType.BookFileImported; }); return allBooksImportedInHistory; diff --git a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs index a6138164a..bf5de6f98 100644 --- a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs +++ b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs @@ -7,6 +7,7 @@ using NzbDrone.Common.Extensions; using NzbDrone.Common.Serializer; using NzbDrone.Core.Books; using NzbDrone.Core.Books.Events; +using NzbDrone.Core.Download.History; using NzbDrone.Core.History; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; @@ -28,7 +29,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads private readonly IParsingService _parsingService; private readonly IHistoryService _historyService; private readonly IEventAggregator _eventAggregator; - private readonly ITrackedDownloadAlreadyImported _trackedDownloadAlreadyImported; + private readonly IDownloadHistoryService _downloadHistoryService; private readonly Logger _logger; private readonly ICached _cache; @@ -36,13 +37,13 @@ namespace NzbDrone.Core.Download.TrackedDownloads ICacheManager cacheManager, IHistoryService historyService, IEventAggregator eventAggregator, - ITrackedDownloadAlreadyImported trackedDownloadAlreadyImported, + IDownloadHistoryService downloadHistoryService, Logger logger) { _parsingService = parsingService; _historyService = historyService; _eventAggregator = eventAggregator; - _trackedDownloadAlreadyImported = trackedDownloadAlreadyImported; + _downloadHistoryService = downloadHistoryService; _cache = cacheManager.GetCache(GetType()); _logger = logger; } @@ -129,31 +130,25 @@ namespace NzbDrone.Core.Download.TrackedDownloads trackedDownload.RemoteBook = _parsingService.Map(parsedBookInfo); } - if (historyItems.Any()) - { - var firstHistoryItem = historyItems.First(); - var state = GetStateFromHistory(firstHistoryItem); - - // One potential issue here is if the latest is imported, but other episodes are ignored or never imported. - // It's unlikely that will happen, but could happen if additional episodes are added to season after it's already imported. - if (state == TrackedDownloadState.Imported) - { - var allImported = _trackedDownloadAlreadyImported.IsImported(trackedDownload, historyItems); + var downloadHistory = _downloadHistoryService.GetLatestDownloadHistoryItem(downloadItem.DownloadId); - trackedDownload.State = allImported ? TrackedDownloadState.Imported : TrackedDownloadState.Downloading; - } - else - { - trackedDownload.State = state; - } + if (downloadHistory != null) + { + var state = GetStateFromHistory(downloadHistory.EventType); + trackedDownload.State = state; - if (firstHistoryItem.EventType == HistoryEventType.BookImportIncomplete) + if (downloadHistory.EventType == DownloadHistoryEventType.DownloadImportIncomplete) { - var messages = Json.Deserialize>(firstHistoryItem?.Data["statusMessages"]).ToArray(); + var messages = Json.Deserialize>(downloadHistory.Data["statusMessages"]).ToArray(); trackedDownload.Warn(messages); } + } + + if (historyItems.Any()) + { + var firstHistoryItem = historyItems.First(); + var grabbedEvent = historyItems.FirstOrDefault(v => v.EventType == EntityHistoryEventType.Grabbed); - var grabbedEvent = historyItems.FirstOrDefault(v => v.EventType == HistoryEventType.Grabbed); trackedDownload.Indexer = grabbedEvent?.Data["indexer"]; if (parsedBookInfo == null || @@ -162,7 +157,6 @@ namespace NzbDrone.Core.Download.TrackedDownloads trackedDownload.RemoteBook.Books.Empty()) { // Try parsing the original source title and if that fails, try parsing it as a special - // TODO: Pass the TVDB ID and TVRage IDs in as well so we have a better chance for finding the item var historyAuthor = firstHistoryItem.Author; var historyBooks = new List { firstHistoryItem.Book }; @@ -172,7 +166,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads { trackedDownload.RemoteBook = _parsingService.Map(parsedBookInfo, firstHistoryItem.AuthorId, - historyItems.Where(v => v.EventType == HistoryEventType.Grabbed).Select(h => h.BookId) + historyItems.Where(v => v.EventType == EntityHistoryEventType.Grabbed).Select(h => h.BookId) .Distinct()); } else @@ -186,7 +180,7 @@ namespace NzbDrone.Core.Download.TrackedDownloads { trackedDownload.RemoteBook = _parsingService.Map(parsedBookInfo, firstHistoryItem.AuthorId, - historyItems.Where(v => v.EventType == HistoryEventType.Grabbed).Select(h => h.BookId) + historyItems.Where(v => v.EventType == EntityHistoryEventType.Grabbed).Select(h => h.BookId) .Distinct()); } } @@ -244,27 +238,21 @@ namespace NzbDrone.Core.Download.TrackedDownloads } } - private static TrackedDownloadState GetStateFromHistory(NzbDrone.Core.History.History history) + private static TrackedDownloadState GetStateFromHistory(DownloadHistoryEventType eventType) { - switch (history.EventType) + switch (eventType) { - case HistoryEventType.BookImportIncomplete: + case DownloadHistoryEventType.DownloadImportIncomplete: return TrackedDownloadState.ImportFailed; - case HistoryEventType.DownloadImported: + case DownloadHistoryEventType.DownloadImported: return TrackedDownloadState.Imported; - case HistoryEventType.DownloadFailed: + case DownloadHistoryEventType.DownloadFailed: return TrackedDownloadState.DownloadFailed; - case HistoryEventType.DownloadIgnored: + case DownloadHistoryEventType.DownloadIgnored: return TrackedDownloadState.Ignored; + default: + return TrackedDownloadState.Downloading; } - - // Since DownloadComplete is a new event type, we can't assume it exists for old downloads - if (history.EventType == HistoryEventType.BookFileImported) - { - return DateTime.UtcNow.Subtract(history.Date).TotalSeconds < 60 ? TrackedDownloadState.Importing : TrackedDownloadState.Imported; - } - - return TrackedDownloadState.Downloading; } public void Handle(BookDeletedEvent message) diff --git a/src/NzbDrone.Core/HealthCheck/Checks/RemotePathMappingCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/RemotePathMappingCheck.cs index af116cdba..34a6903c9 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/RemotePathMappingCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/RemotePathMappingCheck.cs @@ -139,7 +139,7 @@ namespace NzbDrone.Core.HealthCheck.Checks // If the previous case did not match then the failure occured in DownloadedTracksImportService, // while trying to locate the files reported by the download client - var client = _downloadClientProvider.GetDownloadClients().FirstOrDefault(x => x.Definition.Name == failureMessage.DownloadClient); + var client = _downloadClientProvider.Get(failureMessage.DownloadClientInfo.Id); try { var status = client.GetStatus(); diff --git a/src/NzbDrone.Core/History/History.cs b/src/NzbDrone.Core/History/EntityHistory.cs similarity index 84% rename from src/NzbDrone.Core/History/History.cs rename to src/NzbDrone.Core/History/EntityHistory.cs index a0f547a27..6bc31a860 100644 --- a/src/NzbDrone.Core/History/History.cs +++ b/src/NzbDrone.Core/History/EntityHistory.cs @@ -6,11 +6,11 @@ using NzbDrone.Core.Qualities; namespace NzbDrone.Core.History { - public class History : ModelBase + public class EntityHistory : ModelBase { public const string DOWNLOAD_CLIENT = "downloadClient"; - public History() + public EntityHistory() { Data = new Dictionary(); } @@ -22,17 +22,16 @@ namespace NzbDrone.Core.History public DateTime Date { get; set; } public Book Book { get; set; } public Author Author { get; set; } - public HistoryEventType EventType { get; set; } + public EntityHistoryEventType EventType { get; set; } public Dictionary Data { get; set; } public string DownloadId { get; set; } } - public enum HistoryEventType + public enum EntityHistoryEventType { Unknown = 0, Grabbed = 1, - AuthorFolderImported = 2, BookFileImported = 3, DownloadFailed = 4, BookFileDeleted = 5, diff --git a/src/NzbDrone.Core/History/HistoryRepository.cs b/src/NzbDrone.Core/History/HistoryRepository.cs index b321afffe..5686e9ba2 100644 --- a/src/NzbDrone.Core/History/HistoryRepository.cs +++ b/src/NzbDrone.Core/History/HistoryRepository.cs @@ -8,46 +8,46 @@ using NzbDrone.Core.Qualities; namespace NzbDrone.Core.History { - public interface IHistoryRepository : IBasicRepository + public interface IHistoryRepository : IBasicRepository { - History MostRecentForBook(int bookId); - History MostRecentForDownloadId(string downloadId); - List FindByDownloadId(string downloadId); - List GetByAuthor(int authorId, HistoryEventType? eventType); - List GetByBook(int bookId, HistoryEventType? eventType); - List FindDownloadHistory(int idAuthorId, QualityModel quality); + EntityHistory MostRecentForBook(int bookId); + EntityHistory MostRecentForDownloadId(string downloadId); + List FindByDownloadId(string downloadId); + List GetByAuthor(int authorId, EntityHistoryEventType? eventType); + List GetByBook(int bookId, EntityHistoryEventType? eventType); + List FindDownloadHistory(int idAuthorId, QualityModel quality); void DeleteForAuthor(int authorId); - List Since(DateTime date, HistoryEventType? eventType); + List Since(DateTime date, EntityHistoryEventType? eventType); } - public class HistoryRepository : BasicRepository, IHistoryRepository + public class HistoryRepository : BasicRepository, IHistoryRepository { public HistoryRepository(IMainDatabase database, IEventAggregator eventAggregator) : base(database, eventAggregator) { } - public History MostRecentForBook(int bookId) + public EntityHistory MostRecentForBook(int bookId) { return Query(h => h.BookId == bookId) .OrderByDescending(h => h.Date) .FirstOrDefault(); } - public History MostRecentForDownloadId(string downloadId) + public EntityHistory MostRecentForDownloadId(string downloadId) { return Query(h => h.DownloadId == downloadId) .OrderByDescending(h => h.Date) .FirstOrDefault(); } - public List FindByDownloadId(string downloadId) + public List FindByDownloadId(string downloadId) { - return _database.QueryJoined( + return _database.QueryJoined( Builder() - .Join((h, a) => h.AuthorId == a.Id) - .Join((h, a) => h.BookId == a.Id) - .Where(h => h.DownloadId == downloadId), + .Join((h, a) => h.AuthorId == a.Id) + .Join((h, a) => h.BookId == a.Id) + .Where(h => h.DownloadId == downloadId), (history, author, book) => { history.Author = author; @@ -56,30 +56,30 @@ namespace NzbDrone.Core.History }).ToList(); } - public List GetByAuthor(int authorId, HistoryEventType? eventType) + public List GetByAuthor(int authorId, EntityHistoryEventType? eventType) { - var builder = Builder().Where(h => h.AuthorId == authorId); + var builder = Builder().Where(h => h.AuthorId == authorId); if (eventType.HasValue) { - builder.Where(h => h.EventType == eventType); + builder.Where(h => h.EventType == eventType); } return Query(builder).OrderByDescending(h => h.Date).ToList(); } - public List GetByBook(int bookId, HistoryEventType? eventType) + public List GetByBook(int bookId, EntityHistoryEventType? eventType) { var builder = Builder() - .Join((h, a) => h.BookId == a.Id) - .Where(h => h.BookId == bookId); + .Join((h, a) => h.BookId == a.Id) + .Where(h => h.BookId == bookId); if (eventType.HasValue) { - builder.Where(h => h.EventType == eventType); + builder.Where(h => h.EventType == eventType); } - return _database.QueryJoined( + return _database.QueryJoined( builder, (history, book) => { @@ -88,9 +88,9 @@ namespace NzbDrone.Core.History }).OrderByDescending(h => h.Date).ToList(); } - public List FindDownloadHistory(int idAuthorId, QualityModel quality) + public List FindDownloadHistory(int idAuthorId, QualityModel quality) { - var allowed = new[] { HistoryEventType.Grabbed, HistoryEventType.DownloadFailed, HistoryEventType.BookFileImported }; + var allowed = new[] { EntityHistoryEventType.Grabbed, EntityHistoryEventType.DownloadFailed, EntityHistoryEventType.BookFileImported }; return Query(h => h.AuthorId == idAuthorId && h.Quality == quality && @@ -103,12 +103,12 @@ namespace NzbDrone.Core.History } protected override SqlBuilder PagedBuilder() => new SqlBuilder() - .Join((h, a) => h.AuthorId == a.Id) + .Join((h, a) => h.AuthorId == a.Id) .Join((l, r) => l.AuthorMetadataId == r.Id) - .Join((h, a) => h.BookId == a.Id); + .Join((h, a) => h.BookId == a.Id); - protected override IEnumerable PagedQuery(SqlBuilder builder) => - _database.QueryJoined(builder, (history, author, metadata, book) => + protected override IEnumerable PagedQuery(SqlBuilder builder) => + _database.QueryJoined(builder, (history, author, metadata, book) => { author.Metadata = metadata; history.Author = author; @@ -116,13 +116,13 @@ namespace NzbDrone.Core.History return history; }); - public List Since(DateTime date, HistoryEventType? eventType) + public List Since(DateTime date, EntityHistoryEventType? eventType) { - var builder = Builder().Where(x => x.Date >= date); + var builder = Builder().Where(x => x.Date >= date); if (eventType.HasValue) { - builder.Where(h => h.EventType == eventType); + builder.Where(h => h.EventType == eventType); } return Query(builder).OrderBy(h => h.Date).ToList(); diff --git a/src/NzbDrone.Core/History/HistoryService.cs b/src/NzbDrone.Core/History/HistoryService.cs index 76f8a980d..ba3ca4f0a 100644 --- a/src/NzbDrone.Core/History/HistoryService.cs +++ b/src/NzbDrone.Core/History/HistoryService.cs @@ -18,16 +18,17 @@ namespace NzbDrone.Core.History { public interface IHistoryService { - PagingSpec Paged(PagingSpec pagingSpec); - History MostRecentForBook(int bookId); - History MostRecentForDownloadId(string downloadId); - History Get(int historyId); - List GetByAuthor(int authorId, HistoryEventType? eventType); - List GetByBook(int bookId, HistoryEventType? eventType); - List Find(string downloadId, HistoryEventType eventType); - List FindByDownloadId(string downloadId); - List Since(DateTime date, HistoryEventType? eventType); - void UpdateMany(IList items); + PagingSpec Paged(PagingSpec pagingSpec); + EntityHistory MostRecentForBook(int bookId); + EntityHistory MostRecentForDownloadId(string downloadId); + EntityHistory Get(int historyId); + List GetByAuthor(int authorId, EntityHistoryEventType? eventType); + List GetByBook(int bookId, EntityHistoryEventType? eventType); + List Find(string downloadId, EntityHistoryEventType eventType); + List FindByDownloadId(string downloadId); + string FindDownloadId(TrackImportedEvent trackedDownload); + List Since(DateTime date, EntityHistoryEventType? eventType); + void UpdateMany(IList items); } public class HistoryService : IHistoryService, @@ -35,7 +36,6 @@ namespace NzbDrone.Core.History IHandle, IHandle, IHandle, - IHandle, IHandle, IHandle, IHandle, @@ -51,62 +51,61 @@ namespace NzbDrone.Core.History _logger = logger; } - public PagingSpec Paged(PagingSpec pagingSpec) + public PagingSpec Paged(PagingSpec pagingSpec) { return _historyRepository.GetPaged(pagingSpec); } - public History MostRecentForBook(int bookId) + public EntityHistory MostRecentForBook(int bookId) { return _historyRepository.MostRecentForBook(bookId); } - public History MostRecentForDownloadId(string downloadId) + public EntityHistory MostRecentForDownloadId(string downloadId) { return _historyRepository.MostRecentForDownloadId(downloadId); } - public History Get(int historyId) + public EntityHistory Get(int historyId) { return _historyRepository.Get(historyId); } - public List GetByAuthor(int authorId, HistoryEventType? eventType) + public List GetByAuthor(int authorId, EntityHistoryEventType? eventType) { return _historyRepository.GetByAuthor(authorId, eventType); } - public List GetByBook(int bookId, HistoryEventType? eventType) + public List GetByBook(int bookId, EntityHistoryEventType? eventType) { return _historyRepository.GetByBook(bookId, eventType); } - public List Find(string downloadId, HistoryEventType eventType) + public List Find(string downloadId, EntityHistoryEventType eventType) { return _historyRepository.FindByDownloadId(downloadId).Where(c => c.EventType == eventType).ToList(); } - public List FindByDownloadId(string downloadId) + public List FindByDownloadId(string downloadId) { return _historyRepository.FindByDownloadId(downloadId); } - private string FindDownloadId(TrackImportedEvent trackedDownload) + public string FindDownloadId(TrackImportedEvent trackedDownload) { _logger.Debug("Trying to find downloadId for {0} from history", trackedDownload.ImportedBook.Path); var bookIds = new List { trackedDownload.BookInfo.Book.Id }; - var allHistory = _historyRepository.FindDownloadHistory(trackedDownload.BookInfo.Author.Id, trackedDownload.ImportedBook.Quality); - //Find download related items for these episdoes + //Find download related items for these episodes var booksHistory = allHistory.Where(h => bookIds.Contains(h.BookId)).ToList(); var processedDownloadId = booksHistory - .Where(c => c.EventType != HistoryEventType.Grabbed && c.DownloadId != null) + .Where(c => c.EventType != EntityHistoryEventType.Grabbed && c.DownloadId != null) .Select(c => c.DownloadId); - var stillDownloading = booksHistory.Where(c => c.EventType == HistoryEventType.Grabbed && !processedDownloadId.Contains(c.DownloadId)).ToList(); + var stillDownloading = booksHistory.Where(c => c.EventType == EntityHistoryEventType.Grabbed && !processedDownloadId.Contains(c.DownloadId)).ToList(); string downloadId = null; @@ -138,9 +137,9 @@ namespace NzbDrone.Core.History { foreach (var book in message.Book.Books) { - var history = new History + var history = new EntityHistory { - EventType = HistoryEventType.Grabbed, + EventType = EntityHistoryEventType.Grabbed, Date = DateTime.UtcNow, Quality = message.Book.ParsedBookInfo.Quality, SourceTitle = message.Book.Release.Title, @@ -157,6 +156,7 @@ namespace NzbDrone.Core.History history.Data.Add("AgeMinutes", message.Book.Release.AgeMinutes.ToString()); history.Data.Add("PublishedDate", message.Book.Release.PublishDate.ToString("s") + "Z"); history.Data.Add("DownloadClient", message.DownloadClient); + history.Data.Add("DownloadClientName", message.DownloadClientName); history.Data.Add("Size", message.Book.Release.Size.ToString()); history.Data.Add("DownloadUrl", message.Book.Release.DownloadUrl); history.Data.Add("Guid", message.Book.Release.Guid); @@ -188,9 +188,9 @@ namespace NzbDrone.Core.History foreach (var book in message.TrackedDownload.RemoteBook.Books) { - var history = new History + var history = new EntityHistory { - EventType = HistoryEventType.BookImportIncomplete, + EventType = EntityHistoryEventType.BookImportIncomplete, Date = DateTime.UtcNow, Quality = message.TrackedDownload.RemoteBook.ParsedBookInfo?.Quality ?? new QualityModel(), SourceTitle = message.TrackedDownload.DownloadItem.Title, @@ -218,9 +218,9 @@ namespace NzbDrone.Core.History downloadId = FindDownloadId(message); } - var history = new History + var history = new EntityHistory { - EventType = HistoryEventType.BookFileImported, + EventType = EntityHistoryEventType.BookFileImported, Date = DateTime.UtcNow, Quality = message.BookInfo.Quality, SourceTitle = message.ImportedBook.SceneName ?? Path.GetFileNameWithoutExtension(message.BookInfo.Path), @@ -233,7 +233,8 @@ namespace NzbDrone.Core.History //history.Data.Add("FileId", message.ImportedEpisode.Id.ToString()); history.Data.Add("DroppedPath", message.BookInfo.Path); history.Data.Add("ImportedPath", message.ImportedBook.Path); - history.Data.Add("DownloadClient", message.DownloadClient); + history.Data.Add("DownloadClient", message.DownloadClientInfo?.Type); + history.Data.Add("DownloadClientName", message.DownloadClientInfo?.Name); _historyRepository.Insert(history); } @@ -242,9 +243,9 @@ namespace NzbDrone.Core.History { foreach (var bookId in message.BookIds) { - var history = new History + var history = new EntityHistory { - EventType = HistoryEventType.DownloadFailed, + EventType = EntityHistoryEventType.DownloadFailed, Date = DateTime.UtcNow, Quality = message.Quality, SourceTitle = message.SourceTitle, @@ -254,31 +255,13 @@ namespace NzbDrone.Core.History }; history.Data.Add("DownloadClient", message.DownloadClient); + history.Data.Add("DownloadClientName", message.TrackedDownload?.DownloadItem.DownloadClientInfo.Name); history.Data.Add("Message", message.Message); _historyRepository.Insert(history); } } - public void Handle(DownloadCompletedEvent message) - { - foreach (var book in message.TrackedDownload.RemoteBook.Books) - { - var history = new History - { - EventType = HistoryEventType.DownloadImported, - Date = DateTime.UtcNow, - Quality = message.TrackedDownload.RemoteBook.ParsedBookInfo?.Quality ?? new QualityModel(), - SourceTitle = message.TrackedDownload.DownloadItem.Title, - AuthorId = book.AuthorId, - BookId = book.Id, - DownloadId = message.TrackedDownload.DownloadItem.DownloadId - }; - - _historyRepository.Insert(history); - } - } - public void Handle(BookFileDeletedEvent message) { if (message.Reason == DeleteMediaFileReason.NoLinkedEpisodes) @@ -292,9 +275,9 @@ namespace NzbDrone.Core.History return; } - var history = new History + var history = new EntityHistory { - EventType = HistoryEventType.BookFileDeleted, + EventType = EntityHistoryEventType.BookFileDeleted, Date = DateTime.UtcNow, Quality = message.BookFile.Quality, SourceTitle = message.BookFile.Path, @@ -312,9 +295,9 @@ namespace NzbDrone.Core.History var sourcePath = message.OriginalPath; var path = message.BookFile.Path; - var history = new History + var history = new EntityHistory { - EventType = HistoryEventType.BookFileRenamed, + EventType = EntityHistoryEventType.BookFileRenamed, Date = DateTime.UtcNow, Quality = message.BookFile.Quality, SourceTitle = message.OriginalPath, @@ -332,9 +315,9 @@ namespace NzbDrone.Core.History { var path = message.BookFile.Path; - var history = new History + var history = new EntityHistory { - EventType = HistoryEventType.BookFileRetagged, + EventType = EntityHistoryEventType.BookFileRetagged, Date = DateTime.UtcNow, Quality = message.BookFile.Quality, SourceTitle = path, @@ -360,12 +343,12 @@ namespace NzbDrone.Core.History public void Handle(DownloadIgnoredEvent message) { - var historyToAdd = new List(); + var historyToAdd = new List(); foreach (var bookId in message.BookIds) { - var history = new History + var history = new EntityHistory { - EventType = HistoryEventType.DownloadIgnored, + EventType = EntityHistoryEventType.DownloadIgnored, Date = DateTime.UtcNow, Quality = message.Quality, SourceTitle = message.SourceTitle, @@ -383,12 +366,12 @@ namespace NzbDrone.Core.History _historyRepository.InsertMany(historyToAdd); } - public List Since(DateTime date, HistoryEventType? eventType) + public List Since(DateTime date, EntityHistoryEventType? eventType) { return _historyRepository.Since(date, eventType); } - public void UpdateMany(IList items) + public void UpdateMany(IList items) { _historyRepository.UpdateMany(items); } diff --git a/src/NzbDrone.Core/MediaFiles/BookImport/Specifications/AlreadyImportedSpecification.cs b/src/NzbDrone.Core/MediaFiles/BookImport/Specifications/AlreadyImportedSpecification.cs index 2a505cdd4..71a59a1fe 100644 --- a/src/NzbDrone.Core/MediaFiles/BookImport/Specifications/AlreadyImportedSpecification.cs +++ b/src/NzbDrone.Core/MediaFiles/BookImport/Specifications/AlreadyImportedSpecification.cs @@ -39,8 +39,8 @@ namespace NzbDrone.Core.MediaFiles.BookImport.Specifications } var bookHistory = _historyService.GetByBook(bookRelease.BookId, null); - var lastImported = bookHistory.FirstOrDefault(h => h.EventType == HistoryEventType.DownloadImported); - var lastGrabbed = bookHistory.FirstOrDefault(h => h.EventType == HistoryEventType.Grabbed); + var lastImported = bookHistory.FirstOrDefault(h => h.EventType == EntityHistoryEventType.BookFileImported); + var lastGrabbed = bookHistory.FirstOrDefault(h => h.EventType == EntityHistoryEventType.Grabbed); if (lastImported == null) { diff --git a/src/NzbDrone.Core/MediaFiles/Events/BookImportedEvent.cs b/src/NzbDrone.Core/MediaFiles/Events/BookImportedEvent.cs index 200ee7f28..7b3463aff 100644 --- a/src/NzbDrone.Core/MediaFiles/Events/BookImportedEvent.cs +++ b/src/NzbDrone.Core/MediaFiles/Events/BookImportedEvent.cs @@ -12,7 +12,7 @@ namespace NzbDrone.Core.MediaFiles.Events public List ImportedBooks { get; private set; } public List OldFiles { get; private set; } public bool NewDownload { get; private set; } - public string DownloadClient { get; private set; } + public DownloadClientItemClientInfo DownloadClientInfo { get; set; } public string DownloadId { get; private set; } public BookImportedEvent(Author author, Book book, List importedBooks, List oldFiles, bool newDownload, DownloadClientItem downloadClientItem) @@ -25,7 +25,7 @@ namespace NzbDrone.Core.MediaFiles.Events if (downloadClientItem != null) { - DownloadClient = downloadClientItem.DownloadClientInfo.Name; + DownloadClientInfo = downloadClientItem.DownloadClientInfo; DownloadId = downloadClientItem.DownloadId; } } diff --git a/src/NzbDrone.Core/MediaFiles/Events/TrackImportFailedEvent.cs b/src/NzbDrone.Core/MediaFiles/Events/TrackImportFailedEvent.cs index 915aa900e..7b3b20f4c 100644 --- a/src/NzbDrone.Core/MediaFiles/Events/TrackImportFailedEvent.cs +++ b/src/NzbDrone.Core/MediaFiles/Events/TrackImportFailedEvent.cs @@ -10,7 +10,7 @@ namespace NzbDrone.Core.MediaFiles.Events public Exception Exception { get; set; } public LocalBook BookInfo { get; } public bool NewDownload { get; } - public string DownloadClient { get; } + public DownloadClientItemClientInfo DownloadClientInfo { get; } public string DownloadId { get; } public TrackImportFailedEvent(Exception exception, LocalBook bookInfo, bool newDownload, DownloadClientItem downloadClientItem) @@ -21,7 +21,7 @@ namespace NzbDrone.Core.MediaFiles.Events if (downloadClientItem != null) { - DownloadClient = downloadClientItem.DownloadClientInfo.Name; + DownloadClientInfo = downloadClientItem.DownloadClientInfo; DownloadId = downloadClientItem.DownloadId; } } diff --git a/src/NzbDrone.Core/MediaFiles/Events/TrackImportedEvent.cs b/src/NzbDrone.Core/MediaFiles/Events/TrackImportedEvent.cs index f3801eaaa..ec4aefe77 100644 --- a/src/NzbDrone.Core/MediaFiles/Events/TrackImportedEvent.cs +++ b/src/NzbDrone.Core/MediaFiles/Events/TrackImportedEvent.cs @@ -11,7 +11,7 @@ namespace NzbDrone.Core.MediaFiles.Events public BookFile ImportedBook { get; private set; } public List OldFiles { get; private set; } public bool NewDownload { get; private set; } - public string DownloadClient { get; private set; } + public DownloadClientItemClientInfo DownloadClientInfo { get; set; } public string DownloadId { get; private set; } public TrackImportedEvent(LocalBook bookInfo, BookFile importedBook, List oldFiles, bool newDownload, DownloadClientItem downloadClientItem) @@ -23,7 +23,7 @@ namespace NzbDrone.Core.MediaFiles.Events if (downloadClientItem != null) { - DownloadClient = downloadClientItem.DownloadClientInfo.Name; + DownloadClientInfo = downloadClientItem.DownloadClientInfo; DownloadId = downloadClientItem.DownloadId; } } diff --git a/src/NzbDrone.Core/Notifications/NotificationService.cs b/src/NzbDrone.Core/Notifications/NotificationService.cs index b01032a81..df25ebd7a 100644 --- a/src/NzbDrone.Core/Notifications/NotificationService.cs +++ b/src/NzbDrone.Core/Notifications/NotificationService.cs @@ -152,7 +152,7 @@ namespace NzbDrone.Core.Notifications Message = GetBookDownloadMessage(message.Author, message.Book, message.ImportedBooks), Author = message.Author, Book = message.Book, - DownloadClient = message.DownloadClient, + DownloadClient = message.DownloadClientInfo?.Name, DownloadId = message.DownloadId, BookFiles = message.ImportedBooks, OldFiles = message.OldFiles, diff --git a/src/NzbDrone.Core/Queue/QueueService.cs b/src/NzbDrone.Core/Queue/QueueService.cs index adbb245e1..2ee9b20ad 100644 --- a/src/NzbDrone.Core/Queue/QueueService.cs +++ b/src/NzbDrone.Core/Queue/QueueService.cs @@ -63,7 +63,7 @@ namespace NzbDrone.Core.Queue private Queue MapQueueItem(TrackedDownload trackedDownload, Book book) { bool downloadForced = false; - var history = _historyService.Find(trackedDownload.DownloadItem.DownloadId, HistoryEventType.Grabbed).FirstOrDefault(); + var history = _historyService.Find(trackedDownload.DownloadItem.DownloadId, EntityHistoryEventType.Grabbed).FirstOrDefault(); if (history != null && history.Data.ContainsKey("downloadForced")) { downloadForced = bool.Parse(history.Data["downloadForced"]); diff --git a/src/Readarr.Api.V1/History/HistoryController.cs b/src/Readarr.Api.V1/History/HistoryController.cs index a183ee875..77b04cd1e 100644 --- a/src/Readarr.Api.V1/History/HistoryController.cs +++ b/src/Readarr.Api.V1/History/HistoryController.cs @@ -29,7 +29,7 @@ namespace Readarr.Api.V1.History _failedDownloadService = failedDownloadService; } - protected HistoryResource MapToResource(NzbDrone.Core.History.History model, bool includeAuthor, bool includeBook) + protected HistoryResource MapToResource(EntityHistory model, bool includeAuthor, bool includeBook) { var resource = model.ToResource(); @@ -55,7 +55,7 @@ namespace Readarr.Api.V1.History public PagingResource GetHistory(bool includeAuthor = false, bool includeBook = false) { var pagingResource = Request.ReadPagingResourceFromRequest(); - var pagingSpec = pagingResource.MapToPagingSpec("date", SortDirection.Descending); + var pagingSpec = pagingResource.MapToPagingSpec("date", SortDirection.Descending); var eventTypeFilter = pagingResource.Filters.FirstOrDefault(f => f.Key == "eventType"); var bookIdFilter = pagingResource.Filters.FirstOrDefault(f => f.Key == "bookId"); @@ -63,7 +63,7 @@ namespace Readarr.Api.V1.History if (eventTypeFilter != null) { - var filterValue = (HistoryEventType)Convert.ToInt32(eventTypeFilter.Value); + var filterValue = (EntityHistoryEventType)Convert.ToInt32(eventTypeFilter.Value); pagingSpec.FilterExpressions.Add(v => v.EventType == filterValue); } @@ -83,13 +83,13 @@ namespace Readarr.Api.V1.History } [HttpGet("since")] - public List GetHistorySince(DateTime date, HistoryEventType? eventType = null, bool includeAuthor = false, bool includeBook = false) + public List GetHistorySince(DateTime date, EntityHistoryEventType? eventType = null, bool includeAuthor = false, bool includeBook = false) { return _historyService.Since(date, eventType).Select(h => MapToResource(h, includeAuthor, includeBook)).ToList(); } [HttpGet("author")] - public List GetAuthorHistory(int authorId, int? bookId = null, HistoryEventType? eventType = null, bool includeAuthor = false, bool includeBook = false) + public List GetAuthorHistory(int authorId, int? bookId = null, EntityHistoryEventType? eventType = null, bool includeAuthor = false, bool includeBook = false) { if (bookId.HasValue) { diff --git a/src/Readarr.Api.V1/History/HistoryResource.cs b/src/Readarr.Api.V1/History/HistoryResource.cs index 61f78d878..057f001b7 100644 --- a/src/Readarr.Api.V1/History/HistoryResource.cs +++ b/src/Readarr.Api.V1/History/HistoryResource.cs @@ -18,7 +18,7 @@ namespace Readarr.Api.V1.History public DateTime Date { get; set; } public string DownloadId { get; set; } - public HistoryEventType EventType { get; set; } + public EntityHistoryEventType EventType { get; set; } public Dictionary Data { get; set; } @@ -28,7 +28,7 @@ namespace Readarr.Api.V1.History public static class HistoryResourceMapper { - public static HistoryResource ToResource(this NzbDrone.Core.History.History model) + public static HistoryResource ToResource(this EntityHistory model) { if (model == null) {