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
7 changes: 7 additions & 0 deletions src/Umbraco.Core/Models/Blocks/RichTextBlockValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ public RichTextBlockValue(IEnumerable<RichTextBlockLayoutItem> layouts)
/// <inheritdoc />
[JsonIgnore]
public override string PropertyEditorAlias => Constants.PropertyEditors.Aliases.RichText;

/// <inheritdoc />
#pragma warning disable CS0672 // Member overrides obsolete member
#pragma warning disable CS0618 // Type or member is obsolete
public override bool SupportsBlockLayoutAlias(string alias) => base.SupportsBlockLayoutAlias(alias) || alias.Equals("Umbraco.TinyMCE");
#pragma warning restore CS0618 // Type or member is obsolete
#pragma warning restore CS0672 // Member overrides obsolete member
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ IPublishedPropertyType CreateCorePropertyType(
/// </summary>
PublishedDataType GetDataType(int id);

/// <summary>
/// Clears the internal data type cache.
/// </summary>
void ClearDataTypeCache()
{ }

/// <summary>
/// Notifies the factory of datatype changes.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ public PublishedDataType GetDataType(int id)
return dataType;
}

/// <inheritdoc />
public void ClearDataTypeCache()
{
if (_publishedDataTypes is null)
{
// Not initialized yet, so skip and avoid lock
return;
}

lock (_publishedDataTypesLocker)
{
// Clear cache (and let it lazy initialize again later)
_publishedDataTypes = null;
}
}

