diff --git a/src/Umbraco.Core/Services/ContentBlueprintEditingService.cs b/src/Umbraco.Core/Services/ContentBlueprintEditingService.cs index 22f1234297..7313350668 100644 --- a/src/Umbraco.Core/Services/ContentBlueprintEditingService.cs +++ b/src/Umbraco.Core/Services/ContentBlueprintEditingService.cs @@ -7,8 +7,6 @@ using Umbraco.Cms.Core.Services.OperationStatus; namespace Umbraco.Cms.Core.Services; -// not implementing ContentEditingServiceWithSortingBase - it might be for later as it has Move, Copy, etc. -// FIXME: Refactor IContentEditingService and IContentBlueprintEditingService - they share logic internal sealed class ContentBlueprintEditingService : ContentEditingServiceBase, IContentBlueprintEditingService { @@ -33,7 +31,6 @@ internal sealed class ContentBlueprintEditingService return await Task.FromResult(blueprint); } - // NB: Some of the implementation is copied from public async Task> CreateAsync(ContentBlueprintCreateModel createModel, Guid userKey) { if (await ValidateCulturesAsync(createModel) is false) @@ -60,7 +57,6 @@ internal sealed class ContentBlueprintEditingService return Attempt.SucceedWithStatus(ContentEditingOperationStatus.Success, new ContentCreateResult { Content = blueprint, ValidationResult = result.Result.ValidationResult }); } - // NB: Some of the implementation is copied from public async Task> CreateFromContentAsync(Guid contentKey, string name, Guid? key, Guid userKey) { IContent? content = ContentService.GetById(contentKey); @@ -89,7 +85,6 @@ internal sealed class ContentBlueprintEditingService return Attempt.SucceedWithStatus(ContentEditingOperationStatus.Success, new ContentCreateResult { Content = blueprint }); } - // NB: Some of the implementation is copied from public async Task> UpdateAsync(Guid key, ContentBlueprintUpdateModel updateModel, Guid userKey) { IContent? blueprint = await GetAsync(key); @@ -137,6 +132,44 @@ internal sealed class ContentBlueprintEditingService return Attempt.SucceedWithStatus(ContentEditingOperationStatus.Success, blueprint); } + public async Task> MoveAsync(Guid key, Guid? containerKey, Guid userKey) + { + using ICoreScope scope = CoreScopeProvider.CreateCoreScope(); + IContent? toMove = await GetAsync(key); + if (toMove is null) + { + return Attempt.Fail(ContentEditingOperationStatus.NotFound); + } + + var parentId = Constants.System.Root; + if (containerKey.HasValue && containerKey.Value != Guid.Empty) + { + EntityContainer? container = await _containerService.GetAsync(containerKey.Value); + if (container is null) + { + return Attempt.Fail(ContentEditingOperationStatus.ParentNotFound); + } + + parentId = container.Id; + } + + if (toMove.ParentId == parentId) + { + return Attempt.Succeed(ContentEditingOperationStatus.Success); + } + + // NOTE: as long as the parent ID is correct the document repo takes care of updating the rest of the + // structural node data like path, level, sort orders etc. + toMove.ParentId = parentId; + + // Save blueprint + await SaveAsync(toMove, userKey); + + scope.Complete(); + + return Attempt.Succeed(ContentEditingOperationStatus.Success); + } + protected override IContent New(string? name, int parentId, IContentType contentType) => new Content(name, parentId, contentType); @@ -176,42 +209,4 @@ internal sealed class ContentBlueprintEditingService IEnumerable existing = ContentService.GetBlueprintsForContentTypes(content.ContentTypeId); return existing.Any(c => c.Name == name && c.Id != content.Id) is false; } - - public async Task> MoveAsync(Guid key, Guid? containerKey, Guid userKey) - { - using ICoreScope scope = CoreScopeProvider.CreateCoreScope(); - IContent? toMove = await GetAsync(key); - if (toMove is null) - { - return Attempt.Fail(ContentEditingOperationStatus.NotFound); - } - - var parentId = Constants.System.Root; - if (containerKey.HasValue && containerKey.Value != Guid.Empty) - { - EntityContainer? container = await _containerService.GetAsync(containerKey.Value); - if (container is null) - { - return Attempt.Fail(ContentEditingOperationStatus.ParentNotFound); - } - - parentId = container.Id; - } - - if (toMove.ParentId == parentId) - { - return Attempt.Succeed(ContentEditingOperationStatus.Success); - } - - // NOTE: as long as the parent ID is correct the document repo takes care of updating the rest of the - // structural node data like path, level, sort orders etc. - toMove.ParentId = parentId; - - // Save blueprint - await SaveAsync(toMove, userKey); - - scope.Complete(); - - return Attempt.Succeed(ContentEditingOperationStatus.Success); - } } diff --git a/src/Umbraco.Core/Services/IContentEditingService.cs b/src/Umbraco.Core/Services/IContentEditingService.cs index d1f67730af..dc2fa92890 100644 --- a/src/Umbraco.Core/Services/IContentEditingService.cs +++ b/src/Umbraco.Core/Services/IContentEditingService.cs @@ -1,6 +1,5 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Models.ContentEditing.Validation; using Umbraco.Cms.Core.Services.OperationStatus; namespace Umbraco.Cms.Core.Services;