(cherry picked from commit 2dba5ef4b431bee0a061be67354c9a7a612a03c8)pull/2682/head
parent
e5a1b7a72e
commit
8bb52105fd
@ -0,0 +1,130 @@
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
using NzbDrone.Core.Download.Clients.RTorrent;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
[TestFixture]
|
||||
public class cdh_per_downloadclientFixture : MigrationTest<cdh_per_downloadclient>
|
||||
{
|
||||
[Test]
|
||||
public void should_set_cdh_to_enabled()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("DownloadClients").Row(new
|
||||
{
|
||||
Enable = true,
|
||||
Name = "Deluge",
|
||||
Implementation = "Deluge",
|
||||
Priority = 1,
|
||||
Settings = new DelugeSettings34
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
TvCategory = "abc",
|
||||
UrlBase = "/my/"
|
||||
}.ToJson(),
|
||||
ConfigContract = "DelugeSettings"
|
||||
});
|
||||
});
|
||||
|
||||
var items = db.Query<DownloadClientDefinition34>("SELECT * FROM \"DownloadClients\"");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First().RemoveCompletedDownloads.Should().BeFalse();
|
||||
items.First().RemoveFailedDownloads.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_set_cdh_to_disabled_when_globally_disabled()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Config").Row(new
|
||||
{
|
||||
Key = "removecompleteddownloads",
|
||||
Value = "True"
|
||||
});
|
||||
|
||||
c.Insert.IntoTable("DownloadClients").Row(new
|
||||
{
|
||||
Enable = true,
|
||||
Name = "Deluge",
|
||||
Implementation = "Deluge",
|
||||
Priority = 1,
|
||||
Settings = new DelugeSettings34
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
TvCategory = "abc",
|
||||
UrlBase = "/my/"
|
||||
}.ToJson(),
|
||||
ConfigContract = "DelugeSettings"
|
||||
});
|
||||
});
|
||||
|
||||
var items = db.Query<DownloadClientDefinition34>("SELECT * FROM \"DownloadClients\"");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First().RemoveCompletedDownloads.Should().BeTrue();
|
||||
items.First().RemoveFailedDownloads.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_disable_remove_for_existing_rtorrent()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("DownloadClients").Row(new
|
||||
{
|
||||
Enable = true,
|
||||
Name = "RTorrent",
|
||||
Implementation = "RTorrent",
|
||||
Priority = 1,
|
||||
Settings = new RTorrentSettings
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
MusicCategory = "abc",
|
||||
UrlBase = "/my/"
|
||||
}.ToJson(),
|
||||
ConfigContract = "RTorrentSettings"
|
||||
});
|
||||
});
|
||||
|
||||
var items = db.Query<DownloadClientDefinition34>("SELECT * FROM \"DownloadClients\"");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First().RemoveCompletedDownloads.Should().BeFalse();
|
||||
items.First().RemoveFailedDownloads.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
|
||||
public class DelugeSettings34
|
||||
{
|
||||
public string Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string UrlBase { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string TvCategory { get; set; }
|
||||
public int RecentTvPriority { get; set; }
|
||||
public int OlderTvPriority { get; set; }
|
||||
public bool UseSsl { get; set; }
|
||||
}
|
||||
|
||||
public class DownloadClientDefinition34
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public bool Enable { get; set; }
|
||||
public int Priority { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Implementation { get; set; }
|
||||
public JObject Settings { get; set; }
|
||||
public string ConfigContract { get; set; }
|
||||
public bool RemoveCompletedDownloads { get; set; }
|
||||
public bool RemoveFailedDownloads { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(158)]
|
||||
public class cdh_per_downloadclient : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Alter.Table("DownloadClients")
|
||||
.AddColumn("RemoveCompletedDownloads").AsBoolean().NotNullable().WithDefaultValue(true)
|
||||
.AddColumn("RemoveFailedDownloads").AsBoolean().NotNullable().WithDefaultValue(true);
|
||||
|
||||
Execute.WithConnection(MoveRemoveSettings);
|
||||
}
|
||||
|
||||
private void MoveRemoveSettings(IDbConnection conn, IDbTransaction tran)
|
||||
{
|
||||
var removeCompletedDownloads = false;
|
||||
var removeFailedDownloads = true;
|
||||
|
||||
using (var removeCompletedDownloadsCmd = conn.CreateCommand(tran, "SELECT \"Value\" FROM \"Config\" WHERE \"Key\" = 'removecompleteddownloads'"))
|
||||
{
|
||||
if ((removeCompletedDownloadsCmd.ExecuteScalar() as string)?.ToLower() == "true")
|
||||
{
|
||||
removeCompletedDownloads = true;
|
||||
}
|
||||
}
|
||||
|
||||
using (var removeFailedDownloadsCmd = conn.CreateCommand(tran, "SELECT \"Value\" FROM \"Config\" WHERE \"Key\" = 'removefaileddownloads'"))
|
||||
{
|
||||
if ((removeFailedDownloadsCmd.ExecuteScalar() as string)?.ToLower() == "false")
|
||||
{
|
||||
removeFailedDownloads = false;
|
||||
}
|
||||
}
|
||||
|
||||
var parameters = new { RemoveFailedDownloads = removeFailedDownloads, RemoveCompletedDownloads = removeCompletedDownloads };
|
||||
var updateSql = $"UPDATE \"DownloadClients\" SET \"RemoveCompletedDownloads\" = (CASE WHEN \"Implementation\" IN ('RTorrent', 'Flood') THEN 'false' ELSE @RemoveCompletedDownloads END), \"RemoveFailedDownloads\" = @RemoveFailedDownloads";
|
||||
conn.Execute(updateSql, parameters, transaction: tran);
|
||||
|
||||
conn.Execute("DELETE FROM \"Config\" WHERE \"Key\" IN ('removecompleteddownloads', 'removefaileddownloads')");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue