Skip to content

Commit

Permalink
Merge branch 'v15/dev' into v15/QA/updated-E2E-pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
andr317c authored Dec 20, 2024
2 parents ce50fbd + a954051 commit 1ea7b03
Show file tree
Hide file tree
Showing 176 changed files with 2,568 additions and 853 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,31 @@ public IEnumerable<IPermissionPresentationModel> MapManyAsync(IEnumerable<IGranu

public IEnumerable<IGranularPermission> MapToGranularPermissions(IPermissionPresentationModel permissionViewModel)
{
if (permissionViewModel is DocumentPermissionPresentationModel documentPermissionPresentationModel)
if (permissionViewModel is not DocumentPermissionPresentationModel documentPermissionPresentationModel)
{
foreach (var verb in documentPermissionPresentationModel.Verbs)
yield break;
}

if(documentPermissionPresentationModel.Verbs.Any() is false || (documentPermissionPresentationModel.Verbs.Count == 1 && documentPermissionPresentationModel.Verbs.Contains(string.Empty)))
{
yield return new DocumentGranularPermission
{
yield return new DocumentGranularPermission
{
Key = documentPermissionPresentationModel.Document.Id,
Permission = verb,
};
Key = documentPermissionPresentationModel.Document.Id,
Permission = string.Empty,
};
yield break;
}
foreach (var verb in documentPermissionPresentationModel.Verbs)
{
if (string.IsNullOrEmpty(verb))
{
continue;
}
yield return new DocumentGranularPermission
{
Key = documentPermissionPresentationModel.Document.Id,
Permission = verb,
};
}
}
}
1 change: 1 addition & 0 deletions src/Umbraco.Core/Routing/ContentFinderByIdPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public Task<bool> TryFindContent(IPublishedRequestBuilder frequest)
}

ResolveAndSetCultureOnRequest(frequest);
ResolveAndSetSegmentOnRequest(frequest);

frequest.SetPublishedContent(node);
if (_logger.IsEnabled(LogLevel.Debug))
Expand Down
12 changes: 12 additions & 0 deletions src/Umbraco.Core/Routing/ContentFinderByIdentifierPathBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ protected void ResolveAndSetCultureOnRequest(IPublishedRequestBuilder frequest)
}
}

protected void ResolveAndSetSegmentOnRequest(IPublishedRequestBuilder frequest)
{
var segmentFromQuerystring = _requestAccessor.GetQueryStringValue("segment");

// Check if we have a segment in the query string
if (!string.IsNullOrEmpty(segmentFromQuerystring))
{
// We're assuming it will match a segment
frequest.SetSegment(segmentFromQuerystring);
}
}

protected Task<bool> LogAndReturnFailure()
{
if (_logger.IsEnabled(LogLevel.Debug))
Expand Down
1 change: 1 addition & 0 deletions src/Umbraco.Core/Routing/ContentFinderByKeyPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public Task<bool> TryFindContent(IPublishedRequestBuilder frequest)
}

ResolveAndSetCultureOnRequest(frequest);
ResolveAndSetSegmentOnRequest(frequest);

frequest.SetPublishedContent(node);
if (_logger.IsEnabled(LogLevel.Debug))
Expand Down
5 changes: 5 additions & 0 deletions src/Umbraco.Core/Routing/IPublishedRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public interface IPublishedRequest
/// </remarks>
string? Culture { get; }

/// <summary>
/// Gets the content request's segment (if any).
/// </summary>
string? Segment => null;

/// <summary>
/// Gets the url to redirect to, when the content request triggers a redirect.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Umbraco.Core/Routing/IPublishedRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public interface IPublishedRequestBuilder
/// </summary>
string? Culture { get; }

/// <summary>
/// Gets the segment assigned (if any)
/// </summary>
string? Segment => null;

/// <summary>
/// Gets a value indicating whether the current published content has been obtained
/// from the initial published content following internal redirections exclusively.
Expand Down Expand Up @@ -72,6 +77,11 @@ public interface IPublishedRequestBuilder
/// </summary>
IPublishedRequestBuilder SetCulture(string? culture);

/// <summary>
/// Sets the segment for the request
/// </summary>
IPublishedRequestBuilder SetSegment(string? segment) => this;

/// <summary>
/// Sets the found <see cref="IPublishedContent" /> for the request
/// </summary>
Expand Down
38 changes: 38 additions & 0 deletions src/Umbraco.Core/Routing/PublishedRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,39 @@ namespace Umbraco.Cms.Core.Routing;

