aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server/Migrations/Routines/RemoveDownloadImagesInAdvance.cs
blob: 52fb93d594749ab2535a2e99af11200454dd2a2b (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
51
52
using System;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using Microsoft.Extensions.Logging;

namespace Jellyfin.Server.Migrations.Routines
{
    /// <summary>
    /// Removes the old 'RemoveDownloadImagesInAdvance' from library options.
    /// </summary>
    internal class RemoveDownloadImagesInAdvance : IMigrationRoutine
    {
        private readonly ILogger<RemoveDownloadImagesInAdvance> _logger;
        private readonly ILibraryManager _libraryManager;

        public RemoveDownloadImagesInAdvance(ILogger<RemoveDownloadImagesInAdvance> logger, ILibraryManager libraryManager)
        {
            _logger = logger;
            _libraryManager = libraryManager;
        }

        /// <inheritdoc/>
        public Guid Id => Guid.Parse("{A81F75E0-8F43-416F-A5E8-516CCAB4D8CC}");

        /// <inheritdoc/>
        public string Name => "RemoveDownloadImagesInAdvance";

        /// <inheritdoc/>
        public bool PerformOnNewInstall => false;

        /// <inheritdoc/>
        public void Perform()
        {
            var virtualFolders = _libraryManager.GetVirtualFolders(false);
            _logger.LogInformation("Removing 'RemoveDownloadImagesInAdvance' settings in all the libraries");
            foreach (var virtualFolder in virtualFolders)
            {
                // Some virtual folders don't have a proper item id.
                if (!Guid.TryParse(virtualFolder.ItemId, out var folderId))
                {
                    continue;
                }

                var libraryOptions = virtualFolder.LibraryOptions;
                var collectionFolder = _libraryManager.GetItemById<CollectionFolder>(folderId) ?? throw new InvalidOperationException("Failed to find CollectionFolder");
                // The property no longer exists in LibraryOptions, so we just re-save the options to get old data removed.
                collectionFolder.UpdateLibraryOptions(libraryOptions);
                _logger.LogInformation("Removed from '{VirtualFolder}'", virtualFolder.Name);
            }
        }
    }
}