New: Gracefully handle broken release profiles when ppl swapped to older sonarr versions and back again
This commit is contained in:
parent
ec866082d4
commit
e3be3ef91e
|
@ -9,7 +9,7 @@ namespace NzbDrone.Core.Datastore.Converters
|
|||
{
|
||||
public class EmbeddedDocumentConverter : IConverter
|
||||
{
|
||||
private readonly JsonSerializerSettings SerializerSetting;
|
||||
protected readonly JsonSerializerSettings SerializerSetting;
|
||||
|
||||
public EmbeddedDocumentConverter(params JsonConverter[] converters)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
using Marr.Data.Converters;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Converters
|
||||
{
|
||||
public class StringListConverter : EmbeddedDocumentConverter
|
||||
{
|
||||
public override object FromDB(ConverterContext context)
|
||||
{
|
||||
if (context.DbValue == DBNull.Value)
|
||||
{
|
||||
return DBNull.Value;
|
||||
}
|
||||
|
||||
var stringValue = (string)context.DbValue;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(stringValue))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Handle when the database contains a comma separated string. Specifically for ReleaseProfiles when ppl downgraded Sonarr versions and added profiles.
|
||||
if (!stringValue.StartsWith("[") || !stringValue.EndsWith("]"))
|
||||
{
|
||||
return stringValue.Split(',').ToList();
|
||||
}
|
||||
|
||||
return JsonConvert.DeserializeObject(stringValue, context.ColumnMap.FieldType, SerializerSetting);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -171,7 +171,7 @@ namespace NzbDrone.Core.Datastore
|
|||
MapRepository.Instance.RegisterTypeConverter(typeof(List<int>), new EmbeddedDocumentConverter());
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(List<KeyValuePair<string, int>>), new EmbeddedDocumentConverter());
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(Language), new LanguageIntConverter());
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(List<string>), new EmbeddedDocumentConverter());
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(List<string>), new StringListConverter());
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(List<LanguageProfileItem>), new EmbeddedDocumentConverter(new LanguageIntConverter()));
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(ParsedEpisodeInfo), new EmbeddedDocumentConverter());
|
||||
MapRepository.Instance.RegisterTypeConverter(typeof(ReleaseInfo), new EmbeddedDocumentConverter());
|
||||
|
|
Loading…
Reference in New Issue