2015-10-29 09:28:05 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2016-11-18 03:39:20 -05:00
|
|
|
|
using Emby.Server.Implementations.Data;
|
2015-10-29 09:28:05 -04:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2016-10-23 15:47:34 -04:00
|
|
|
|
using MediaBrowser.Model.Tasks;
|
2016-11-11 01:43:42 -05:00
|
|
|
|
using Emby.Server.Core.Data;
|
2016-11-18 03:39:20 -05:00
|
|
|
|
using Emby.Server.Implementations.Migrations;
|
2015-10-29 09:28:05 -04:00
|
|
|
|
|
2016-11-11 01:43:42 -05:00
|
|
|
|
namespace Emby.Server.Core.Migrations
|
2015-10-29 09:28:05 -04:00
|
|
|
|
{
|
|
|
|
|
|
public class DbMigration : IVersionMigration
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
|
|
|
private readonly ITaskManager _taskManager;
|
|
|
|
|
|
|
|
|
|
|
|
public DbMigration(IServerConfigurationManager config, ITaskManager taskManager)
|
|
|
|
|
|
{
|
|
|
|
|
|
_config = config;
|
|
|
|
|
|
_taskManager = taskManager;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-17 02:09:29 -04:00
|
|
|
|
public async Task Run()
|
2015-10-29 09:28:05 -04:00
|
|
|
|
{
|
2016-06-15 14:56:37 -04:00
|
|
|
|
// If a forced migration is required, do that now
|
2016-02-14 23:46:51 -05:00
|
|
|
|
if (_config.Configuration.MigrationVersion < CleanDatabaseScheduledTask.MigrationVersion)
|
2015-10-29 09:28:05 -04:00
|
|
|
|
{
|
2016-02-14 23:46:51 -05:00
|
|
|
|
if (!_config.Configuration.IsStartupWizardCompleted)
|
|
|
|
|
|
{
|
|
|
|
|
|
_config.Configuration.MigrationVersion = CleanDatabaseScheduledTask.MigrationVersion;
|
|
|
|
|
|
_config.SaveConfiguration();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-02-03 15:52:45 -05:00
|
|
|
|
_taskManager.SuspendTriggers = true;
|
2016-02-01 14:54:49 -05:00
|
|
|
|
CleanDatabaseScheduledTask.EnableUnavailableMessage = true;
|
|
|
|
|
|
|
2015-11-02 12:25:01 -05:00
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
|
{
|
2016-02-14 23:46:51 -05:00
|
|
|
|
await Task.Delay(1000).ConfigureAwait(false);
|
2015-10-29 09:28:05 -04:00
|
|
|
|
|
2016-02-03 15:52:45 -05:00
|
|
|
|
_taskManager.Execute<CleanDatabaseScheduledTask>();
|
2015-11-02 12:25:01 -05:00
|
|
|
|
});
|
2016-06-15 14:56:37 -04:00
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_config.Configuration.SchemaVersion < SqliteItemRepository.LatestSchemaVersion)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!_config.Configuration.IsStartupWizardCompleted)
|
|
|
|
|
|
{
|
|
|
|
|
|
_config.Configuration.SchemaVersion = SqliteItemRepository.LatestSchemaVersion;
|
|
|
|
|
|
_config.SaveConfiguration();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
await Task.Delay(1000).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
_taskManager.Execute<CleanDatabaseScheduledTask>();
|
|
|
|
|
|
});
|
2015-11-02 12:25:01 -05:00
|
|
|
|
}
|
2015-10-29 09:28:05 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|