Added db migration to deal with the settings changes.

pull/4/head
Taloth Saldono 10 years ago
parent 67dcfad5dc
commit ab154d924e

@ -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
};
}

@ -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<String>("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<String>("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();
}
}
}
}
}
}
}

@ -15,7 +15,7 @@ using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Download.Clients.Pneumatic
{
public class Pneumatic : DownloadClientBase<FolderSettings>, IExecute<TestPneumaticCommand>
public class Pneumatic : DownloadClientBase<PneumaticSettings>, IExecute<TestPneumaticCommand>
{
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)

@ -8,21 +8,21 @@ using NzbDrone.Core.Validation.Paths;
namespace NzbDrone.Core.Download.Clients.Pneumatic
{
public class FolderSettingsValidator : AbstractValidator<FolderSettings>
public class PneumaticSettingsValidator : AbstractValidator<PneumaticSettings>
{
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()
{

@ -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);
}
}
}

@ -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();
}
}

@ -197,6 +197,7 @@
<Compile Include="Datastore\Migration\048_add_title_to_scenemappings.cs" />
<Compile Include="Datastore\Migration\049_fix_dognzb_url.cs" />
<Compile Include="Datastore\Migration\050_add_hash_to_metadata_files.cs" />
<Compile Include="Datastore\Migration\051_rename_download_client_settings.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" />

Loading…
Cancel
Save