mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07:00
Tweaked default config for extra files import.
This commit is contained in:
parent
56ecbf4a31
commit
ec7f749541
8 changed files with 279 additions and 18 deletions
|
@ -0,0 +1,54 @@
|
||||||
|
using System.Linq;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.Datastore.Migration;
|
||||||
|
using NzbDrone.Core.Parser;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class import_extra_files_configFixture : MigrationTest<import_extra_files>
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void should_not_insert_if_missing()
|
||||||
|
{
|
||||||
|
var db = WithMigrationTestDb();
|
||||||
|
|
||||||
|
var items = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||||
|
items.Should().BeNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_insert_if_empty()
|
||||||
|
{
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("Config").Row(new
|
||||||
|
{
|
||||||
|
Key = "extrafileextensions",
|
||||||
|
Value = ""
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var items = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||||
|
items.Should().BeNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_insert_True_if_configured()
|
||||||
|
{
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("Config").Row(new
|
||||||
|
{
|
||||||
|
Key = "extrafileextensions",
|
||||||
|
Value = "srt"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var items = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||||
|
items.Should().Be("True");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,133 @@
|
||||||
|
using System.Linq;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.Datastore.Migration;
|
||||||
|
using NzbDrone.Core.Parser;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class fix_extra_files_configFixture : MigrationTest<fix_extra_files_config>
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void should_not_update_importextrafiles_disabled()
|
||||||
|
{
|
||||||
|
var db = WithMigrationTestDb();
|
||||||
|
|
||||||
|
var itemEnabled = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||||
|
itemEnabled.Should().BeNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_fix_importextrafiles_if_wrong()
|
||||||
|
{
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("Config").Row(new
|
||||||
|
{
|
||||||
|
Key = "importextrafiles",
|
||||||
|
Value = 1
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var itemEnabled = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||||
|
itemEnabled.Should().Be("True");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_fill_in_default_extensions()
|
||||||
|
{
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("Config").Row(new
|
||||||
|
{
|
||||||
|
Key = "importextrafiles",
|
||||||
|
Value = "False"
|
||||||
|
});
|
||||||
|
|
||||||
|
c.Insert.IntoTable("Config").Row(new
|
||||||
|
{
|
||||||
|
Key = "extrafileextensions",
|
||||||
|
Value = ""
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var itemEnabled = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||||
|
itemEnabled.Should().Be("False");
|
||||||
|
|
||||||
|
var itemExtensions = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'extrafileextensions'");
|
||||||
|
itemExtensions.Should().Be("srt");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_fill_in_default_extensions()
|
||||||
|
{
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("Config").Row(new
|
||||||
|
{
|
||||||
|
Key = "importextrafiles",
|
||||||
|
Value = "True"
|
||||||
|
});
|
||||||
|
|
||||||
|
c.Insert.IntoTable("Config").Row(new
|
||||||
|
{
|
||||||
|
Key = "extrafileextensions",
|
||||||
|
Value = ""
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var itemEnabled = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||||
|
itemEnabled.Should().Be("True");
|
||||||
|
|
||||||
|
var itemExtensions = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'extrafileextensions'");
|
||||||
|
itemExtensions.Should().Be("");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_fill_in_default_extensions_if_not_defined()
|
||||||
|
{
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("Config").Row(new
|
||||||
|
{
|
||||||
|
Key = "importextrafiles",
|
||||||
|
Value = "False"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var itemEnabled = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||||
|
itemEnabled.Should().Be("False");
|
||||||
|
|
||||||
|
var itemExtensions = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'extrafileextensions'");
|
||||||
|
itemExtensions.Should().BeNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_fill_in_default_extensions_if_already_defined()
|
||||||
|
{
|
||||||
|
var db = WithMigrationTestDb(c =>
|
||||||
|
{
|
||||||
|
c.Insert.IntoTable("Config").Row(new
|
||||||
|
{
|
||||||
|
Key = "importextrafiles",
|
||||||
|
Value = "False"
|
||||||
|
});
|
||||||
|
|
||||||
|
c.Insert.IntoTable("Config").Row(new
|
||||||
|
{
|
||||||
|
Key = "extrafileextensions",
|
||||||
|
Value = "sub"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var itemEnabled = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||||
|
itemEnabled.Should().Be("False");
|
||||||
|
|
||||||
|
var itemExtensions = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'extrafileextensions'");
|
||||||
|
itemExtensions.Should().Be("sub");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
{
|
{
|
||||||
List<Dictionary<string, object>> Query(string sql);
|
List<Dictionary<string, object>> Query(string sql);
|
||||||
List<T> Query<T>(string sql) where T : new();
|
List<T> Query<T>(string sql) where T : new();
|
||||||
|
T QueryScalar<T>(string sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DirectDataMapper : IDirectDataMapper
|
public class DirectDataMapper : IDirectDataMapper
|
||||||
|
@ -62,6 +63,13 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
return dataTable.Rows.Cast<DataRow>().Select(MapToObject<T>).ToList();
|
return dataTable.Rows.Cast<DataRow>().Select(MapToObject<T>).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T QueryScalar<T>(string sql)
|
||||||
|
{
|
||||||
|
var dataTable = GetDataTable(sql);
|
||||||
|
|
||||||
|
return dataTable.Rows.Cast<DataRow>().Select(d => MapValue(d, 0, typeof(T))).Cast<T>().FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
protected Dictionary<string, object> MapToDictionary(DataRow dataRow)
|
protected Dictionary<string, object> MapToDictionary(DataRow dataRow)
|
||||||
{
|
{
|
||||||
var item = new Dictionary<string, object>();
|
var item = new Dictionary<string, object>();
|
||||||
|
@ -107,24 +115,29 @@ namespace NzbDrone.Core.Test.Framework
|
||||||
propertyType = propertyType.GetGenericArguments()[0];
|
propertyType = propertyType.GetGenericArguments()[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
object value;
|
object value = MapValue(dataRow, i, propertyType);
|
||||||
if (dataRow.ItemArray[i] == DBNull.Value)
|
|
||||||
{
|
|
||||||
value = null;
|
|
||||||
}
|
|
||||||
else if (dataRow.Table.Columns[i].DataType == typeof(string) && propertyType != typeof(string))
|
|
||||||
{
|
|
||||||
value = Json.Deserialize((string)dataRow.ItemArray[i], propertyType);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
value = Convert.ChangeType(dataRow.ItemArray[i], propertyType);
|
|
||||||
}
|
|
||||||
|
|
||||||
propertyInfo.SetValue(item, value, null);
|
propertyInfo.SetValue(item, value, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private object MapValue(DataRow dataRow, int i, Type targetType)
|
||||||
|
{
|
||||||
|
if (dataRow.ItemArray[i] == DBNull.Value)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else if (dataRow.Table.Columns[i].DataType == typeof(string) && targetType != typeof(string))
|
||||||
|
{
|
||||||
|
return Json.Deserialize((string)dataRow.ItemArray[i], targetType);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Convert.ChangeType(dataRow.ItemArray[i], targetType);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,8 @@
|
||||||
<Compile Include="Datastore\MappingExtentionFixture.cs" />
|
<Compile Include="Datastore\MappingExtentionFixture.cs" />
|
||||||
<Compile Include="Datastore\MarrDataLazyLoadingFixture.cs" />
|
<Compile Include="Datastore\MarrDataLazyLoadingFixture.cs" />
|
||||||
<Compile Include="Datastore\Migration\108_fix_metadata_file_extensionsFixture.cs" />
|
<Compile Include="Datastore\Migration\108_fix_metadata_file_extensionsFixture.cs" />
|
||||||
|
<Compile Include="Datastore\Migration\109_import_extra_files_configFixture.cs" />
|
||||||
|
<Compile Include="Datastore\Migration\110_fix_extra_files_configFixture.cs" />
|
||||||
<Compile Include="Datastore\Migration\106_update_btn_urlFixture.cs" />
|
<Compile Include="Datastore\Migration\106_update_btn_urlFixture.cs" />
|
||||||
<Compile Include="Datastore\Migration\103_fix_metadata_file_extensionsFixture.cs" />
|
<Compile Include="Datastore\Migration\103_fix_metadata_file_extensionsFixture.cs" />
|
||||||
<Compile Include="Datastore\Migration\099_extra_and_subtitle_filesFixture.cs" />
|
<Compile Include="Datastore\Migration\099_extra_and_subtitle_filesFixture.cs" />
|
||||||
|
|
|
@ -212,7 +212,7 @@ namespace NzbDrone.Core.Configuration
|
||||||
|
|
||||||
public string ExtraFileExtensions
|
public string ExtraFileExtensions
|
||||||
{
|
{
|
||||||
get { return GetValue("ExtraFileExtensions", ""); }
|
get { return GetValue("ExtraFileExtensions", "srt"); }
|
||||||
|
|
||||||
set { SetValue("ExtraFileExtensions", value); }
|
set { SetValue("ExtraFileExtensions", value); }
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
using System.Data;
|
||||||
|
using FluentMigrator;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Datastore.Migration
|
||||||
|
{
|
||||||
|
[Migration(110)]
|
||||||
|
public class fix_extra_files_config : NzbDroneMigrationBase
|
||||||
|
{
|
||||||
|
protected override void MainDbUpgrade()
|
||||||
|
{
|
||||||
|
Execute.WithConnection(FixExtraFilesConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FixExtraFilesConfig(IDbConnection conn, IDbTransaction tran)
|
||||||
|
{
|
||||||
|
string extraFileExtensions;
|
||||||
|
string importExtraFiles;
|
||||||
|
|
||||||
|
using (var cmd = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
cmd.Transaction = tran;
|
||||||
|
cmd.CommandText = "SELECT Value FROM Config WHERE Key = 'extrafileextensions'";
|
||||||
|
|
||||||
|
extraFileExtensions = (string)cmd.ExecuteScalar();
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var cmd = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
cmd.Transaction = tran;
|
||||||
|
cmd.CommandText = "SELECT Value FROM Config WHERE Key = 'importextrafiles'";
|
||||||
|
|
||||||
|
importExtraFiles = (string)cmd.ExecuteScalar();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (importExtraFiles == "1" || importExtraFiles == "True")
|
||||||
|
{
|
||||||
|
using (var insertCmd = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
insertCmd.Transaction = tran;
|
||||||
|
insertCmd.CommandText = "UPDATE Config SET Value = 'True' WHERE Key = 'importextrafiles'";
|
||||||
|
insertCmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (extraFileExtensions.IsNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
using (var insertCmd = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
insertCmd.Transaction = tran;
|
||||||
|
insertCmd.CommandText = "UPDATE Config SET Value = 'srt' WHERE Key = 'extrafileextensions'";
|
||||||
|
insertCmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -248,6 +248,7 @@
|
||||||
<Compile Include="Datastore\Migration\068_add_release_restrictions.cs" />
|
<Compile Include="Datastore\Migration\068_add_release_restrictions.cs" />
|
||||||
<Compile Include="Datastore\Migration\069_quality_proper.cs" />
|
<Compile Include="Datastore\Migration\069_quality_proper.cs" />
|
||||||
<Compile Include="Datastore\Migration\070_delay_profile.cs" />
|
<Compile Include="Datastore\Migration\070_delay_profile.cs" />
|
||||||
|
<Compile Include="Datastore\Migration\110_fix_extra_files_config.cs" />
|
||||||
<Compile Include="Datastore\Migration\109_import_extra_files.cs" />
|
<Compile Include="Datastore\Migration\109_import_extra_files.cs" />
|
||||||
<Compile Include="Datastore\Migration\108_fix_extra_file_extension.cs" />
|
<Compile Include="Datastore\Migration\108_fix_extra_file_extension.cs" />
|
||||||
<Compile Include="Datastore\Migration\107_remove_wombles.cs" />
|
<Compile Include="Datastore\Migration\107_remove_wombles.cs" />
|
||||||
|
|
|
@ -25,11 +25,11 @@
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<fieldset class="advanced-setting">
|
<fieldset>
|
||||||
<legend>Importing</legend>
|
<legend>Importing</legend>
|
||||||
|
|
||||||
{{#if_mono}}
|
{{#if_mono}}
|
||||||
<div class="form-group">
|
<div class="form-group advanced-setting">
|
||||||
<label class="col-sm-3 control-label">Skip Free Space Check</label>
|
<label class="col-sm-3 control-label">Skip Free Space Check</label>
|
||||||
|
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{/if_mono}}
|
{{/if_mono}}
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group advanced-setting">
|
||||||
<label class="col-sm-3 control-label">Use Hardlinks instead of Copy</label>
|
<label class="col-sm-3 control-label">Use Hardlinks instead of Copy</label>
|
||||||
|
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
|
@ -111,4 +111,5 @@
|
||||||
<input type="text" name="extraFileExtensions" class="form-control"/>
|
<input type="text" name="extraFileExtensions" class="form-control"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue