Add migration to properly set playlist owner

This commit is contained in:
Shadowghost 2023-03-10 19:16:57 +01:00
parent 76ae599bd3
commit 8d158df678
4 changed files with 90 additions and 1 deletions

View File

@ -563,5 +563,19 @@ namespace Emby.Server.Implementations.Playlists
}
}
}
public async Task UpdatePlaylist(Playlist playlist)
{
var currentPlaylist = (Playlist)_libraryManager.GetItemById(playlist.Id);
currentPlaylist.OwnerUserId = playlist.OwnerUserId;
currentPlaylist.Shares = playlist.Shares;
await playlist.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
if (playlist.IsFile)
{
SavePlaylistFile(currentPlaylist);
}
}
}
}

View File

@ -40,7 +40,8 @@ namespace Jellyfin.Server.Migrations
typeof(Routines.ReaddDefaultPluginRepository),
typeof(Routines.MigrateDisplayPreferencesDb),
typeof(Routines.RemoveDownloadImagesInAdvance),
typeof(Routines.MigrateAuthenticationDb)
typeof(Routines.MigrateAuthenticationDb),
typeof(Routines.FixPlaylistOwner)
};
/// <summary>

View File

@ -0,0 +1,67 @@
using System;
using System.Linq;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Playlists;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Server.Migrations.Routines;
/// <summary>
/// Properly set playlist owner.
/// </summary>
internal class FixPlaylistOwner : IMigrationRoutine
{
private readonly ILogger<RemoveDuplicateExtras> _logger;
private readonly ILibraryManager _libraryManager;
private readonly IPlaylistManager _playlistManager;
public FixPlaylistOwner(
ILogger<RemoveDuplicateExtras> logger,
ILibraryManager libraryManager,
IPlaylistManager playlistManager)
{
_logger = logger;
_libraryManager = libraryManager;
_playlistManager = playlistManager;
}
/// <inheritdoc/>
public Guid Id => Guid.Parse("{615DFA9E-2497-4DBB-A472-61938B752C5B}");
/// <inheritdoc/>
public string Name => "FixPlaylistOwner";
/// <inheritdoc/>
public bool PerformOnNewInstall => false;
/// <inheritdoc/>
public void Perform()
{
var playlists = _libraryManager.GetItemList(new InternalItemsQuery
{
IncludeItemTypes = new[] { BaseItemKind.Playlist }
})
.Cast<Playlist>()
.Where(x => x.OwnerUserId.Equals(Guid.Empty))
.ToArray();
if (playlists.Length > 0)
{
foreach (var playlist in playlists)
{
var shares = playlist.Shares;
var firstEditShare = shares.First(x => x.CanEdit);
if (firstEditShare is not null && Guid.TryParse(firstEditShare.UserId, out var guid))
{
playlist.OwnerUserId = guid;
playlist.Shares = shares.Where(x => x != firstEditShare).ToArray();
_playlistManager.UpdatePlaylist(playlist).GetAwaiter().GetResult();
}
}
}
}
}

View File

@ -64,5 +64,12 @@ namespace MediaBrowser.Controller.Playlists
/// <param name="userId">The user id.</param>
/// <returns>Task.</returns>
Task RemovePlaylists(Guid userId);
/// <summary>
/// Updates a playlist.
/// </summary>
/// <param name="playlist">The updated playlist.</param>
/// <returns>Task.</returns>
Task UpdatePlaylist(Playlist playlist);
}
}