From bfea6815224470b104ce215bfca326fb0a5816a6 Mon Sep 17 00:00:00 2001 From: Jim MacKenzie Date: Fri, 14 Oct 2016 22:14:27 -0500 Subject: [PATCH] Migration setup --- .../SettingModels/PlexRequestSettings.cs | 3 +- PlexRequests.Core/Setup.cs | 30 +++++++++++++++++++ PlexRequests.Services/Jobs/RecentlyAdded.cs | 8 ++--- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/PlexRequests.Core/SettingModels/PlexRequestSettings.cs b/PlexRequests.Core/SettingModels/PlexRequestSettings.cs index 0802bb204..682e584f5 100644 --- a/PlexRequests.Core/SettingModels/PlexRequestSettings.cs +++ b/PlexRequests.Core/SettingModels/PlexRequestSettings.cs @@ -58,7 +58,8 @@ namespace PlexRequests.Core.SettingModels public bool Wizard { get; set; } public bool DisableTvRequestsByEpisode { get; set; } public bool DisableTvRequestsBySeason { get; set; } - + //To Remove at some point? + public bool SendRecentlyAddedEmail { get; set; } public string CustomDonationUrl { get; set; } public bool EnableCustomDonationUrl { get; set; } public string CustomDonationMessage { get; set; } diff --git a/PlexRequests.Core/Setup.cs b/PlexRequests.Core/Setup.cs index dac15a731..e16613161 100644 --- a/PlexRequests.Core/Setup.cs +++ b/PlexRequests.Core/Setup.cs @@ -72,6 +72,10 @@ namespace PlexRequests.Core { MigrateToVersion1910(); } + if (version > 1943 && version <= 1945) + { + MigrateToVersion1945(); + } } return Db.DbConnection().ConnectionString; @@ -275,5 +279,31 @@ namespace PlexRequests.Core Log.Error(e); } } + + + /// + /// Migrates to version1945 + /// + public void MigrateToVersion1945() + { + try + { + var settings = new SettingsServiceV2(new SettingsJsonRepository(Db, new MemoryCacheProvider())); + var plex = settings.GetSettings(); + var newsLetterSettings = new SettingsServiceV2(new SettingsJsonRepository(Db, new MemoryCacheProvider())); + var newsLetter = newsLetterSettings.GetSettings(); + if (plex.SendRecentlyAddedEmail) + { + newsLetter.SendRecentlyAddedEmail = plex.SendRecentlyAddedEmail; + plex.SendRecentlyAddedEmail = false; + settings.SaveSettings(plex); + newsLetterSettings.SaveSettings(newsLetter); + } + } + catch (Exception e) + { + Log.Error(e); + } + } } } diff --git a/PlexRequests.Services/Jobs/RecentlyAdded.cs b/PlexRequests.Services/Jobs/RecentlyAdded.cs index 1ffee4ebb..6f0e76f3a 100644 --- a/PlexRequests.Services/Jobs/RecentlyAdded.cs +++ b/PlexRequests.Services/Jobs/RecentlyAdded.cs @@ -48,14 +48,14 @@ namespace PlexRequests.Services.Jobs public class RecentlyAdded : IJob, IRecentlyAdded { public RecentlyAdded(IPlexApi api, ISettingsService plexSettings, ISettingsService email, - ISettingsService scheduledService, IJobRecord rec, ISettingsService plexRequest) + ISettingsService scheduledService, IJobRecord rec, ISettingsService newsletter) { JobRecord = rec; Api = api; PlexSettings = plexSettings; EmailSettings = email; ScheduledJobsSettings = scheduledService; - PlexRequestSettings = plexRequest; + NewsletterSettings = newsletter; } private IPlexApi Api { get; } @@ -63,7 +63,7 @@ namespace PlexRequests.Services.Jobs private readonly TheMovieDbApi _movieApi = new TheMovieDbApi(); private ISettingsService PlexSettings { get; } private ISettingsService EmailSettings { get; } - private ISettingsService PlexRequestSettings { get; } + private ISettingsService NewsletterSettings { get; } private ISettingsService ScheduledJobsSettings { get; } private IJobRecord JobRecord { get; } @@ -73,7 +73,7 @@ namespace PlexRequests.Services.Jobs { try { - var settings = PlexRequestSettings.GetSettings(); + var settings = NewsletterSettings.GetSettings(); if (!settings.SendRecentlyAddedEmail) { return;