2020-01-15 21:39:49 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Data;
|
|
|
|
using System.Text.Json;
|
|
|
|
using Dapper;
|
|
|
|
using FluentMigrator;
|
|
|
|
using NzbDrone.Common.Extensions;
|
2020-08-16 05:19:23 +00:00
|
|
|
using NzbDrone.Core.Datastore.Converters;
|
2020-01-15 21:39:49 +00:00
|
|
|
using NzbDrone.Core.Datastore.Migration.Framework;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Datastore.Migration
|
|
|
|
{
|
|
|
|
[Migration(166)]
|
|
|
|
public class fix_tmdb_list_config : NzbDroneMigrationBase
|
|
|
|
{
|
2020-01-15 21:41:57 +00:00
|
|
|
private readonly JsonSerializerOptions _serializerSettings;
|
2020-01-15 21:39:49 +00:00
|
|
|
|
2020-01-15 21:41:57 +00:00
|
|
|
public fix_tmdb_list_config()
|
2020-01-15 21:39:49 +00:00
|
|
|
{
|
2020-01-15 21:41:57 +00:00
|
|
|
_serializerSettings = new JsonSerializerOptions
|
2020-01-15 21:39:49 +00:00
|
|
|
{
|
|
|
|
AllowTrailingCommas = true,
|
|
|
|
IgnoreNullValues = false,
|
|
|
|
PropertyNameCaseInsensitive = true,
|
|
|
|
DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,
|
|
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
|
|
|
WriteIndented = true
|
|
|
|
};
|
2020-07-17 01:14:37 +00:00
|
|
|
|
|
|
|
_serializerSettings.Converters.Add(new StringConverter());
|
2020-01-15 21:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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>();
|
2020-01-15 21:39:49 +00:00
|
|
|
|
|
|
|
foreach (var row in rows)
|
|
|
|
{
|
2020-01-15 21:41:57 +00:00
|
|
|
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);
|
2020-01-15 21:39:49 +00:00
|
|
|
|
|
|
|
if (settings.ListId.IsNotNullOrWhiteSpace())
|
|
|
|
{
|
|
|
|
var newSettings = new TMDbListSettings166
|
|
|
|
{
|
|
|
|
ListId = settings.ListId
|
|
|
|
};
|
|
|
|
|
|
|
|
corrected.Add(new ProviderDefinition166
|
|
|
|
{
|
|
|
|
Id = row.Id,
|
|
|
|
Implementation = "TMDbListImport",
|
|
|
|
ConfigContract = "TMDbListSettings",
|
2020-01-15 21:41:57 +00:00
|
|
|
Settings = JsonSerializer.Serialize(newSettings, _serializerSettings)
|
2020-01-15 21:39:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var newSettings = new TMDbPopularSettings166
|
|
|
|
{
|
2020-01-15 21:41:57 +00:00
|
|
|
TMDbListType = settings.ListType,
|
2020-01-15 21:39:49 +00:00
|
|
|
FilterCriteria = new TMDbFilterSettings166
|
|
|
|
{
|
|
|
|
MinVoteAverage = settings.MinVoteAverage,
|
|
|
|
MinVotes = settings.MinVotes,
|
2020-01-15 21:41:57 +00:00
|
|
|
Certification = settings.Ceritification,
|
2020-01-15 21:39:49 +00:00
|
|
|
IncludeGenreIds = settings.IncludeGenreIds,
|
|
|
|
ExcludeGenreIds = settings.ExcludeGenreIds,
|
|
|
|
LanguageCode = settings.LanguageCode
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
corrected.Add(new ProviderDefinition166
|
|
|
|
{
|
|
|
|
Id = row.Id,
|
|
|
|
Implementation = "TMDbPopularImport",
|
|
|
|
ConfigContract = "TMDbPopularSettings",
|
2020-01-15 21:41:57 +00:00
|
|
|
Settings = JsonSerializer.Serialize(newSettings, _serializerSettings)
|
2020-01-15 21:39:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var updateSql = "UPDATE NetImport SET Implementation = @Implementation, ConfigContract = @ConfigContract, Settings = @Settings WHERE Id = @Id";
|
|
|
|
conn.Execute(updateSql, corrected, transaction: tran);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class ProviderDefinition166 : ModelBase
|
|
|
|
{
|
|
|
|
public string Implementation { get; set; }
|
|
|
|
public string ConfigContract { get; set; }
|
|
|
|
public string Settings { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TMDbSettings165
|
|
|
|
{
|
|
|
|
public string Link { get; set; }
|
|
|
|
public int ListType { get; set; }
|
|
|
|
public string ListId { get; set; }
|
|
|
|
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 TMDbListSettings166
|
|
|
|
{
|
|
|
|
public string ListId { get; set; }
|
|
|
|
}
|
|
|
|
|
2020-01-15 21:41:57 +00:00
|
|
|
private class TMDbPopularSettings165
|
2020-01-15 21:39:49 +00:00
|
|
|
{
|
|
|
|
public int ListType { get; set; }
|
2020-01-15 21:41:57 +00:00
|
|
|
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; }
|
2020-01-15 21:39:49 +00:00
|
|
|
public TMDbFilterSettings166 FilterCriteria { get; set; }
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TMDbFilterSettings166
|
|
|
|
{
|
|
|
|
public string MinVoteAverage { get; set; }
|
|
|
|
public string MinVotes { get; set; }
|
2020-01-15 21:41:57 +00:00
|
|
|
public string Certification { get; set; }
|
2020-01-15 21:39:49 +00:00
|
|
|
public string IncludeGenreIds { get; set; }
|
|
|
|
public string ExcludeGenreIds { get; set; }
|
|
|
|
public int LanguageCode { get; set; }
|
|
|
|
}
|
2020-01-15 21:41:57 +00:00
|
|
|
|
|
|
|
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; }
|
|
|
|
}
|
2020-01-15 21:39:49 +00:00
|
|
|
}
|
|
|
|
}
|