From 68352e0340c4428028db088d37d8f896247bd713 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Fri, 30 May 2014 17:54:02 +0200 Subject: [PATCH] Updated migration to enable completed download handling for new users (those with no drone factory configured) --- .../Configuration/ConfigServiceFixture.cs | 2 ++ .../Migration/051_download_client_import.cs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/NzbDrone.Core.Test/Configuration/ConfigServiceFixture.cs b/src/NzbDrone.Core.Test/Configuration/ConfigServiceFixture.cs index 35caa1216..5f686eac3 100644 --- a/src/NzbDrone.Core.Test/Configuration/ConfigServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Configuration/ConfigServiceFixture.cs @@ -14,6 +14,8 @@ namespace NzbDrone.Core.Test.Configuration public void SetUp() { Mocker.SetConstant(Mocker.Resolve()); + + Db.All().ForEach(Db.Delete); } [Test] diff --git a/src/NzbDrone.Core/Datastore/Migration/051_download_client_import.cs b/src/NzbDrone.Core/Datastore/Migration/051_download_client_import.cs index f801eda79..c773e6224 100644 --- a/src/NzbDrone.Core/Datastore/Migration/051_download_client_import.cs +++ b/src/NzbDrone.Core/Datastore/Migration/051_download_client_import.cs @@ -16,11 +16,30 @@ namespace NzbDrone.Core.Datastore.Migration { protected override void MainDbUpgrade() { + Execute.WithConnection(EnableCompletedDownloadHandlingForNewUsers); + Execute.WithConnection(ConvertFolderSettings); Execute.WithConnection(AssociateImportedHistoryItems); } + private void EnableCompletedDownloadHandlingForNewUsers(IDbConnection conn, IDbTransaction tran) + { + using (IDbCommand cmd = conn.CreateCommand()) + { + cmd.Transaction = tran; + cmd.CommandText = @"SELECT Value FROM Config WHERE Key = 'downloadedepisodesfolder'"; + + var result = cmd.ExecuteScalar(); + + if (result == null) + { + cmd.CommandText = @"INSERT INTO Config (Key, Value) VALUES ('enablecompleteddownloadhandling', 'True')"; + cmd.ExecuteNonQuery(); + } + } + } + private void ConvertFolderSettings(IDbConnection conn, IDbTransaction tran) { using (IDbCommand downloadClientsCmd = conn.CreateCommand())