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
12 changes: 10 additions & 2 deletions src/Umbraco.Core/Services/ContentPublishingService.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/ContentPublishingService.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: Primitive Obsession

The ratio of primitive types in function arguments decreases from 45.10% to 44.23%, 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 All @@ -8,6 +8,7 @@
using Umbraco.Cms.Core.Models.ContentPublishing;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services.OperationStatus;
using Umbraco.Cms.Core.Web;
using Umbraco.Extensions;

namespace Umbraco.Cms.Core.Services;
Expand All @@ -26,6 +27,7 @@
private readonly IRelationService _relationService;
private readonly ILogger<ContentPublishingService> _logger;
private readonly ILongRunningOperationService _longRunningOperationService;
private readonly IUmbracoContextFactory _umbracoContextFactory;

public ContentPublishingService(
ICoreScopeProvider coreScopeProvider,
Expand All @@ -37,7 +39,8 @@
IOptionsMonitor<ContentSettings> optionsMonitor,
IRelationService relationService,
ILogger<ContentPublishingService> logger,
ILongRunningOperationService longRunningOperationService)
ILongRunningOperationService longRunningOperationService,
IUmbracoContextFactory umbracoContextFactory)
{
_coreScopeProvider = coreScopeProvider;
_contentService = contentService;
Expand All @@ -53,6 +56,7 @@
{
_contentSettings = contentSettings;
});
_umbracoContextFactory = umbracoContextFactory;
}

/// <inheritdoc />
Expand Down Expand Up @@ -290,7 +294,7 @@
return MapInternalPublishingAttempt(minimalAttempt);
}

_logger.LogInformation("Starting async background thread for publishing branch.");
_logger.LogDebug("Starting long running operation for publishing branch {Key} on background thread.", key);
Attempt<Guid, LongRunningOperationEnqueueStatus> enqueueAttempt = await _longRunningOperationService.RunAsync(
PublishBranchOperationType,
async _ => await PerformPublishBranchAsync(key, cultures, publishBranchFilter, userKey, returnContent: false),
Expand Down Expand Up @@ -324,6 +328,10 @@
Guid userKey,
bool returnContent)
{
// Ensure we have an UmbracoContext in case running on a background thread so operations that run in the published notification handlers
// have access to this (e.g. webhooks).
using UmbracoContextReference umbracoContextReference = _umbracoContextFactory.EnsureUmbracoContext();

using ICoreScope scope = _coreScopeProvider.CreateCoreScope();
IContent? content = _contentService.GetById(key);
if (content is null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.

using System.Text.Json;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Models.DeliveryApi;
using Umbraco.Cms.Core.Models.PublishedContent;
Expand Down Expand Up @@ -53,10 +54,10 @@ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType
{
value = _jsonSerializer.Deserialize<ImageCropperValue>(sourceString);
}
catch (Exception ex)
catch (JsonException ex)
{
// cannot deserialize, assume it may be a raw image URL
_logger.LogError(ex, "Could not deserialize string '{JsonString}' into an image cropper value.", sourceString);
// Cannot deserialize, assume it may be a raw image URL.
_logger.LogDebug(ex, "Could not deserialize string '{JsonString}' into an image cropper value.", sourceString);
value = new ImageCropperValue { Src = sourceString };
}

Expand Down