diff --git a/src/NzbDrone.Core/Datastore/Migration/139_fix_indexer_baseurl.cs b/src/NzbDrone.Core/Datastore/Migration/139_fix_indexer_baseurl.cs new file mode 100644 index 000000000..779d70cc6 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/139_fix_indexer_baseurl.cs @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using System.Data; +using FluentMigrator; +using Newtonsoft.Json.Linq; +using NzbDrone.Common.Extensions; +using NzbDrone.Common.Serializer; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(139)] + public class consolidate_indexer_baseurl : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Execute.WithConnection(RenameUrlToBaseUrl); + } + + private void RenameUrlToBaseUrl(IDbConnection conn, IDbTransaction tran) + { + using (var cmd = conn.CreateCommand()) + { + cmd.Transaction = tran; + cmd.CommandText = "SELECT Id, Settings FROM Indexers WHERE ConfigContract IN ('NewznabSettings', 'TorznabSettings', 'IPTorrentsSettings', 'OmgwtfnzbsSettings', )"; + + using (var reader = cmd.ExecuteReader()) + { + while (reader.Read()) + { + var id = reader.GetInt32(0); + var settings = reader.GetString(1); + + if (settings.IsNotNullOrWhiteSpace()) + { + var jsonObject = Json.Deserialize(settings); + + if (jsonObject.Property("url") != null) + { + jsonObject.AddFirst(new JProperty("baseUrl", jsonObject["url"])); + jsonObject.Remove("url"); + settings = jsonObject.ToJson(); + + using (var updateCmd = conn.CreateCommand()) + { + updateCmd.Transaction = tran; + updateCmd.CommandText = "UPDATE Indexers SET Settings = ? WHERE Id = ?"; + updateCmd.AddParameter(settings); + updateCmd.AddParameter(id); + updateCmd.ExecuteNonQuery(); + } + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 532038f52..40f2693a3 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -1291,6 +1291,7 @@ +