public class PublishedRequest : IPublishedRequest
{
[Obsolete("Please use the constructor that accepts a segment. Will be removed in V16.")]
public PublishedRequest(
Uri uri,
string absolutePathDecoded,
IPublishedContent? publishedContent,
bool isInternalRedirect,
ITemplate? template,
DomainAndUri? domain,
string? culture,
string? redirectUrl,
int? responseStatusCode,
IReadOnlyList<string>? cacheExtensions,
IReadOnlyDictionary<string, string>? headers,
bool setNoCacheHeader,
bool ignorePublishedContentCollisions)
: this(
uri,
absolutePathDecoded,
publishedContent,
isInternalRedirect,
template,
domain,
culture,
segment: null,
redirectUrl,
responseStatusCode,
cacheExtensions,
headers,
setNoCacheHeader,
ignorePublishedContentCollisions)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="PublishedRequest" /> class.
/// </summary>
Expand All @@ -16,6 +49,7 @@ public PublishedRequest(
ITemplate? template,
DomainAndUri? domain,
string? culture,
string? segment,
string? redirectUrl,
int? responseStatusCode,
IReadOnlyList<string>? cacheExtensions,
Expand All @@ -30,6 +64,7 @@ public PublishedRequest(
Template = template;
Domain = domain;
Culture = culture;
Segment = segment;
RedirectUrl = redirectUrl;
ResponseStatusCode = responseStatusCode;
CacheExtensions = cacheExtensions;
Expand Down Expand Up @@ -62,6 +97,9 @@ public PublishedRequest(
/// <inheritdoc />
public string? Culture { get; }

/// <inheritdoc />
public string? Segment { get; }

/// <inheritdoc />
public string? RedirectUrl { get; }

Expand Down
11 changes: 11 additions & 0 deletions src/Umbraco.Core/Routing/PublishedRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public PublishedRequestBuilder(Uri uri, IFileService fileService)
/// <inheritdoc />
public string? Culture { get; private set; }

/// <inheritdoc />
public string? Segment { get; private set; }

/// <inheritdoc />
public ITemplate? Template { get; private set; }

Expand Down Expand Up @@ -69,6 +72,7 @@ private set
Template,
Domain,
Culture,
Segment,
_redirectUrl,
_responseStatus.HasValue ? (int?)_responseStatus : null,
_cacheExtensions,
Expand Down Expand Up @@ -97,6 +101,13 @@ public IPublishedRequestBuilder SetCulture(string? culture)
return this;
}

/// <inheritdoc />
public IPublishedRequestBuilder SetSegment(string? segment)
{
Segment = segment;
return this;
}

/// <inheritdoc />
public IPublishedRequestBuilder SetDomain(DomainAndUri domain)
{
Expand Down
17 changes: 9 additions & 8 deletions src/Umbraco.Core/Routing/PublishedRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public async Task<IPublishedRequest> UpdateRequestAsync(
builder.SetDomain(request.Domain);
}
builder.SetCulture(request.Culture);
builder.SetSegment(request.Segment);

// set to the new content (or null if specified)
builder.SetPublishedContent(publishedContent);
Expand Down Expand Up @@ -181,7 +182,7 @@ internal IPublishedRequest BuildRequest(IPublishedRequestBuilder builder)
}

// set the culture -- again, 'cos it might have changed in the event handler
SetVariationContext(result.Culture);
SetVariationContext(result.Culture, result.Segment);

return result;
}
Expand All @@ -205,15 +206,15 @@ private async Task<IPublishedRequest> TryRouteRequest(IPublishedRequestBuilder r
return request.Build();
}

private void SetVariationContext(string? culture)
private void SetVariationContext(string? culture, string? segment)
{
VariationContext? variationContext = _variationContextAccessor.VariationContext;
if (variationContext != null && variationContext.Culture == culture)
if (variationContext != null && variationContext.Culture == culture && variationContext.Segment == segment)
{
return;
}

_variationContextAccessor.VariationContext = new VariationContext(culture);
_variationContextAccessor.VariationContext = new VariationContext(culture, segment);
}

private async Task RouteRequestInternalAsync(IPublishedRequestBuilder builder, bool skipContentFinders = false)
Expand All @@ -226,7 +227,7 @@ private async Task RouteRequestInternalAsync(IPublishedRequestBuilder builder, b
}

// set the culture
SetVariationContext(builder.Culture);
SetVariationContext(builder.Culture, builder.Segment);

var foundContentByFinders = false;

Expand Down Expand Up @@ -261,7 +262,7 @@ private async Task RouteRequestInternalAsync(IPublishedRequestBuilder builder, b
HandleWildcardDomains(builder);

// set the culture -- again, 'cos it might have changed due to a finder or wildcard domain
SetVariationContext(builder.Culture);
SetVariationContext(builder.Culture, builder.Segment);
}

// trigger the routing request (used to be called Prepared) event - at that point it is still possible to change about anything
Expand All @@ -278,15 +279,15 @@ public bool RouteDomain(IPublishedRequestBuilder request)
{
var found = FindAndSetDomain(request);
HandleWildcardDomains(request);
SetVariationContext(request.Culture);
SetVariationContext(request.Culture, request.Segment);
return found;
}

/// <inheritdoc />
public bool UpdateVariationContext(Uri uri)
{
DomainAndUri? domain = FindDomain(uri, out _);
SetVariationContext(domain?.Culture);
SetVariationContext(domain?.Culture, null);
return domain?.Culture is not null;
}

Expand Down
32 changes: 31 additions & 1 deletion src/Umbraco.Infrastructure/Migrations/MigrationPlanExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class MigrationPlanExecutor : IMigrationPlanExecutor
private readonly IDatabaseCacheRebuilder _databaseCacheRebuilder;
private readonly IKeyValueService _keyValueService;
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly AppCaches _appCaches;
private readonly DistributedCache _distributedCache;
private readonly IScopeAccessor _scopeAccessor;
private readonly ICoreScopeProvider _scopeProvider;
Expand All @@ -62,7 +63,8 @@ public MigrationPlanExecutor(
IDatabaseCacheRebuilder databaseCacheRebuilder,
DistributedCache distributedCache,
IKeyValueService keyValueService,
IServiceScopeFactory serviceScopeFactory)
IServiceScopeFactory serviceScopeFactory,
AppCaches appCaches)
{
_scopeProvider = scopeProvider;
_scopeAccessor = scopeAccessor;
Expand All @@ -72,10 +74,36 @@ public MigrationPlanExecutor(
_databaseCacheRebuilder = databaseCacheRebuilder;
_keyValueService = keyValueService;
_serviceScopeFactory = serviceScopeFactory;
_appCaches = appCaches;
_distributedCache = distributedCache;
_logger = _loggerFactory.CreateLogger<MigrationPlanExecutor>();
}

[Obsolete("Use the non obsoleted constructor instead. Scheduled for removal in v17")]
public MigrationPlanExecutor(
ICoreScopeProvider scopeProvider,
IScopeAccessor scopeAccessor,
ILoggerFactory loggerFactory,
IMigrationBuilder migrationBuilder,
IUmbracoDatabaseFactory databaseFactory,
IDatabaseCacheRebuilder databaseCacheRebuilder,
DistributedCache distributedCache,
IKeyValueService keyValueService,
IServiceScopeFactory serviceScopeFactory)
: this(
scopeProvider,
scopeAccessor,
loggerFactory,
migrationBuilder,
databaseFactory,
databaseCacheRebuilder,
distributedCache,
keyValueService,
serviceScopeFactory,
StaticServiceProvider.Instance.GetRequiredService<AppCaches>())
{
}

public string Execute(MigrationPlan plan, string fromState) => ExecutePlan(plan, fromState).FinalState;

/// <summary>
Expand Down Expand Up @@ -303,6 +331,8 @@ private void RunMigration(Type migrationType, MigrationContext context)

private void RebuildCache()
{
_appCaches.RuntimeCache.Clear();
_appCaches.IsolatedCaches.ClearAllCaches();
_databaseCacheRebuilder.Rebuild();
_distributedCache.RefreshAllPublishedSnapshot();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,6 @@ protected virtual void DefinePlan()
To<V_15_0_0.ConvertRichTextEditorProperties>("{37875E80-5CDD-42FF-A21A-7D4E3E23E0ED}");
To<V_15_0_0.ConvertLocalLinks>("{42E44F9E-7262-4269-922D-7310CB48E724}");
To<V_15_1_0.RebuildCacheMigration>("{7B51B4DE-5574-4484-993E-05D12D9ED703}");
To<V_15_1_0.FixConvertLocalLinks>("{F3D3EF46-1B1F-47DB-B437-7D573EEDEB98}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public abstract class ConvertBlockEditorPropertiesBase : MigrationBase

protected bool SkipMigration { get; init; }

protected bool ParallelizeMigration { get; init; }

protected enum EditorValueHandling
{
IgnoreConversion,
Expand Down Expand Up @@ -258,7 +260,7 @@ void HandleUpdateBatch(UpdateBatch<PropertyDataDto> update)
propertyDataDto.TextValue = stringValue;
}

if (DatabaseType == DatabaseType.SQLite)
if (ParallelizeMigration is false || DatabaseType == DatabaseType.SQLite)
{
// SQLite locks up if we run the migration in parallel, so... let's not.
foreach (UpdateBatch<PropertyDataDto> update in updateBatch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ public class ConvertBlockEditorPropertiesOptions
/// If you choose to skip the migration, you're responsible for performing the content migration for Rich Texts after the V15 upgrade has completed.
/// </remarks>
public bool SkipRichTextEditors { get; set; } = false;

/// <summary>
/// Setting this property to true will cause all block editor migrations to run as parallel operations.
/// </summary>
/// <remarks>
/// While this greatly improves the speed of the migration, some content setups may experience issues and failing migrations as a result.
/// </remarks>
public bool ParallelizeMigration { get; set; } = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public ConvertBlockGridEditorProperties(
IOptions<ConvertBlockEditorPropertiesOptions> options,
ICoreScopeProvider coreScopeProvider)
: base(context, logger, contentTypeService, dataTypeService, jsonSerializer, umbracoContextFactory, languageService, coreScopeProvider)
=> SkipMigration = options.Value.SkipBlockGridEditors;
{
SkipMigration = options.Value.SkipBlockGridEditors;
ParallelizeMigration = options.Value.ParallelizeMigration;
}

protected override IEnumerable<string> PropertyEditorAliases
=> new[] { Constants.PropertyEditors.Aliases.BlockGrid };
Expand Down
Loading

0 comments on commit 1ea7b03

Please sign in to comment.