Skip to content

Commit

Permalink
Merge branch 'v15/dev' into v15/dotnet-package-bellisima
Browse files Browse the repository at this point in the history
  • Loading branch information
warrenbuckley authored Oct 28, 2024
2 parents 30b86d8 + e92a1b7 commit f076ab3
Show file tree
Hide file tree
Showing 61 changed files with 1,658 additions and 666 deletions.
1 change: 1 addition & 0 deletions build/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ stages:
jobs:
# Integration Tests (SQLite)
- job:
timeoutInMinutes: 180
displayName: Integration Tests (SQLite)
strategy:
matrix:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,45 @@ namespace Umbraco.Cms.Persistence.EFCore.Scoping;

public class AmbientEFCoreScopeStack<TDbContext> : IAmbientEFCoreScopeStack<TDbContext> where TDbContext : DbContext
{

private static Lock _lock = new();
private static AsyncLocal<ConcurrentStack<IEfCoreScope<TDbContext>>> _stack = new();

public IEfCoreScope<TDbContext>? AmbientScope
{
get
{
if (_stack.Value?.TryPeek(out IEfCoreScope<TDbContext>? ambientScope) ?? false)
lock (_lock)
{
return ambientScope;
}
if (_stack.Value?.TryPeek(out IEfCoreScope<TDbContext>? ambientScope) ?? false)
{
return ambientScope;
}

return null;
return null;
}
}
}

public IEfCoreScope<TDbContext> Pop()
{
if (_stack.Value?.TryPop(out IEfCoreScope<TDbContext>? ambientScope) ?? false)
lock (_lock)
{
return ambientScope;
}
if (_stack.Value?.TryPop(out IEfCoreScope<TDbContext>? ambientScope) ?? false)
{
return ambientScope;
}

throw new InvalidOperationException("No AmbientScope was found.");
throw new InvalidOperationException("No AmbientScope was found.");
}
}

