Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix copy content with descendants not copying sort order (#13464) #13644

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Umbraco.Core/Constants-SqlTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static class VersionableRepository
public const string GetVersion = "Umbraco.Core.VersionableRepository.GetVersion";
public const string GetVersions = "Umbraco.Core.VersionableRepository.GetVersions";
public const string EnsureUniqueNodeName = "Umbraco.Core.VersionableRepository.EnsureUniqueNodeName";
public const string SortOrderExists = "Umbraco.Core.VersionableRepository.SortOrderExists";
public const string GetSortOrder = "Umbraco.Core.VersionableRepository.GetSortOrder";
public const string GetParentNode = "Umbraco.Core.VersionableRepository.GetParentNode";
public const string GetReservedId = "Umbraco.Core.VersionableRepository.GetReservedId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,21 @@ public TempContent(int id, int versionId, int publishedVersionId, IContentTypeCo
return SimilarNodeName.GetUniqueName(names, id, nodeName);
}

protected virtual bool SortorderExists(int parentId, int sortOrder)
{
SqlTemplate? template = SqlContext.Templates.Get(Constants.SqlTemplates.VersionableRepository.SortOrderExists, tsql => tsql
.Select("sortOrder")
.From<NodeDto>()
.Where<NodeDto>(x => x.NodeObjectType == SqlTemplate.Arg<Guid>("nodeObjectType") &&
x.ParentId == SqlTemplate.Arg<int>("parentId") &&
x.SortOrder == SqlTemplate.Arg<int>("sortOrder")));

Sql<ISqlContext> sql = template.Sql(NodeObjectTypeId, parentId, sortOrder);
var result = Database.ExecuteScalar<int?>(sql);

return result != null;
}

protected virtual int GetNewChildSortOrder(int parentId, int first)
{
SqlTemplate? template = SqlContext.Templates.Get(Constants.SqlTemplates.VersionableRepository.GetSortOrder, tsql => tsql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,9 @@ protected override void PersistNewItem(IContent entity)
NodeDto parent = GetParentNodeDto(entity.ParentId);
var level = parent.Level + 1;

// get sort order
var sortOrder = GetNewChildSortOrder(entity.ParentId, 0);
var sortOrderExists = SortorderExists(entity.ParentId, entity.SortOrder);
// if the sortorder of the entity already exists get a new one, else use the sortOrder of the entity
var sortOrder = sortOrderExists ? GetNewChildSortOrder(entity.ParentId, 0) : entity.SortOrder;

// persist the node dto
NodeDto nodeDto = dto.ContentDto.NodeDto;
Expand Down