RemoveDownloadImagesInAdvance.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Library;
  4. using Microsoft.Extensions.Logging;
  5. namespace Jellyfin.Server.Migrations.Routines
  6. {
  7. /// <summary>
  8. /// Removes the old 'RemoveDownloadImagesInAdvance' from library options.
  9. /// </summary>
  10. internal class RemoveDownloadImagesInAdvance : IMigrationRoutine
  11. {
  12. private readonly ILogger<RemoveDownloadImagesInAdvance> _logger;
  13. private readonly ILibraryManager _libraryManager;
  14. public RemoveDownloadImagesInAdvance(ILogger<RemoveDownloadImagesInAdvance> logger, ILibraryManager libraryManager)
  15. {
  16. _logger = logger;
  17. _libraryManager = libraryManager;
  18. }
  19. /// <inheritdoc/>
  20. public Guid Id => Guid.Parse("{A81F75E0-8F43-416F-A5E8-516CCAB4D8CC}");
  21. /// <inheritdoc/>
  22. public string Name => "RemoveDownloadImagesInAdvance";
  23. /// <inheritdoc/>
  24. public bool PerformOnNewInstall => false;
  25. /// <inheritdoc/>
  26. public void Perform()
  27. {
  28. var virtualFolders = _libraryManager.GetVirtualFolders(false);
  29. _logger.LogInformation("Removing 'RemoveDownloadImagesInAdvance' settings in all the libraries");
  30. foreach (var virtualFolder in virtualFolders)
  31. {
  32. // Some virtual folders don't have a proper item id.
  33. if (!Guid.TryParse(virtualFolder.ItemId, out var folderId))
  34. {
  35. continue;
  36. }
  37. var libraryOptions = virtualFolder.LibraryOptions;
  38. var collectionFolder = _libraryManager.GetItemById<CollectionFolder>(folderId) ?? throw new InvalidOperationException("Failed to find CollectionFolder");
  39. // The property no longer exists in LibraryOptions, so we just re-save the options to get old data removed.
  40. collectionFolder.UpdateLibraryOptions(libraryOptions);
  41. _logger.LogInformation("Removed from '{VirtualFolder}'", virtualFolder.Name);
  42. }
  43. }
  44. }
  45. }