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

V14: ContentBlueprintEditingService cleanup #16018

Merged
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
81 changes: 38 additions & 43 deletions src/Umbraco.Core/Services/ContentBlueprintEditingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

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<IContent, IContentType, IContentService, IContentTypeService>, IContentBlueprintEditingService
{
Expand All @@ -33,7 +31,6 @@ public ContentBlueprintEditingService(
return await Task.FromResult(blueprint);
}

// NB: Some of the implementation is copied from <see cref="IContentEditingService.CreateAsync()" />
public async Task<Attempt<ContentCreateResult, ContentEditingOperationStatus>> CreateAsync(ContentBlueprintCreateModel createModel, Guid userKey)
{
if (await ValidateCulturesAsync(createModel) is false)
Expand All @@ -60,7 +57,6 @@ public async Task<Attempt<ContentCreateResult, ContentEditingOperationStatus>> C
return Attempt.SucceedWithStatus(ContentEditingOperationStatus.Success, new ContentCreateResult { Content = blueprint, ValidationResult = result.Result.ValidationResult });
}

// NB: Some of the implementation is copied from <see cref="IContentEditingService.CreateAsync()" />
public async Task<Attempt<ContentCreateResult, ContentEditingOperationStatus>> CreateFromContentAsync(Guid contentKey, string name, Guid? key, Guid userKey)
{
IContent? content = ContentService.GetById(contentKey);
Expand Down Expand Up @@ -89,7 +85,6 @@ public async Task<Attempt<ContentCreateResult, ContentEditingOperationStatus>> C
return Attempt.SucceedWithStatus(ContentEditingOperationStatus.Success, new ContentCreateResult { Content = blueprint });
}

// NB: Some of the implementation is copied from <see cref="IContentEditingService.UpdateAsync()" />
public async Task<Attempt<ContentUpdateResult, ContentEditingOperationStatus>> UpdateAsync(Guid key, ContentBlueprintUpdateModel updateModel, Guid userKey)
{
IContent? blueprint = await GetAsync(key);
Expand Down Expand Up @@ -137,6 +132,44 @@ public async Task<Attempt<ContentUpdateResult, ContentEditingOperationStatus>> U
return Attempt.SucceedWithStatus<IContent?, ContentEditingOperationStatus>(ContentEditingOperationStatus.Success, blueprint);
}

public async Task<Attempt<ContentEditingOperationStatus>> 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);

Expand Down Expand Up @@ -176,42 +209,4 @@ private bool ValidateUniqueName(string name, IContent content)
IEnumerable<IContent> existing = ContentService.GetBlueprintsForContentTypes(content.ContentTypeId);
return existing.Any(c => c.Name == name && c.Id != content.Id) is false;
}

public async Task<Attempt<ContentEditingOperationStatus>> 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);
}
}
1 change: 0 additions & 1 deletion src/Umbraco.Core/Services/IContentEditingService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading