2
0

RenameEnableGroupingIntoCollections.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml.Linq;
  6. using Emby.Server.Implementations;
  7. using Microsoft.Extensions.Logging;
  8. namespace Jellyfin.Server.Migrations.PreStartupRoutines;
  9. /// <inheritdoc />
  10. #pragma warning disable CS0618 // Type or member is obsolete
  11. [JellyfinMigration("2025-04-20T04:00:00", nameof(RenameEnableGroupingIntoCollections), "E73B777D-CD5C-4E71-957A-B86B3660B7CF", Stage = Stages.JellyfinMigrationStageTypes.PreInitialisation)]
  12. public class RenameEnableGroupingIntoCollections : IMigrationRoutine
  13. #pragma warning restore CS0618 // Type or member is obsolete
  14. {
  15. private readonly ServerApplicationPaths _applicationPaths;
  16. private readonly ILogger<RenameEnableGroupingIntoCollections> _logger;
  17. /// <summary>
  18. /// Initializes a new instance of the <see cref="RenameEnableGroupingIntoCollections"/> class.
  19. /// </summary>
  20. /// <param name="applicationPaths">An instance of <see cref="ServerApplicationPaths"/>.</param>
  21. /// <param name="loggerFactory">An instance of the <see cref="ILoggerFactory"/> interface.</param>
  22. public RenameEnableGroupingIntoCollections(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory)
  23. {
  24. _applicationPaths = applicationPaths;
  25. _logger = loggerFactory.CreateLogger<RenameEnableGroupingIntoCollections>();
  26. }
  27. /// <inheritdoc />
  28. public void Perform()
  29. {
  30. string path = Path.Combine(_applicationPaths.ConfigurationDirectoryPath, "system.xml");
  31. if (!File.Exists(path))
  32. {
  33. _logger.LogWarning("Configuration file not found: {Path}", path);
  34. return;
  35. }
  36. try
  37. {
  38. XDocument xmlDocument = XDocument.Load(path);
  39. var element = xmlDocument.Descendants("EnableGroupingIntoCollections").FirstOrDefault();
  40. if (element is not null)
  41. {
  42. element.Name = "EnableGroupingMoviesIntoCollections";
  43. _logger.LogInformation("The tag <EnableGroupingIntoCollections> was successfully renamed to <EnableGroupingMoviesIntoCollections>.");
  44. xmlDocument.Save(path);
  45. }
  46. }
  47. catch (Exception ex)
  48. {
  49. _logger.LogError(ex, "An error occurred while updating the XML file: {Message}", ex.Message);
  50. }
  51. }
  52. }