Skip to content

Commit 6705de0

Browse files
authored
sort the children of a parent content after either deleting or moving its child content (#17315)
1 parent ece5a3a commit 6705de0

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/Umbraco.Core/Services/ContentService.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,6 +2406,8 @@ public OperationResult MoveToRecycleBin(IContent content, int userId = Constants
24062406

24072407
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
24082408
{
2409+
var parentId = content.ParentId;
2410+
24092411
scope.WriteLock(Constants.Locks.ContentTree);
24102412

24112413
var originalPath = content.Path;
@@ -2438,6 +2440,14 @@ public OperationResult MoveToRecycleBin(IContent content, int userId = Constants
24382440
movingToRecycleBinNotification));
24392441
Audit(AuditType.Move, userId, content.Id, "Moved to recycle bin");
24402442

2443+
// sort the children of the parent after deleting the content
2444+
IQuery<IContent> childQuery = Query<IContent>().Where(x => x.ParentId == parentId && x.Id != content.Id);
2445+
IEnumerable<IContent> children = _documentRepository.Get(childQuery);
2446+
if(children.Any())
2447+
{
2448+
Sort(children, userId);
2449+
}
2450+
24412451
scope.Complete();
24422452
}
24432453

@@ -2459,6 +2469,8 @@ public OperationResult Move(IContent content, int parentId, int userId = Constan
24592469
{
24602470
EventMessages eventMessages = EventMessagesFactory.Get();
24612471

2472+
var parentIdBeforeMove = content.ParentId;
2473+
24622474
if (content.ParentId == parentId)
24632475
{
24642476
return OperationResult.Succeed(eventMessages);
@@ -2523,6 +2535,14 @@ public OperationResult Move(IContent content, int parentId, int userId = Constan
25232535

25242536
Audit(AuditType.Move, userId, content.Id);
25252537

2538+
// sort the children of the old parent after moving the content
2539+
IQuery<IContent> childQuery = Query<IContent>().Where(x => x.ParentId == parentIdBeforeMove && x.Id != content.Id);
2540+
IEnumerable<IContent> children = _documentRepository.Get(childQuery);
2541+
if (children.Any())
2542+
{
2543+
Sort(children, userId);
2544+
}
2545+
25262546
scope.Complete();
25272547
return OperationResult.Succeed(eventMessages);
25282548
}

0 commit comments

Comments
 (0)