sort the children of a parent content after either deleting or moving its child content (#17315)

This commit is contained in:
Nathaniel Nunes
2024-11-07 21:11:30 +05:30
committed by GitHub
parent ece5a3ae26
commit 6705de0329

View File

@@ -2406,6 +2406,8 @@ public class ContentService : RepositoryService, IContentService
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
{
var parentId = content.ParentId;
scope.WriteLock(Constants.Locks.ContentTree);
var originalPath = content.Path;
@@ -2438,6 +2440,14 @@ public class ContentService : RepositoryService, IContentService
movingToRecycleBinNotification));
Audit(AuditType.Move, userId, content.Id, "Moved to recycle bin");
// sort the children of the parent after deleting the content
IQuery<IContent> childQuery = Query<IContent>().Where(x => x.ParentId == parentId && x.Id != content.Id);
IEnumerable<IContent> children = _documentRepository.Get(childQuery);
if(children.Any())
{
Sort(children, userId);
}
scope.Complete();
}
@@ -2459,6 +2469,8 @@ public class ContentService : RepositoryService, IContentService
{
EventMessages eventMessages = EventMessagesFactory.Get();
var parentIdBeforeMove = content.ParentId;
if (content.ParentId == parentId)
{
return OperationResult.Succeed(eventMessages);
@@ -2523,6 +2535,14 @@ public class ContentService : RepositoryService, IContentService
Audit(AuditType.Move, userId, content.Id);
// sort the children of the old parent after moving the content
IQuery<IContent> childQuery = Query<IContent>().Where(x => x.ParentId == parentIdBeforeMove && x.Id != content.Id);
IEnumerable<IContent> children = _documentRepository.Get(childQuery);
if (children.Any())
{
Sort(children, userId);
}
scope.Complete();
return OperationResult.Succeed(eventMessages);
}