From 66c11231b209ade94831bc200f840b38aaba3160 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Mon, 23 Feb 2026 20:25:55 +0100 Subject: [PATCH] Fix promotion logic --- MediaBrowser.Controller/Entities/Folder.cs | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index ecf99accb6..e6c94d3cbe 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -486,6 +486,9 @@ namespace MediaBrowser.Controller.Entities var itemsRemoved = currentChildren.Values.Except(validChildren).ToList(); var shouldRemove = !IsRoot || allowRemoveRoot; // If it's an AggregateFolder, don't remove + // Collect old primaries that need demotion to alternates of newly created primaries + var oldPrimariesToDemote = new List<(Video OldPrimary, Video NewPrimary)>(); + if (shouldRemove && itemsRemoved.Count > 0) { // Build a set of paths that are alternate versions of valid children @@ -517,6 +520,19 @@ namespace MediaBrowser.Controller.Entities // Check if path is in LocalAlternateVersions of any valid child if (!string.IsNullOrEmpty(item.Path) && alternateVersionPaths.Contains(item.Path)) { + // If this was a primary (no PrimaryVersionId, no OwnerId), it needs demotion + if (video.OwnerId.IsEmpty()) + { + var newPrimary = newItems + .OfType