aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Startup.Common/Migrations/Release5767.cs
blob: d1c085734ed6a6c845bcd7b00fdbd615c5345757 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Server.Implementations.LiveTv;
using MediaBrowser.Server.Implementations.Persistence;
using MediaBrowser.Server.Implementations.ScheduledTasks;

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

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

        public async void Run()
        {
            var name = "5767.1";

            if (_config.Configuration.Migrations.Contains(name, StringComparer.OrdinalIgnoreCase))
            {
                return;
            }

            Task.Run(async () =>
            {
                await Task.Delay(3000).ConfigureAwait(false);

                _taskManager.QueueScheduledTask<RefreshChannelsScheduledTask>();
                _taskManager.QueueScheduledTask<CleanDatabaseScheduledTask>();
                _taskManager.QueueScheduledTask<RefreshMediaLibraryTask>();
            });

            // Wait a few minutes before marking this as done. Make sure the server doesn't get restarted.
            await Task.Delay(300000).ConfigureAwait(false);
            
            var list = _config.Configuration.Migrations.ToList();
            list.Add(name);
            _config.Configuration.Migrations = list.ToArray();
            _config.SaveConfiguration();
        }
    }
}