/// <inheritdoc />
public void NotifyDataTypeChanges(params int[] ids)
{
Expand Down
34 changes: 34 additions & 0 deletions src/Umbraco.Infrastructure/Migrations/MigrationPlanExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using OpenIddict.Abstractions;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Migrations;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services;
Expand Down Expand Up @@ -47,9 +49,12 @@ public class MigrationPlanExecutor : IMigrationPlanExecutor
private readonly DistributedCache _distributedCache;
private readonly IScopeAccessor _scopeAccessor;
private readonly ICoreScopeProvider _scopeProvider;
private readonly IPublishedContentTypeFactory _publishedContentTypeFactory;

private bool _rebuildCache;
private bool _invalidateBackofficeUserAccess;

[Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 19.")]
public MigrationPlanExecutor(
ICoreScopeProvider scopeProvider,
IScopeAccessor scopeAccessor,
Expand All @@ -61,6 +66,33 @@ public MigrationPlanExecutor(
IKeyValueService keyValueService,
IServiceScopeFactory serviceScopeFactory,
AppCaches appCaches)
: this(
scopeProvider,
scopeAccessor,
loggerFactory,
migrationBuilder,
databaseFactory,
databaseCacheRebuilder,
distributedCache,
keyValueService,
serviceScopeFactory,
appCaches,
StaticServiceProvider.Instance.GetRequiredService<IPublishedContentTypeFactory>())
{
}

public MigrationPlanExecutor(
ICoreScopeProvider scopeProvider,
IScopeAccessor scopeAccessor,
ILoggerFactory loggerFactory,
IMigrationBuilder migrationBuilder,
IUmbracoDatabaseFactory databaseFactory,
IDatabaseCacheRebuilder databaseCacheRebuilder,
DistributedCache distributedCache,
IKeyValueService keyValueService,
IServiceScopeFactory serviceScopeFactory,
AppCaches appCaches,
IPublishedContentTypeFactory publishedContentTypeFactory)
{
_scopeProvider = scopeProvider;
_scopeAccessor = scopeAccessor;
Expand All @@ -72,6 +104,7 @@ public MigrationPlanExecutor(
_serviceScopeFactory = serviceScopeFactory;
_appCaches = appCaches;
_distributedCache = distributedCache;
_publishedContentTypeFactory = publishedContentTypeFactory;
_logger = _loggerFactory.CreateLogger<MigrationPlanExecutor>();
}

Expand Down Expand Up @@ -269,6 +302,7 @@ private async Task RebuildCache()
_appCaches.IsolatedCaches.ClearAllCaches();
await _databaseCacheRebuilder.RebuildAsync(false);
_distributedCache.RefreshAllPublishedSnapshot();
_publishedContentTypeFactory.ClearDataTypeCache();
}

private async Task RevokeBackofficeTokens()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Migrations;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services;
Expand Down Expand Up @@ -38,6 +39,7 @@ internal sealed class AdvancedMigrationTests : UmbracoIntegrationTest
private IServiceScopeFactory ServiceScopeFactory => GetRequiredService<IServiceScopeFactory>();
private DistributedCache DistributedCache => GetRequiredService<DistributedCache>();
private IDatabaseCacheRebuilder DatabaseCacheRebuilder => GetRequiredService<IDatabaseCacheRebuilder>();
private IPublishedContentTypeFactory PublishedContentTypeFactory => GetRequiredService<IPublishedContentTypeFactory>();
private IMigrationPlanExecutor MigrationPlanExecutor => new MigrationPlanExecutor(
CoreScopeProvider,
ScopeAccessor,
Expand All @@ -48,7 +50,8 @@ internal sealed class AdvancedMigrationTests : UmbracoIntegrationTest
DistributedCache,
Mock.Of<IKeyValueService>(),
ServiceScopeFactory,
AppCaches.NoCache);
AppCaches.NoCache,
PublishedContentTypeFactory);

[Test]
public async Task CreateTableOfTDtoAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,76 +110,84 @@
Assert.IsNull(value.Blocks);
}

[Test]
public void Can_Parse_Blocks_With_Both_Content_And_Settings()
[TestCase(Constants.PropertyEditors.Aliases.RichText)]
[TestCase("Umbraco.TinyMCE")]
public void Can_Parse_Blocks_With_Both_Content_And_Settings(string propertyEditorAlias)
{
const string input = """
string input = """
{
"markup": "<p>this is some markup</p><umb-rte-block data-content-key=\"36cc710a-d8a6-45d0-a07f-7bbd8742cf02\"><!--Umbraco-Block--></umb-rte-block>",
"blocks": {
"layout": {
"Umbraco.RichText": [{
"[PropertyEditorAlias]": [{
"contentKey": "36cc710a-d8a6-45d0-a07f-7bbd8742cf02",
"settingsKey": "d2eeef66-4111-42f4-a164-7a523eaffbc2"
}
]
},
"contentData": [{
"contentTypeKey": "b2f0806c-d231-4c78-88b2-3c97d26e1123",
"key": "36cc710a-d8a6-45d0-a07f-7bbd8742cf02",
"values": [
{ "alias": "contentPropertyAlias", "value": "A content property value" }
]
}
],
"settingsData": [{
"contentTypeKey": "e7a9447f-e14d-44dd-9ae8-e68c3c3da598",
"key": "d2eeef66-4111-42f4-a164-7a523eaffbc2",
"values": [
{ "alias": "settingsPropertyAlias", "value": "A settings property value" }
]
}
]
}
}
""";
input = input.Replace("[PropertyEditorAlias]", propertyEditorAlias);

var result = RichTextPropertyEditorHelper.TryParseRichTextEditorValue(input, JsonSerializer(), Logger(), out RichTextEditorValue? value);
Assert.IsTrue(result);
Assert.IsNotNull(value);
Assert.AreEqual("<p>this is some markup</p><umb-rte-block data-content-key=\"36cc710a-d8a6-45d0-a07f-7bbd8742cf02\"><!--Umbraco-Block--></umb-rte-block>", value.Markup);

Assert.IsNotNull(value.Blocks);

Assert.AreEqual(1, value.Blocks.ContentData.Count);
var item = value.Blocks.ContentData.Single();
var contentTypeGuid = Guid.Parse("b2f0806c-d231-4c78-88b2-3c97d26e1123");
var itemGuid = Guid.Parse("36cc710a-d8a6-45d0-a07f-7bbd8742cf02");
Assert.AreEqual(contentTypeGuid, item.ContentTypeKey);
Assert.AreEqual(itemGuid, item.Key);
Assert.AreEqual(itemGuid, item.Key);
var contentProperties = value.Blocks.ContentData.First().Values;
Assert.AreEqual(1, contentProperties.Count);
Assert.Multiple(() =>
{
Assert.AreEqual("contentPropertyAlias", contentProperties.First().Alias);
Assert.AreEqual("A content property value", contentProperties.First().Value);
});

Assert.AreEqual(1, value.Blocks.SettingsData.Count);
item = value.Blocks.SettingsData.Single();
contentTypeGuid = Guid.Parse("e7a9447f-e14d-44dd-9ae8-e68c3c3da598");
itemGuid = Guid.Parse("d2eeef66-4111-42f4-a164-7a523eaffbc2");
Assert.AreEqual(contentTypeGuid, item.ContentTypeKey);
Assert.AreEqual(itemGuid, item.Key);
Assert.AreEqual(itemGuid, item.Key);
var settingsProperties = value.Blocks.SettingsData.First().Values;
Assert.AreEqual(1, settingsProperties.Count);
Assert.Multiple(() =>
{
Assert.AreEqual("settingsPropertyAlias", settingsProperties.First().Alias);
Assert.AreEqual("A settings property value", settingsProperties.First().Value);
});

Assert.IsTrue(value.Blocks.Layout.ContainsKey(Constants.PropertyEditors.Aliases.RichText));
var layout = value.Blocks.Layout[Constants.PropertyEditors.Aliases.RichText];
Assert.AreEqual(1, layout.Count());
Assert.AreEqual(Guid.Parse("36cc710a-d8a6-45d0-a07f-7bbd8742cf02"), layout.First().ContentKey);
Assert.AreEqual(Guid.Parse("d2eeef66-4111-42f4-a164-7a523eaffbc2"), layout.First().SettingsKey);

Check warning on line 190 in tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/RichTextPropertyEditorHelperTests.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Large Method

Can_Parse_Blocks_With_Both_Content_And_Settings has 73 lines, 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.
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;
Expand Down Expand Up @@ -85,7 +86,8 @@
distributedCache,
Mock.Of<IKeyValueService>(),
Mock.Of<IServiceScopeFactory>(),
appCaches);
appCaches,
Mock.Of<IPublishedContentTypeFactory>());

Check warning on line 90 in tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationPlanTests.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Large Method

CanExecute has 70 lines, 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.

var plan = new MigrationPlan("default")
.From(string.Empty)
Expand Down
Loading