diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs index bae8867fe..a0e33f1bd 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/PneumaticProviderFixture.cs @@ -45,9 +45,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests _remoteEpisode.ParsedEpisodeInfo.FullSeason = false; Subject.Definition = new DownloadClientDefinition(); - Subject.Definition.Settings = new FolderSettings + Subject.Definition.Settings = new PneumaticSettings { - Folder = _pneumaticFolder + NzbFolder = _pneumaticFolder }; } diff --git a/src/NzbDrone.Core/Datastore/Migration/051_rename_download_client_settings.cs b/src/NzbDrone.Core/Datastore/Migration/051_rename_download_client_settings.cs new file mode 100644 index 000000000..ccc3f3527 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/051_rename_download_client_settings.cs @@ -0,0 +1,88 @@ +using NzbDrone.Core.Datastore.Migration.Framework; +using FluentMigrator; +using System.Data; +using NzbDrone.Common.Serializer; +using NzbDrone.Core.Download.Clients.UsenetBlackhole; +using Newtonsoft.Json; +using System; +using NzbDrone.Core.Download.Clients.Pneumatic; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(51)] + public class rename_download_client_settings : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Execute.WithConnection(ConvertFolderSettings); + } + + private void ConvertFolderSettings(IDbConnection conn, IDbTransaction tran) + { + using (IDbCommand downloadClientsCmd = conn.CreateCommand()) + { + downloadClientsCmd.Transaction = tran; + downloadClientsCmd.CommandText = @"SELECT Value FROM Config WHERE Key = 'downloadedepisodesfolder'"; + var downloadedEpisodesFolder = downloadClientsCmd.ExecuteScalar() as String; + + downloadClientsCmd.Transaction = tran; + downloadClientsCmd.CommandText = @"SELECT Id, Implementation, Settings, ConfigContract FROM DownloadClients WHERE ConfigContract = 'FolderSettings'"; + using (IDataReader downloadClientReader = downloadClientsCmd.ExecuteReader()) + { + while (downloadClientReader.Read()) + { + var id = downloadClientReader.GetInt32(0); + var implementation = downloadClientReader.GetString(1); + var settings = downloadClientReader.GetString(2); + var configContract = downloadClientReader.GetString(3); + + var settingsJson = JsonConvert.DeserializeObject(settings) as Newtonsoft.Json.Linq.JObject; + + if (implementation == "Blackhole") + { + var newSettings = new + { + NzbFolder = settingsJson.Value("folder"), + WatchFolder = downloadedEpisodesFolder + }.ToJson(); + + using (IDbCommand updateCmd = conn.CreateCommand()) + { + updateCmd.Transaction = tran; + updateCmd.CommandText = "UPDATE DownloadClients SET Implementation = ?, Settings = ?, ConfigContract = ? WHERE Id = ?"; + updateCmd.AddParameter("UsenetBlackhole"); + updateCmd.AddParameter(newSettings); + updateCmd.AddParameter("UsenetBlackholeSettings"); + updateCmd.AddParameter(id); + + updateCmd.ExecuteNonQuery(); + } + } + else if (implementation == "Pneumatic") + { + var newSettings = new + { + NzbFolder = settingsJson.Value("folder") + }.ToJson(); + + using (IDbCommand updateCmd = conn.CreateCommand()) + { + updateCmd.Transaction = tran; + updateCmd.CommandText = "UPDATE DownloadClients SET Settings = ?, ConfigContract = ? WHERE Id = ?"; + updateCmd.AddParameter(newSettings); + updateCmd.AddParameter("PneumaticSettings"); + updateCmd.AddParameter(id); + + updateCmd.ExecuteNonQuery(); + } + } + else + { + throw new NotSupportedException(); + } + } + } + } +} + } +} diff --git a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs index c62a6bca0..7e3bb56de 100644 --- a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs +++ b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs @@ -15,7 +15,7 @@ using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Download.Clients.Pneumatic { - public class Pneumatic : DownloadClientBase, IExecute + public class Pneumatic : DownloadClientBase, IExecute { private readonly IConfigService _configService; private readonly IHttpProvider _httpProvider; @@ -56,7 +56,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic title = FileNameBuilder.CleanFilename(title); //Save to the Pneumatic directory (The user will need to ensure its accessible by XBMC) - var filename = Path.Combine(Settings.Folder, title + ".nzb"); + var filename = Path.Combine(Settings.NzbFolder, title + ".nzb"); logger.Debug("Downloading NZB from: {0} to: {1}", url, filename); _httpProvider.DownloadFile(url, filename); @@ -73,7 +73,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic { get { - return !string.IsNullOrWhiteSpace(Settings.Folder); + return !string.IsNullOrWhiteSpace(Settings.NzbFolder); } } @@ -94,7 +94,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic public override void Test() { - PerformTest(Settings.Folder); + PerformTest(Settings.NzbFolder); } private void PerformTest(string folder) diff --git a/src/NzbDrone.Core/Download/Clients/Pneumatic/PneumaticSettings.cs b/src/NzbDrone.Core/Download/Clients/Pneumatic/PneumaticSettings.cs index 00ebb3b93..29b414c26 100644 --- a/src/NzbDrone.Core/Download/Clients/Pneumatic/PneumaticSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/Pneumatic/PneumaticSettings.cs @@ -8,21 +8,21 @@ using NzbDrone.Core.Validation.Paths; namespace NzbDrone.Core.Download.Clients.Pneumatic { - public class FolderSettingsValidator : AbstractValidator + public class PneumaticSettingsValidator : AbstractValidator { - public FolderSettingsValidator() + public PneumaticSettingsValidator() { //Todo: Validate that the path actually exists - RuleFor(c => c.Folder).IsValidPath(); + RuleFor(c => c.NzbFolder).IsValidPath(); } } - public class FolderSettings : IProviderConfig + public class PneumaticSettings : IProviderConfig { - private static readonly FolderSettingsValidator Validator = new FolderSettingsValidator(); + private static readonly PneumaticSettingsValidator Validator = new PneumaticSettingsValidator(); - [FieldDefinition(0, Label = "Folder", Type = FieldType.Path)] - public String Folder { get; set; } + [FieldDefinition(0, Label = "Nzb Folder", Type = FieldType.Path)] + public String NzbFolder { get; set; } public ValidationResult Validate() { diff --git a/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackhole.cs b/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackhole.cs index ec1865c2f..260d99198 100644 --- a/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackhole.cs +++ b/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackhole.cs @@ -149,8 +149,8 @@ namespace NzbDrone.Core.Download.Clients.UsenetBlackhole public void Execute(TestUsenetBlackholeCommand message) { - PerformTest(Settings.NzbFolder); - PerformTest(Settings.WatchFolder); + PerformTest(message.NzbFolder); + PerformTest(message.WatchFolder); } } } diff --git a/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackholeSettings.cs b/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackholeSettings.cs index ae518f1ec..dd5371af8 100644 --- a/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackholeSettings.cs +++ b/src/NzbDrone.Core/Download/Clients/UsenetBlackhole/UsenetBlackholeSettings.cs @@ -14,6 +14,7 @@ namespace NzbDrone.Core.Download.Clients.UsenetBlackhole { //Todo: Validate that the path actually exists RuleFor(c => c.NzbFolder).IsValidPath(); + RuleFor(c => c.WatchFolder).IsValidPath(); } } diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index b46015936..4549f34a1 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -197,6 +197,7 @@ +