Reroute on version removal

This commit is contained in:
Shadowghost
2026-01-30 21:58:24 +01:00
parent a650148dfd
commit 694db80d4c
5 changed files with 83 additions and 0 deletions

View File

@@ -428,6 +428,9 @@ namespace Emby.Server.Implementations.Library
newPrimary.SetPrimaryVersionId(null);
newPrimary.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).GetAwaiter().GetResult();
// Re-route playlist/collection references from deleted primary to new primary
_itemRepository.RerouteLinkedChildren(video.Id, newPrimary.Id);
// Update remaining alternates to point to new primary
foreach (var alternate in alternateVersions.Skip(1))
{
@@ -436,6 +439,12 @@ namespace Emby.Server.Implementations.Library
}
}
}
else if (item is Video alternateVideo && !string.IsNullOrEmpty(alternateVideo.PrimaryVersionId)
&& Guid.TryParse(alternateVideo.PrimaryVersionId, out var primaryId))
{
// If deleting an alternate version, re-route references to its primary
_itemRepository.RerouteLinkedChildren(alternateVideo.Id, primaryId);
}
var children = item.IsFolder
? ((Folder)item).GetRecursiveChildren(false)
@@ -3480,5 +3489,11 @@ namespace Emby.Server.Implementations.Library
_fileSystem.CreateShortcut(lnk, _appHost.ReverseVirtualPath(path));
RemoveContentTypeOverrides(path);
}
/// <inheritdoc />
public int RerouteLinkedChildReferences(Guid fromChildId, Guid toChildId)
{
return _itemRepository.RerouteLinkedChildren(fromChildId, toChildId);
}
}
}