|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
#region Copyright
|
|
|
|
|
|
|
|
|
|
// /************************************************************************
|
|
|
|
|
// Copyright (c) 2016 Jamie Rees
|
|
|
|
|
// File: Version1100.cs
|
|
|
|
@ -23,16 +24,15 @@
|
|
|
|
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
// ************************************************************************/
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using NLog;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using PlexRequests.Api.Interfaces;
|
|
|
|
|
using PlexRequests.Core.SettingModels;
|
|
|
|
|
using PlexRequests.Core.Users;
|
|
|
|
|
using PlexRequests.Helpers;
|
|
|
|
|
using PlexRequests.Helpers.Permissions;
|
|
|
|
|
using PlexRequests.Store;
|
|
|
|
@ -44,8 +44,10 @@ namespace PlexRequests.Core.Migration.Migrations
|
|
|
|
|
[Migration(11000, "v1.10.0.0")]
|
|
|
|
|
public class Version1100 : BaseMigration, IMigration
|
|
|
|
|
{
|
|
|
|
|
public Version1100(IUserRepository userRepo, IRequestService requestService, ISettingsService<LogSettings> log, IPlexApi plexApi, ISettingsService<PlexSettings> plexService,
|
|
|
|
|
IPlexUserRepository plexusers, ISettingsService<PlexRequestSettings> prSettings, ISettingsService<UserManagementSettings> umSettings,
|
|
|
|
|
public Version1100(IUserRepository userRepo, IRequestService requestService, ISettingsService<LogSettings> log,
|
|
|
|
|
IPlexApi plexApi, ISettingsService<PlexSettings> plexService,
|
|
|
|
|
IPlexUserRepository plexusers, ISettingsService<PlexRequestSettings> prSettings,
|
|
|
|
|
ISettingsService<UserManagementSettings> umSettings,
|
|
|
|
|
ISettingsService<ScheduledJobsSettings> sjs, IRepository<UsersToNotify> usersToNotify)
|
|
|
|
|
{
|
|
|
|
|
UserRepo = userRepo;
|
|
|
|
@ -59,7 +61,9 @@ namespace PlexRequests.Core.Migration.Migrations
|
|
|
|
|
ScheduledJobSettings = sjs;
|
|
|
|
|
UserNotifyRepo = usersToNotify;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Version => 11000;
|
|
|
|
|
|
|
|
|
|
private IUserRepository UserRepo { get; }
|
|
|
|
|
private IRequestService RequestService { get; }
|
|
|
|
|
private ISettingsService<LogSettings> Log { get; }
|
|
|
|
@ -71,6 +75,9 @@ namespace PlexRequests.Core.Migration.Migrations
|
|
|
|
|
private ISettingsService<ScheduledJobsSettings> ScheduledJobSettings { get; }
|
|
|
|
|
private IRepository<UsersToNotify> UserNotifyRepo { get; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
public void Start(IDbConnection con)
|
|
|
|
|
{
|
|
|
|
|
UpdateDb(con);
|
|
|
|
@ -88,6 +95,8 @@ namespace PlexRequests.Core.Migration.Migrations
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MigrateUserNotifications()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var usersToNotify = UserNotifyRepo.GetAll();
|
|
|
|
|
var plexUsers = PlexUsers.GetAll().ToList();
|
|
|
|
@ -100,7 +109,9 @@ namespace PlexRequests.Core.Migration.Migrations
|
|
|
|
|
|
|
|
|
|
foreach (var u in usersToNotify)
|
|
|
|
|
{
|
|
|
|
|
var selectedPlexUser = plexUsers.FirstOrDefault(x => x.Username.Equals(u.Username, StringComparison.CurrentCultureIgnoreCase));
|
|
|
|
|
var selectedPlexUser =
|
|
|
|
|
plexUsers.FirstOrDefault(
|
|
|
|
|
x => x.Username.Equals(u.Username, StringComparison.CurrentCultureIgnoreCase));
|
|
|
|
|
if (selectedPlexUser != null)
|
|
|
|
|
{
|
|
|
|
|
selectedPlexUser.Features += (int)Features.RequestAddedNotification;
|
|
|
|
@ -114,11 +125,18 @@ namespace PlexRequests.Core.Migration.Migrations
|
|
|
|
|
selectedLocalUser.Features += (int)Features.RequestAddedNotification;
|
|
|
|
|
UserRepo.Update(selectedLocalUser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdateScheduledJobs)");
|
|
|
|
|
Logger.Fatal(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateScheduledJobs()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var settings = ScheduledJobSettings.GetSettings();
|
|
|
|
|
|
|
|
|
@ -127,8 +145,16 @@ namespace PlexRequests.Core.Migration.Migrations
|
|
|
|
|
|
|
|
|
|
ScheduledJobSettings.SaveSettings(settings);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdateScheduledJobs)");
|
|
|
|
|
Logger.Fatal(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PopulateDefaultUserManagementSettings()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var plexRequestSettings = PlexRequestSettings.GetSettings();
|
|
|
|
|
|
|
|
|
@ -142,8 +168,16 @@ namespace PlexRequests.Core.Migration.Migrations
|
|
|
|
|
AutoApproveTvShows = !plexRequestSettings.RequireTvShowApproval
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Fatal("Exception when migrating Version 1.10.0 (PopulateDefaultUserMngmentSettings)");
|
|
|
|
|
Logger.Fatal(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdatePlexUsers()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var settings = PlexSettings.GetSettings();
|
|
|
|
|
if (string.IsNullOrEmpty(settings.PlexAuthToken))
|
|
|
|
@ -210,10 +244,17 @@ namespace PlexRequests.Core.Migration.Migrations
|
|
|
|
|
|
|
|
|
|
PlexUsers.Insert(m);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdatePlexUsers)");
|
|
|
|
|
Logger.Fatal(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ResetLogLevel()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var logSettings = Log.GetSettings();
|
|
|
|
|
logSettings.Level = LogLevel.Error.Ordinal;
|
|
|
|
@ -221,8 +262,16 @@ namespace PlexRequests.Core.Migration.Migrations
|
|
|
|
|
|
|
|
|
|
LoggingHelper.ReconfigureLogLevel(LogLevel.FromOrdinal(logSettings.Level));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Fatal("Exception when migrating Version 1.10.0 (ResetLogLvl)");
|
|
|
|
|
Logger.Fatal(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateDb(IDbConnection con)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Create the two new columns
|
|
|
|
|
con.AlterTable("Users", "ADD", "Permissions", true, "INTEGER");
|
|
|
|
@ -258,8 +307,16 @@ namespace PlexRequests.Core.Migration.Migrations
|
|
|
|
|
}
|
|
|
|
|
RequestService.BatchUpdate(requestedModels);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdateDb)");
|
|
|
|
|
Logger.Fatal(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateAdmin()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var users = UserRepo.GetAll().ToList();
|
|
|
|
|
|
|
|
|
@ -278,5 +335,11 @@ namespace PlexRequests.Core.Migration.Migrations
|
|
|
|
|
|
|
|
|
|
UserRepo.UpdateAll(users);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdateAdmin)");
|
|
|
|
|
Logger.Fatal(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|