Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Umbraco.Cms.Core.Models;

namespace Umbraco.Cms.Core.Notifications;

/// <summary>
/// A notification that is used to trigger the IContentService when the SavedBlueprint method is called in the API.
/// </summary>
Expand All @@ -14,8 +15,21 @@ public ContentSavedBlueprintNotification(IContent target, EventMessages messages
: base(target, messages)
{
}

public ContentSavedBlueprintNotification(IContent target, IContent? createdFromContent, EventMessages messages)
: base(target, messages)
{
CreatedFromContent = createdFromContent;
}

/// <summary>
/// Getting the saved blueprint <see cref="IContent"/> object.
/// </summary>
public IContent SavedBlueprint => Target;

/// <summary>
/// Getting the saved blueprint <see cref="IContent"/> object.
/// </summary>
public IContent? CreatedFromContent { get; }

}
6 changes: 3 additions & 3 deletions src/Umbraco.Core/Services/ContentBlueprintEditingService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Logging;

Check notice on line 1 in src/Umbraco.Core/Services/ContentBlueprintEditingService.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Primitive Obsession

The ratio of primitive types in function arguments decreases from 55.77% to 54.72%, threshold = 30.0%. The functions in this file have too many primitive types (e.g. int, double, float) in their function argument lists. Using many primitive types lead to the code smell Primitive Obsession. Avoid adding more primitive arguments.
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Events;
Expand Down Expand Up @@ -122,7 +122,7 @@
}

// Save blueprint
await SaveAsync(blueprint, userKey);
await SaveAsync(blueprint, userKey, content);

return Attempt.SucceedWithStatus(ContentEditingOperationStatus.Success, new ContentCreateResult { Content = blueprint });
}
Expand Down Expand Up @@ -240,10 +240,10 @@

protected override OperationResult? Delete(IContent content, int userId) => throw new NotImplementedException();

private async Task SaveAsync(IContent blueprint, Guid userKey)
private async Task SaveAsync(IContent blueprint, Guid userKey, IContent? createdFromContent = null)
{
var currentUserId = await GetUserIdAsync(userKey);
ContentService.SaveBlueprint(blueprint, currentUserId);
ContentService.SaveBlueprint(blueprint, createdFromContent, currentUserId);
}

private bool ValidateUniqueName(string name, IContent content)
Expand Down
5 changes: 4 additions & 1 deletion src/Umbraco.Core/Services/ContentService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics.CodeAnalysis;

Check notice on line 1 in src/Umbraco.Core/Services/ContentService.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 4.10 to 4.07, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.

Check notice on line 1 in src/Umbraco.Core/Services/ContentService.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Primitive Obsession

The ratio of primitive types in function arguments decreases from 46.71% to 46.58%, threshold = 30.0%. The functions in this file have too many primitive types (e.g. int, double, float) in their function argument lists. Using many primitive types lead to the code smell Primitive Obsession. Avoid adding more primitive arguments.
using System.Runtime.InteropServices;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -3611,6 +3611,9 @@
}

public void SaveBlueprint(IContent content, int userId = Constants.Security.SuperUserId)
=> SaveBlueprint(content, null, userId);

public void SaveBlueprint(IContent content, IContent? createdFromContent, int userId = Constants.Security.SuperUserId)
{
EventMessages evtMsgs = EventMessagesFactory.Get();

Expand All @@ -3631,7 +3634,7 @@

Audit(AuditType.Save, userId, content.Id, $"Saved content template: {content.Name}");

scope.Notifications.Publish(new ContentSavedBlueprintNotification(content, evtMsgs));
scope.Notifications.Publish(new ContentSavedBlueprintNotification(content, createdFromContent, evtMsgs));
scope.Notifications.Publish(new ContentTreeChangeNotification(content, TreeChangeTypes.RefreshNode, evtMsgs));

scope.Complete();
Expand Down
9 changes: 9 additions & 0 deletions src/Umbraco.Core/Services/IContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,17 @@ public interface IContentService : IContentServiceBase<IContent>
/// <summary>
/// Saves a blueprint.
/// </summary>
[Obsolete("Please use the method taking all parameters. Scheduled for removal in Umbraco 18.")]
void SaveBlueprint(IContent content, int userId = Constants.Security.SuperUserId);

/// <summary>
/// Saves a blueprint.
/// </summary>
void SaveBlueprint(IContent content, IContent? createdFromContent, int userId = Constants.Security.SuperUserId)
#pragma warning disable CS0618 // Type or member is obsolete
=> SaveBlueprint(content, userId);
#pragma warning restore CS0618 // Type or member is obsolete

/// <summary>
/// Deletes a blueprint.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,14 @@
.AddNotificationHandler<ContentSavingNotification, RichTextPropertyNotificationHandler>()
.AddNotificationHandler<ContentCopyingNotification, RichTextPropertyNotificationHandler>()
.AddNotificationHandler<ContentScaffoldedNotification, RichTextPropertyNotificationHandler>()
.AddNotificationHandler<ContentCopiedNotification, FileUploadContentCopiedNotificationHandler>()
.AddNotificationHandler<ContentCopiedNotification, FileUploadContentCopiedOrScaffoldedNotificationHandler>()
.AddNotificationHandler<ContentScaffoldedNotification, FileUploadContentCopiedOrScaffoldedNotificationHandler>()
.AddNotificationHandler<ContentSavedBlueprintNotification, FileUploadContentCopiedOrScaffoldedNotificationHandler>()
.AddNotificationHandler<ContentDeletedNotification, FileUploadContentDeletedNotificationHandler>()
.AddNotificationHandler<MediaDeletedNotification, FileUploadMediaDeletedNotificationHandler>()
.AddNotificationHandler<ContentDeletedBlueprintNotification, FileUploadContentDeletedNotificationHandler>()
.AddNotificationHandler<MediaDeletedNotification, FileUploadContentDeletedNotificationHandler>()
.AddNotificationHandler<MemberDeletedNotification, FileUploadContentDeletedNotificationHandler>()
.AddNotificationHandler<MediaSavingNotification, FileUploadMediaSavingNotificationHandler>()

Check warning on line 366 in src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Large Method

AddCoreNotifications increases from 93 to 96 lines of code, threshold = 70. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.
.AddNotificationHandler<MemberDeletedNotification, FileUploadMemberDeletedNotificationHandler>()
.AddNotificationHandler<ContentCopiedNotification, ImageCropperPropertyEditor>()
.AddNotificationHandler<ContentDeletedNotification, ImageCropperPropertyEditor>()
.AddNotificationHandler<MediaDeletedNotification, ImageCropperPropertyEditor>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Umbraco.Cms.Core;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Persistence.Repositories;
using Umbraco.Cms.Core.Services;
Expand Down Expand Up @@ -63,7 +63,7 @@ protected override void Migrate()
}

blueprint.ParentId = container.Id;
_contentService.SaveBlueprint(blueprint);
_contentService.SaveBlueprint(blueprint, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,10 @@ public FileUploadPropertyValueEditor(
{
FileUploadValue? editorModelValue = _valueParser.Parse(editorValue.Value);

// no change?
// No change or created from blueprint.
if (editorModelValue?.TemporaryFileId.HasValue is not true && string.IsNullOrEmpty(editorModelValue?.Src) is false)
{
// since current value can be json string, we have to parse value
FileUploadValue? currentModelValue = _valueParser.Parse(currentValue);

return currentModelValue?.Src;
return editorModelValue.Src;
}

// the current editor value (if any) is the path to the file
Expand Down
Loading