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

@@ -3843,4 +3843,43 @@ public sealed class BaseItemRepository
return result;
}
/// <inheritdoc/>
public IReadOnlyList<Guid> GetManualLinkedParentIds(Guid childId)
{
using var context = _dbProvider.CreateDbContext();
return context.LinkedChildren
.Where(lc => lc.ChildId == childId && lc.ChildType == DbLinkedChildType.Manual)
.Select(lc => lc.ParentId)
.Distinct()
.ToList();
}
/// <inheritdoc/>
public int RerouteLinkedChildren(Guid fromChildId, Guid toChildId)
{
using var context = _dbProvider.CreateDbContext();
// Get parents that already reference toChildId (to avoid duplicates)
var parentsWithTarget = context.LinkedChildren
.Where(lc => lc.ChildId == toChildId && lc.ChildType == DbLinkedChildType.Manual)
.Select(lc => lc.ParentId)
.ToHashSet();
// Update references that won't create duplicates
var updated = context.LinkedChildren
.Where(lc => lc.ChildId == fromChildId
&& lc.ChildType == DbLinkedChildType.Manual
&& !parentsWithTarget.Contains(lc.ParentId))
.ExecuteUpdate(s => s.SetProperty(e => e.ChildId, toChildId));
// Remove references that would be duplicates
context.LinkedChildren
.Where(lc => lc.ChildId == fromChildId
&& lc.ChildType == DbLinkedChildType.Manual
&& parentsWithTarget.Contains(lc.ParentId))
.ExecuteDelete();
return updated;
}
}