@ -13,18 +13,11 @@ namespace NzbDrone.Core.Datastore.Migration
[Migration(166)]
public class fix_tmdb_list_config : NzbDroneMigrationBase
{
protected override void MainDbUpgrade ( )
{
Execute . WithConnection ( FixConfig ) ;
}
private readonly JsonSerializerOptions _serializerSettings ;
p rivate void FixConfig ( IDbConnection conn , IDbTransaction tran )
public fix_tmdb_list_config ( )
{
var rows = conn . Query < ProviderDefinition166 > ( $"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TMDbImport'" ) ;
var corrected = new List < ProviderDefinition166 > ( ) ;
var serializerSettings = new JsonSerializerOptions
_serializerSettings = new JsonSerializerOptions
{
AllowTrailingCommas = true ,
IgnoreNullValues = false ,
@ -33,10 +26,102 @@ namespace NzbDrone.Core.Datastore.Migration
PropertyNamingPolicy = JsonNamingPolicy . CamelCase ,
WriteIndented = true
} ;
}
protected override void MainDbUpgrade ( )
{
Execute . WithConnection ( RenameTMDbListType ) ;
Execute . WithConnection ( RenameTraktListType ) ;
Execute . WithConnection ( FixConfig ) ;
}
private void RenameTMDbListType ( IDbConnection conn , IDbTransaction tran )
{
var rows = conn . Query < ProviderDefinition166 > ( $"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TMDbPopularImport'" ) ;
var corrected = new List < ProviderDefinition166 > ( ) ;
foreach ( var row in rows )
{
var settings = JsonSerializer . Deserialize < TMDbSettings165 > ( row . Settings , serializerSettings ) ;
var settings = JsonSerializer . Deserialize < TMDbPopularSettings165 > ( row . Settings , _serializerSettings ) ;
var newSettings = new TMDbPopularSettings166
{
TMDbListType = settings . ListType ,
FilterCriteria = new TMDbFilterSettings166
{
MinVoteAverage = settings . FilterCriteria . MinVoteAverage ,
MinVotes = settings . FilterCriteria . MinVotes ,
Certification = settings . FilterCriteria . Ceritification ,
IncludeGenreIds = settings . FilterCriteria . IncludeGenreIds ,
ExcludeGenreIds = settings . FilterCriteria . ExcludeGenreIds ,
LanguageCode = settings . FilterCriteria . LanguageCode
}
} ;
corrected . Add ( new ProviderDefinition166
{
Id = row . Id ,
Implementation = "TMDbPopularImport" ,
ConfigContract = "TMDbPopularSettings" ,
Settings = JsonSerializer . Serialize ( newSettings , _serializerSettings )
} ) ;
}
var updateSql = "UPDATE NetImport SET Settings = @Settings WHERE Id = @Id" ;
conn . Execute ( updateSql , corrected , transaction : tran ) ;
}
private void RenameTraktListType ( IDbConnection conn , IDbTransaction tran )
{
var rows = conn . Query < ProviderDefinition166 > ( $"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TraktImport'" ) ;
var corrected = new List < ProviderDefinition166 > ( ) ;
foreach ( var row in rows )
{
var settings = JsonSerializer . Deserialize < TraktSettings165 > ( row . Settings , _serializerSettings ) ;
var newSettings = new TraktSettings166
{
AccessToken = settings . AccessToken ,
RefreshToken = settings . RefreshToken ,
Expires = settings . Expires ,
Link = settings . Link ,
TraktListType = settings . ListType ,
Username = settings . Username ,
Listname = settings . Listname ,
Rating = settings . Rating ,
Certification = settings . Ceritification ,
Genres = settings . Genres ,
Years = settings . Years ,
Limit = settings . Limit ,
TraktAdditionalParameters = settings . TraktAdditionalParameters ,
SignIn = settings . SignIn
} ;
corrected . Add ( new ProviderDefinition166
{
Id = row . Id ,
Implementation = "TraktImport" ,
ConfigContract = "TraktSettings" ,
Settings = JsonSerializer . Serialize ( newSettings , _serializerSettings )
} ) ;
}
var updateSql = "UPDATE NetImport SET Settings = @Settings WHERE Id = @Id" ;
conn . Execute ( updateSql , corrected , transaction : tran ) ;
}
private void FixConfig ( IDbConnection conn , IDbTransaction tran )
{
var rows = conn . Query < ProviderDefinition166 > ( $"SELECT Id, Implementation, ConfigContract, Settings FROM NetImport WHERE Implementation = 'TMDbImport'" ) ;
var corrected = new List < ProviderDefinition166 > ( ) ;
foreach ( var row in rows )
{
var settings = JsonSerializer . Deserialize < TMDbSettings165 > ( row . Settings , _serializerSettings ) ;
if ( settings . ListId . IsNotNullOrWhiteSpace ( ) )
{
@ -50,19 +135,19 @@ namespace NzbDrone.Core.Datastore.Migration
Id = row . Id ,
Implementation = "TMDbListImport" ,
ConfigContract = "TMDbListSettings" ,
Settings = JsonSerializer . Serialize ( newSettings , serializerSettings)
Settings = JsonSerializer . Serialize ( newSettings , _ serializerSettings)
} ) ;
}
else
{
var newSettings = new TMDbPopularSettings166
{
ListType = settings . ListType ,
TMDb ListType = settings . ListType ,
FilterCriteria = new TMDbFilterSettings166
{
MinVoteAverage = settings . MinVoteAverage ,
MinVotes = settings . MinVotes ,
Cer i tification = settings . Ceritification ,
Cer tification = settings . Ceritification ,
IncludeGenreIds = settings . IncludeGenreIds ,
ExcludeGenreIds = settings . ExcludeGenreIds ,
LanguageCode = settings . LanguageCode
@ -74,7 +159,7 @@ namespace NzbDrone.Core.Datastore.Migration
Id = row . Id ,
Implementation = "TMDbPopularImport" ,
ConfigContract = "TMDbPopularSettings" ,
Settings = JsonSerializer . Serialize ( newSettings , serializerSettings)
Settings = JsonSerializer . Serialize ( newSettings , _ serializerSettings)
} ) ;
}
}
@ -110,9 +195,25 @@ namespace NzbDrone.Core.Datastore.Migration
public string ListId { get ; set ; }
}
private class TMDbPopularSettings16 6
private class TMDbPopularSettings16 5
{
public int ListType { get ; set ; }
public TMDbFilterSettings165 FilterCriteria { get ; set ; }
}
private class TMDbFilterSettings165
{
public string MinVoteAverage { get ; set ; }
public string MinVotes { get ; set ; }
public string Ceritification { get ; set ; }
public string IncludeGenreIds { get ; set ; }
public string ExcludeGenreIds { get ; set ; }
public int LanguageCode { get ; set ; }
}
private class TMDbPopularSettings166
{
public int TMDbListType { get ; set ; }
public TMDbFilterSettings166 FilterCriteria { get ; set ; }
}
@ -120,10 +221,46 @@ namespace NzbDrone.Core.Datastore.Migration
{
public string MinVoteAverage { get ; set ; }
public string MinVotes { get ; set ; }
public string Cer i tification { get ; set ; }
public string Cer tification { get ; set ; }
public string IncludeGenreIds { get ; set ; }
public string ExcludeGenreIds { get ; set ; }
public int LanguageCode { get ; set ; }
}
private class TraktSettings165
{
public string AccessToken { get ; set ; }
public string RefreshToken { get ; set ; }
public DateTime Expires { get ; set ; }
public string Link { get ; set ; }
public int ListType { get ; set ; }
public string Username { get ; set ; }
public string Listname { get ; set ; }
public string Rating { get ; set ; }
public string Ceritification { get ; set ; }
public string Genres { get ; set ; }
public string Years { get ; set ; }
public int Limit { get ; set ; }
public string TraktAdditionalParameters { get ; set ; }
public string SignIn { get ; set ; }
}
private class TraktSettings166
{
public string AccessToken { get ; set ; }
public string RefreshToken { get ; set ; }
public DateTime Expires { get ; set ; }
public string Link { get ; set ; }
public int TraktListType { get ; set ; }
public string Username { get ; set ; }
public string Listname { get ; set ; }
public string Rating { get ; set ; }
public string Certification { get ; set ; }
public string Genres { get ; set ; }
public string Years { get ; set ; }
public int Limit { get ; set ; }
public string TraktAdditionalParameters { get ; set ; }
public string SignIn { get ; set ; }
}
}
}