aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs
blob: 3cd92bcde8a168a22abb89fd43fbf1a01e1ddd7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Threading.Tasks;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Server.Implementations.Persistence;

namespace MediaBrowser.Server.Startup.Common.Migrations
{
    public class DbMigration : IVersionMigration
    {
        private readonly IServerConfigurationManager _config;
        private readonly ITaskManager _taskManager;

        public DbMigration(IServerConfigurationManager config, ITaskManager taskManager)
        {
            _config = config;
            _taskManager = taskManager;
        }

        public void Run()
        {
            if (_config.Configuration.MigrationVersion < CleanDatabaseScheduledTask.MigrationVersion && 
                _config.Configuration.IsStartupWizardCompleted)
            {
                _taskManager.SuspendTriggers = true;
                CleanDatabaseScheduledTask.EnableUnavailableMessage = true;
                
                Task.Run(async () =>
                {
                    await Task.Delay(100).ConfigureAwait(false);

                    _taskManager.Execute<CleanDatabaseScheduledTask>();
                });
            }
        }
    }
}