finished #646 and fixed #664

This commit is contained in:
Jamie.Rees 2016-11-14 13:16:02 +00:00
commit 55f1309140
41 changed files with 494 additions and 261 deletions

View file

@ -23,37 +23,30 @@ namespace PlexRequests.Core.Migration
{
var con = Db.DbConnection();
var versions = GetMigrations();
var dbVersion = con.GetVersionInfo().OrderByDescending(x => x.Version).FirstOrDefault();
if (dbVersion == null)
{
dbVersion = new TableCreation.VersionInfo { Version = 0 };
}
var dbVersion = con.GetVersionInfo().OrderByDescending(x => x.Version).FirstOrDefault() ??
new TableCreation.VersionInfo { Version = 0 };
foreach (var v in versions)
{
#if !DEBUG
if (v.Value.Version > dbVersion.Version)
{
// Assuming only one constructor
var ctor = v.Key.GetConstructors().FirstOrDefault();
var dependencies = new List<object>();
#endif
// Assuming only one constructor
var ctor = v.Key.GetConstructors().FirstOrDefault();
var dependencies = ctor.GetParameters().Select(param => Kernel.Get(param.ParameterType)).ToList();
foreach (var param in ctor.GetParameters())
{
var dep = Kernel.Get(param.ParameterType);
dependencies.Add(dep);
}
var method = v.Key.GetMethod("Start");
if (method != null)
{
var classInstance = Activator.CreateInstance(v.Key, dependencies.Any() ? dependencies.ToArray() : null);
var parametersArray = new object[] { Db.DbConnection() };
var method = v.Key.GetMethod("Start");
if (method != null)
{
object result = null;
var classInstance = Activator.CreateInstance(v.Key, dependencies.Any() ? dependencies.ToArray() : null);
var parametersArray = new object[] { Db.DbConnection() };
method.Invoke(classInstance, parametersArray);
}
method.Invoke(classInstance, parametersArray);
}
#if !DEBUG
}
#endif
}
}

View file

@ -27,7 +27,10 @@
using System;
using System.Data;
using NLog;
using System.Linq;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.Helpers.Permissions;
using PlexRequests.Store;
using PlexRequests.Store.Repository;
@ -37,14 +40,16 @@ namespace PlexRequests.Core.Migration.Migrations
[Migration(11000, "v1.10.0.0")]
public class Version1100 : BaseMigration, IMigration
{
public Version1100(IUserRepository userRepo, IRequestService requestService)
public Version1100(IUserRepository userRepo, IRequestService requestService, ISettingsService<LogSettings> log)
{
UserRepo = userRepo;
RequestService = requestService;
Log = log;
}
public int Version => 11000;
private IUserRepository UserRepo { get; }
private IRequestService RequestService { get; }
private ISettingsService<LogSettings> Log { get; }
public void Start(IDbConnection con)
{
@ -52,22 +57,25 @@ namespace PlexRequests.Core.Migration.Migrations
// Update the current admin permissions set
UpdateAdmin();
ResetLogLevel();
UpdateSchema(con, Version);
}
private void ResetLogLevel()
{
var logSettings = Log.GetSettings();
logSettings.Level = LogLevel.Error.Ordinal;
Log.SaveSettings(logSettings);
LoggingHelper.ReconfigureLogLevel(LogLevel.FromOrdinal(logSettings.Level));
}
private void UpdateDb(IDbConnection con)
{
// Create the two new columns
con.AlterTable("Users", "ADD", "Permissions", true, "INTEGER");
con.AlterTable("Users", "ADD", "Features", true, "INTEGER");
// Add the new 'running' item into the scheduled jobs so we can check if the cachers are running
con.AlterTable("ScheduledJobs", "ADD", "Running", true, "INTEGER");
//https://image.tmdb.org/t/p/w150/https://image.tmdb.org/t/p/w150//aqhAqttDq7zgsTaBHtCD8wmTk6k.jpg
// UI = https://image.tmdb.org/t/p/w150/{{posterPath}}

View file

@ -45,6 +45,10 @@
<Reference Include="Ninject">
<HintPath>..\packages\Ninject.3.2.0.0\lib\net45-full\Ninject.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.3.11\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Quartz, Version=2.3.3.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
<HintPath>..\packages\Quartz.2.3.3\lib\net40\Quartz.dll</HintPath>
<Private>True</Private>

View file

@ -2,5 +2,6 @@
<packages>
<package id="Common.Logging" version="3.0.0" targetFramework="net45" />
<package id="Common.Logging.Core" version="3.0.0" targetFramework="net45" />
<package id="NLog" version="4.3.11" targetFramework="net45" />
<package id="Quartz" version="2.3.3" targetFramework="net45" />
</packages>