public void Push(IEfCoreScope<TDbContext> scope)
{
_stack.Value ??= new ConcurrentStack<IEfCoreScope<TDbContext>>();
lock (_lock)
{
_stack.Value ??= new ConcurrentStack<IEfCoreScope<TDbContext>>();

_stack.Value.Push(scope);
_stack.Value.Push(scope);
}
}
}
3 changes: 2 additions & 1 deletion src/Umbraco.Cms.StaticAssets/Umbraco.Cms.StaticAssets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<Description>Contains the static assets needed to run Umbraco CMS.</Description>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<StaticWebAssetBasePath>/</StaticWebAssetBasePath>
<CompressionEnabled>false</CompressionEnabled> <!-- Disable compression. E.g. for umbraco backoffice files. These files should be precompressed by node and not let dotnet handle it -->
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -76,4 +77,4 @@
</ItemGroup>
<RemoveDir Directories="@(LoginDirectories)" />
</Target>
</Project>
</Project>
2 changes: 1 addition & 1 deletion src/Umbraco.Core/Constants-Composing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class Composing
{
public static readonly string[] UmbracoCoreAssemblyNames =
{
"Umbraco.Core", "Umbraco.Infrastructure", "Umbraco.PublishedCache.NuCache", "Umbraco.Examine.Lucene",
"Umbraco.Core", "Umbraco.Infrastructure", "Umbraco.Examine.Lucene",
"Umbraco.Web.Common", "Umbraco.Cms.Api.Common","Umbraco.Cms.Api.Delivery","Umbraco.Cms.Api.Management", "Umbraco.Web.Website",
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ private void AddCoreServices()

// Routing
Services.AddUnique<IDocumentUrlService, DocumentUrlService>();
Services.AddHostedService<DocumentUrlServiceInitializer>();
Services.AddNotificationAsyncHandler<UmbracoApplicationStartingNotification, DocumentUrlServiceInitializerNotificationHandler>();

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Umbraco.Cms.Core.Notifications;

public class PostRuntimePremigrationsUpgradeNotification : INotification
{

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Umbraco.Cms.Core.Models;
using Umbraco.Extensions;

namespace Umbraco.Cms.Core.PropertyEditors;

Expand All @@ -9,11 +8,15 @@ namespace Umbraco.Cms.Core.PropertyEditors;
/// </summary>
public class DefaultPropertyIndexValueFactory : IPropertyIndexValueFactory
{
public IEnumerable<KeyValuePair<string, IEnumerable<object?>>> GetIndexValues(IProperty property, string? culture, string? segment, bool published,
public IEnumerable<IndexValue> GetIndexValues(IProperty property, string? culture, string? segment, bool published,
IEnumerable<string> availableCultures, IDictionary<Guid, IContentType> contentTypeDictionary)
{
yield return new KeyValuePair<string, IEnumerable<object?>>(
property.Alias,
property.GetValue(culture, segment, published).Yield());
}
=>
[
new IndexValue
{
Culture = culture,
FieldName = property.Alias,
Values = [property.GetValue(culture, segment, published)]
}
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ public interface IPropertyIndexValueFactory
/// </summary>
/// <remarks>
/// <para>
/// Returns key-value pairs, where keys are indexed field names. By default, that would be the property alias,
/// and there would be only one pair, but some implementations (see for instance the grid one) may return more than
/// one pair, with different indexed field names.
/// Returns index values for a given property. By default, a property uses its alias as index field name,
/// and there would be only one index value, but some implementations (see for instance the grid one) may return more than
/// one value, with different indexed field names.
/// </para>
/// <para>
/// And then, values are an enumerable of objects, because each indexed field can in turn have multiple
/// values. By default, there would be only one object: the property value. But some implementations may return
/// more than one value for a given field.
/// </para>
/// </remarks>
IEnumerable<KeyValuePair<string, IEnumerable<object?>>> GetIndexValues(
IEnumerable<IndexValue> GetIndexValues(
IProperty property,
string? culture,
string? segment,
Expand Down
10 changes: 10 additions & 0 deletions src/Umbraco.Core/PropertyEditors/IndexValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Umbraco.Cms.Core.PropertyEditors;

public sealed class IndexValue
{
public required string? Culture { get; set; }

public required string FieldName { get; set; }

public required IEnumerable<object?> Values { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ protected JsonPropertyIndexValueFactoryBase(IJsonSerializer jsonSerializer, IOpt
indexingSettings.OnChange(newValue => _indexingSettings = newValue);
}

public virtual IEnumerable<KeyValuePair<string, IEnumerable<object?>>> GetIndexValues(
public virtual IEnumerable<IndexValue> GetIndexValues(
IProperty property,
string? culture,
string? segment,
bool published,
IEnumerable<string> availableCultures,
IDictionary<Guid, IContentType> contentTypeDictionary)
{
var result = new List<KeyValuePair<string, IEnumerable<object?>>>();
var result = new List<IndexValue>();

var propertyValue = property.GetValue(culture, segment, published);

Expand Down Expand Up @@ -65,7 +65,7 @@ protected JsonPropertyIndexValueFactoryBase(IJsonSerializer jsonSerializer, IOpt
}
}

IEnumerable<KeyValuePair<string, IEnumerable<object?>>> summary = HandleResume(result, property, culture, segment, published);
IEnumerable<IndexValue> summary = HandleResume(result, property, culture, segment, published);
if (_indexingSettings.ExplicitlyIndexEachNestedProperty || ForceExplicitlyIndexEachNestedProperty)
{
result.AddRange(summary);
Expand All @@ -78,17 +78,17 @@ protected JsonPropertyIndexValueFactoryBase(IJsonSerializer jsonSerializer, IOpt
/// <summary>
/// Method to return a list of summary of the content. By default this returns an empty list
/// </summary>
protected virtual IEnumerable<KeyValuePair<string, IEnumerable<object?>>> HandleResume(
List<KeyValuePair<string, IEnumerable<object?>>> result,
protected virtual IEnumerable<IndexValue> HandleResume(
List<IndexValue> result,
IProperty property,
string? culture,
string? segment,
bool published) => Array.Empty<KeyValuePair<string, IEnumerable<object?>>>();
bool published) => Array.Empty<IndexValue>();

/// <summary>
/// Method that handle the deserialized object.
/// </summary>
protected abstract IEnumerable<KeyValuePair<string, IEnumerable<object?>>> Handle(
protected abstract IEnumerable<IndexValue> Handle(
TSerialized deserializedPropertyValue,
IProperty property,
string? culture,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Umbraco.Cms.Core.PropertyEditors;
public class NoopPropertyIndexValueFactory : IPropertyIndexValueFactory
{
/// <inheritdoc />
public IEnumerable<KeyValuePair<string, IEnumerable<object?>>> GetIndexValues(IProperty property, string? culture, string? segment, bool published,
public IEnumerable<IndexValue> GetIndexValues(IProperty property, string? culture, string? segment, bool published,
IEnumerable<string> availableCultures, IDictionary<Guid, IContentType> contentTypeDictionary)
=> Array.Empty<KeyValuePair<string, IEnumerable<object?>>>();
=> [];
}
32 changes: 14 additions & 18 deletions src/Umbraco.Core/PropertyEditors/TagPropertyIndexValueFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,39 @@ public TagPropertyIndexValueFactory(
indexingSettings.OnChange(newValue => _indexingSettings = newValue);
}

[Obsolete("Use the overload with the 'contentTypeDictionary' parameter instead, scheduled for removal in v15")]
protected IEnumerable<KeyValuePair<string, IEnumerable<object?>>> Handle(
string[] deserializedPropertyValue,
IProperty property,
string? culture,
string? segment,
bool published,
IEnumerable<string> availableCultures)
=> Handle(deserializedPropertyValue, property, culture, segment, published, availableCultures, new Dictionary<Guid, IContentType>());

protected override IEnumerable<KeyValuePair<string, IEnumerable<object?>>> Handle(
protected override IEnumerable<IndexValue> Handle(
string[] deserializedPropertyValue,
IProperty property,
string? culture,
string? segment,
bool published,
IEnumerable<string> availableCultures,
IDictionary<Guid, IContentType> contentTypeDictionary)
{
yield return new KeyValuePair<string, IEnumerable<object?>>(property.Alias, deserializedPropertyValue);
}
=>
[
new IndexValue
{
Culture = culture,
FieldName = property.Alias,
Values = deserializedPropertyValue
}
];

public override IEnumerable<KeyValuePair<string, IEnumerable<object?>>> GetIndexValues(
public override IEnumerable<IndexValue> GetIndexValues(
IProperty property,
string? culture,
string? segment,
bool published,
IEnumerable<string> availableCultures,
IDictionary<Guid, IContentType> contentTypeDictionary)
{
IEnumerable<KeyValuePair<string, IEnumerable<object?>>> jsonValues = base.GetIndexValues(property, culture, segment, published, availableCultures, contentTypeDictionary);
IEnumerable<IndexValue> jsonValues = base.GetIndexValues(property, culture, segment, published, availableCultures, contentTypeDictionary);
if (jsonValues?.Any() is true)
{
return jsonValues;
}

var result = new List<KeyValuePair<string, IEnumerable<object?>>>();
var result = new List<IndexValue>();

var propertyValue = property.GetValue(culture, segment, published);

Expand All @@ -67,7 +63,7 @@ public TagPropertyIndexValueFactory(
result.AddRange(Handle(values, property, culture, segment, published, availableCultures, contentTypeDictionary));
}

IEnumerable<KeyValuePair<string, IEnumerable<object?>>> summary = HandleResume(result, property, culture, segment, published);
IEnumerable<IndexValue> summary = HandleResume(result, property, culture, segment, published);
if (_indexingSettings.ExplicitlyIndexEachNestedProperty || ForceExplicitlyIndexEachNestedProperty)
{
result.AddRange(summary);
Expand Down
53 changes: 0 additions & 53 deletions src/Umbraco.Core/Services/DocumentUrlServiceInitializer.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;

namespace Umbraco.Cms.Core.Services;

public class DocumentUrlServiceInitializerNotificationHandler : INotificationAsyncHandler<UmbracoApplicationStartingNotification>
{
private readonly IDocumentUrlService _documentUrlService;
private readonly IRuntimeState _runtimeState;

public DocumentUrlServiceInitializerNotificationHandler(IDocumentUrlService documentUrlService, IRuntimeState runtimeState)
{
_documentUrlService = documentUrlService;
_runtimeState = runtimeState;
}

public async Task HandleAsync(UmbracoApplicationStartingNotification notification, CancellationToken cancellationToken)
{
if (_runtimeState.Level == RuntimeLevel.Upgrade)
{
//Special case on the first upgrade, as the database is not ready yet.
return;
}

await _documentUrlService.InitAsync(
_runtimeState.Level <= RuntimeLevel.Install,
cancellationToken);
}
}
Loading

0 comments on commit f076ab3

Please sign in to comment.