From 6fd6a55bfc25abd156f2aafb122627eb0c356635 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 5 Oct 2021 13:52:15 +0200 Subject: [PATCH 1/6] Introduce an opt-out options from the import of embedded schema files. --- src/JsonSchema/AppSettings.cs | 1 + .../Models/PackageMigrationsSettings.cs | 25 +++++++++++++++ src/Umbraco.Core/Constants-Configuration.cs | 1 + .../UmbracoBuilder.Configuration.cs | 3 +- .../ImportPackageBuilderExpression.cs | 32 ++++++++++++++++++- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 1 + 6 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/Umbraco.Core/Configuration/Models/PackageMigrationsSettings.cs diff --git a/src/JsonSchema/AppSettings.cs b/src/JsonSchema/AppSettings.cs index 4045421eb16e..2e4ba01e00ce 100644 --- a/src/JsonSchema/AppSettings.cs +++ b/src/JsonSchema/AppSettings.cs @@ -47,6 +47,7 @@ public class CmsDefinition public RichTextEditorSettings RichTextEditor { get; set; } public RuntimeMinificationSettings RuntimeMinification { get; set; } public BasicAuthSettings BasicAuth { get; set; } + public PackageMigrationsSettings PackageMigrations { get; set; } } /// diff --git a/src/Umbraco.Core/Configuration/Models/PackageMigrationsSettings.cs b/src/Umbraco.Core/Configuration/Models/PackageMigrationsSettings.cs new file mode 100644 index 000000000000..d31524761355 --- /dev/null +++ b/src/Umbraco.Core/Configuration/Models/PackageMigrationsSettings.cs @@ -0,0 +1,25 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System; +using System.ComponentModel; + +namespace Umbraco.Cms.Core.Configuration.Models +{ + /// + /// Typed configuration options for global settings. + /// + [UmbracoOptions(Constants.Configuration.ConfigPackageMigrations)] + public class PackageMigrationsSettings + { + + private const bool StaticDisableImportFromEmbeddedSchema = false; + + /// + /// An option to disable the import from embedded schema files using package migrations. + /// + [DefaultValue(StaticDisableImportFromEmbeddedSchema)] + public bool DisableImportFromEmbeddedSchema { get; set; } = StaticDisableImportFromEmbeddedSchema; + + } +} diff --git a/src/Umbraco.Core/Constants-Configuration.cs b/src/Umbraco.Core/Constants-Configuration.cs index 0c7657d07e8f..c02a45028cbd 100644 --- a/src/Umbraco.Core/Constants-Configuration.cs +++ b/src/Umbraco.Core/Constants-Configuration.cs @@ -52,6 +52,7 @@ public static class Configuration public const string ConfigWebRouting = ConfigPrefix + "WebRouting"; public const string ConfigUserPassword = ConfigPrefix + "Security:UserPassword"; public const string ConfigRichTextEditor = ConfigPrefix + "RichTextEditor"; + public const string ConfigPackageMigrations = ConfigPrefix + "PackageMigrations"; } } } diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs index 77902cc5c10d..8d5890366d82 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs @@ -72,7 +72,8 @@ public static IUmbracoBuilder AddConfiguration(this IUmbracoBuilder builder) .AddUmbracoOptions() .AddUmbracoOptions() .AddUmbracoOptions() - .AddUmbracoOptions(); + .AddUmbracoOptions() + .AddUmbracoOptions(); return builder; } diff --git a/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs b/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs index 8eda0f0b453c..a859b30bb3e4 100644 --- a/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs +++ b/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs @@ -5,7 +5,9 @@ using System.Xml.Linq; using System.Xml.XPath; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Umbraco.Cms.Core; +using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Packaging; @@ -26,6 +28,7 @@ internal class ImportPackageBuilderExpression : MigrationExpressionBase private readonly IPackagingService _packagingService; private readonly IShortStringHelper _shortStringHelper; private bool _executed; + private readonly IOptions _options; public ImportPackageBuilderExpression( IPackagingService packagingService, @@ -34,7 +37,8 @@ public ImportPackageBuilderExpression( MediaUrlGeneratorCollection mediaUrlGenerators, IShortStringHelper shortStringHelper, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, - IMigrationContext context) : base(context) + IMigrationContext context, + IOptions options) : base(context) { _packagingService = packagingService; _mediaService = mediaService; @@ -42,6 +46,27 @@ public ImportPackageBuilderExpression( _mediaUrlGenerators = mediaUrlGenerators; _shortStringHelper = shortStringHelper; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; + _options = options; + } + + [Obsolete("Use ctor with more params")] + public ImportPackageBuilderExpression( + IPackagingService packagingService, + IMediaService mediaService, + MediaFileManager mediaFileManager, + MediaUrlGeneratorCollection mediaUrlGenerators, + IShortStringHelper shortStringHelper, + IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, + IMigrationContext context) : this( + packagingService, + mediaService, + mediaFileManager, + mediaUrlGenerators, + shortStringHelper, + contentTypeBaseServiceProvider, + context, Options.Create(new PackageMigrationsSettings())) + { + } /// @@ -53,6 +78,11 @@ public ImportPackageBuilderExpression( public override void Execute() { + if (_options.Value.DisableImportFromEmbeddedSchema) + { + Logger.LogInformation("Skipping import of embedded schema file, due to configuration"); + return; + } if (_executed) { throw new InvalidOperationException("This expression has already been executed."); diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index a050d22a161d..d94b74e9cc7b 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -74,6 +74,7 @@ all + From d5962e8a953dcad419d8ad8c689e854156506ccb Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 6 Oct 2021 09:47:08 +0200 Subject: [PATCH 2/6] Moved the initialization of the static service provider into CoreRuntime as this runs before the IStartupFilters, and otherwise the static service provider is not available in hosted services. E.g. for migrations --- src/JsonSchema/AppSettings.cs | 2 +- .../Models/PackageMigrationSettings.cs | 37 +++++++++++++++++ .../Models/PackageMigrationsSettings.cs | 25 ------------ src/Umbraco.Core/Constants-Configuration.cs | 2 +- .../StaticServiceProvider.cs | 8 ++-- .../UmbracoBuilder.Configuration.cs | 2 +- .../DependencyInjection/UmbracoBuilder.cs | 1 + .../Packaging/ImportPackageBuilder.cs | 9 ++++- .../ImportPackageBuilderExpression.cs | 40 ++++++------------- .../Packaging/PackageMigrationBase.cs | 40 ++++++++++++++++++- .../Runtime/CoreRuntime.cs | 40 ++++++++++++++++++- .../UmbracoApplicationServicesCapture.cs | 20 ---------- .../Umbraco.Web.Common.csproj | 4 ++ 13 files changed, 145 insertions(+), 85 deletions(-) create mode 100644 src/Umbraco.Core/Configuration/Models/PackageMigrationSettings.cs delete mode 100644 src/Umbraco.Core/Configuration/Models/PackageMigrationsSettings.cs rename src/{Umbraco.Web.Common => Umbraco.Core}/DependencyInjection/StaticServiceProvider.cs (64%) delete mode 100644 src/Umbraco.Web.Common/DependencyInjection/UmbracoApplicationServicesCapture.cs diff --git a/src/JsonSchema/AppSettings.cs b/src/JsonSchema/AppSettings.cs index 2e4ba01e00ce..1b7c6d46fc37 100644 --- a/src/JsonSchema/AppSettings.cs +++ b/src/JsonSchema/AppSettings.cs @@ -47,7 +47,7 @@ public class CmsDefinition public RichTextEditorSettings RichTextEditor { get; set; } public RuntimeMinificationSettings RuntimeMinification { get; set; } public BasicAuthSettings BasicAuth { get; set; } - public PackageMigrationsSettings PackageMigrations { get; set; } + public PackageMigrationSettings PackageMigration { get; set; } } /// diff --git a/src/Umbraco.Core/Configuration/Models/PackageMigrationSettings.cs b/src/Umbraco.Core/Configuration/Models/PackageMigrationSettings.cs new file mode 100644 index 000000000000..43210fc7b31a --- /dev/null +++ b/src/Umbraco.Core/Configuration/Models/PackageMigrationSettings.cs @@ -0,0 +1,37 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System.ComponentModel; +namespace Umbraco.Cms.Core.Configuration.Models +{ + /// + /// Typed configuration options for package migration settings. + /// + [UmbracoOptions(Constants.Configuration.ConfigPackageMigration)] + public class PackageMigrationSettings + { + private const bool StaticRunSchemaAndContentMigrations = true; + private const bool StaticAllowComponentOverrideOfRunSchemaAndContentMigrations = true; + /// + /// Gets or sets a value indicating whether package migration steps that install schema and content should run. + /// + /// + /// By default this is true and schema and content defined in a package migration are installed. + /// Using configuration, administrators can optionally switch this off in certain environments. + /// Deployment tools such as Umbraco Deploy can also configure this option to run or not run these migration + /// steps as is appropriate for normal use of the tool. + /// + [DefaultValue(StaticRunSchemaAndContentMigrations)] + public bool RunSchemaAndContentMigrations { get; set; } = StaticRunSchemaAndContentMigrations; + /// + /// Gets or sets a value indicating whether components can override the configured value for . + /// + /// + /// By default this is true and components can override the configured setting for . + /// If an administrator wants explicit control over which environments migration steps installing schema and content can run, + /// they can set this to false. Components should respect this and not override the configuration. + /// + [DefaultValue(StaticAllowComponentOverrideOfRunSchemaAndContentMigrations)] + public bool AllowComponentOverrideOfRunSchemaAndContentMigrations { get; set; } = StaticAllowComponentOverrideOfRunSchemaAndContentMigrations; + } +} diff --git a/src/Umbraco.Core/Configuration/Models/PackageMigrationsSettings.cs b/src/Umbraco.Core/Configuration/Models/PackageMigrationsSettings.cs deleted file mode 100644 index d31524761355..000000000000 --- a/src/Umbraco.Core/Configuration/Models/PackageMigrationsSettings.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System; -using System.ComponentModel; - -namespace Umbraco.Cms.Core.Configuration.Models -{ - /// - /// Typed configuration options for global settings. - /// - [UmbracoOptions(Constants.Configuration.ConfigPackageMigrations)] - public class PackageMigrationsSettings - { - - private const bool StaticDisableImportFromEmbeddedSchema = false; - - /// - /// An option to disable the import from embedded schema files using package migrations. - /// - [DefaultValue(StaticDisableImportFromEmbeddedSchema)] - public bool DisableImportFromEmbeddedSchema { get; set; } = StaticDisableImportFromEmbeddedSchema; - - } -} diff --git a/src/Umbraco.Core/Constants-Configuration.cs b/src/Umbraco.Core/Constants-Configuration.cs index c02a45028cbd..c36f5813abea 100644 --- a/src/Umbraco.Core/Constants-Configuration.cs +++ b/src/Umbraco.Core/Constants-Configuration.cs @@ -52,7 +52,7 @@ public static class Configuration public const string ConfigWebRouting = ConfigPrefix + "WebRouting"; public const string ConfigUserPassword = ConfigPrefix + "Security:UserPassword"; public const string ConfigRichTextEditor = ConfigPrefix + "RichTextEditor"; - public const string ConfigPackageMigrations = ConfigPrefix + "PackageMigrations"; + public const string ConfigPackageMigration = ConfigPrefix + "PackageMigration"; } } } diff --git a/src/Umbraco.Web.Common/DependencyInjection/StaticServiceProvider.cs b/src/Umbraco.Core/DependencyInjection/StaticServiceProvider.cs similarity index 64% rename from src/Umbraco.Web.Common/DependencyInjection/StaticServiceProvider.cs rename to src/Umbraco.Core/DependencyInjection/StaticServiceProvider.cs index c73685b41d5c..8d195c56f4de 100644 --- a/src/Umbraco.Web.Common/DependencyInjection/StaticServiceProvider.cs +++ b/src/Umbraco.Core/DependencyInjection/StaticServiceProvider.cs @@ -4,22 +4,22 @@ namespace Umbraco.Cms.Web.Common.DependencyInjection { /// - /// INTERNAL Service locator. Should only be used if no other ways exist. + /// Service locator for internal (umbraco cms) only purposes. Should only be used if no other ways exist. /// /// /// It is created with only two goals in mind /// 1) Continue to have the same extension methods on IPublishedContent and IPublishedElement as in V8. To make migration easier. - /// 2) To have a tool to avoid breaking changes in minor versions. All methods using this should in theory be obsolete. + /// 2) To have a tool to avoid breaking changes in minor and patch versions. All methods using this should in theory be obsolete. /// /// Keep in mind, every time this is used, the code becomes basically untestable. /// [EditorBrowsable(EditorBrowsableState.Never)] - internal static class StaticServiceProvider + public static class StaticServiceProvider { /// /// The service locator. /// [EditorBrowsable(EditorBrowsableState.Never)] - internal static IServiceProvider Instance { get; set; } + public static IServiceProvider Instance { get; set; } } } diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs index 8d5890366d82..9b31ed7056bc 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs @@ -73,7 +73,7 @@ public static IUmbracoBuilder AddConfiguration(this IUmbracoBuilder builder) .AddUmbracoOptions() .AddUmbracoOptions() .AddUmbracoOptions() - .AddUmbracoOptions(); + .AddUmbracoOptions(); return builder; } diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs index 6f6a53df66b3..bf3b3edaf91c 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs @@ -38,6 +38,7 @@ using Umbraco.Cms.Core.Sync; using Umbraco.Cms.Core.Templates; using Umbraco.Cms.Core.Web; +using Umbraco.Cms.Web.Common.DependencyInjection; using Umbraco.Extensions; namespace Umbraco.Cms.Core.DependencyInjection diff --git a/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilder.cs b/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilder.cs index c14d3e5119dd..130b1f3ed307 100644 --- a/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilder.cs +++ b/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilder.cs @@ -1,5 +1,7 @@ using System; using System.Xml.Linq; +using Microsoft.Extensions.Options; +using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.PropertyEditors; using Umbraco.Cms.Core.Serialization; @@ -20,7 +22,8 @@ public ImportPackageBuilder( MediaUrlGeneratorCollection mediaUrlGenerators, IShortStringHelper shortStringHelper, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, - IMigrationContext context) + IMigrationContext context, + IOptions options) : base(new ImportPackageBuilderExpression( packagingService, mediaService, @@ -28,7 +31,9 @@ public ImportPackageBuilder( mediaUrlGenerators, shortStringHelper, contentTypeBaseServiceProvider, - context)) + context, + options + )) { } diff --git a/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs b/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs index a859b30bb3e4..8d4ce437eb62 100644 --- a/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs +++ b/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Xml.Linq; using System.Xml.XPath; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Cms.Core; @@ -15,6 +16,7 @@ using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Migrations; +using Umbraco.Cms.Web.Common.DependencyInjection; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Packaging @@ -28,7 +30,7 @@ internal class ImportPackageBuilderExpression : MigrationExpressionBase private readonly IPackagingService _packagingService; private readonly IShortStringHelper _shortStringHelper; private bool _executed; - private readonly IOptions _options; + private readonly IOptions _options; public ImportPackageBuilderExpression( IPackagingService packagingService, @@ -38,7 +40,7 @@ public ImportPackageBuilderExpression( IShortStringHelper shortStringHelper, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IMigrationContext context, - IOptions options) : base(context) + IOptions options) : base(context) { _packagingService = packagingService; _mediaService = mediaService; @@ -49,26 +51,6 @@ public ImportPackageBuilderExpression( _options = options; } - [Obsolete("Use ctor with more params")] - public ImportPackageBuilderExpression( - IPackagingService packagingService, - IMediaService mediaService, - MediaFileManager mediaFileManager, - MediaUrlGeneratorCollection mediaUrlGenerators, - IShortStringHelper shortStringHelper, - IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, - IMigrationContext context) : this( - packagingService, - mediaService, - mediaFileManager, - mediaUrlGenerators, - shortStringHelper, - contentTypeBaseServiceProvider, - context, Options.Create(new PackageMigrationsSettings())) - { - - } - /// /// The type of the migration which dictates the namespace of the embedded resource /// @@ -78,17 +60,15 @@ public ImportPackageBuilderExpression( public override void Execute() { - if (_options.Value.DisableImportFromEmbeddedSchema) - { - Logger.LogInformation("Skipping import of embedded schema file, due to configuration"); - return; - } + if (_executed) { throw new InvalidOperationException("This expression has already been executed."); } _executed = true; + + Context.BuildingExpression = false; if (EmbeddedResourceMigrationType == null && PackageDataManifest == null) @@ -97,6 +77,12 @@ public override void Execute() $"Nothing to execute, neither {nameof(EmbeddedResourceMigrationType)} or {nameof(PackageDataManifest)} has been set."); } + if (!_options.Value.RunSchemaAndContentMigrations) + { + Logger.LogInformation("Skipping import of embedded schema file, due to configuration"); + return; + } + InstallationSummary installationSummary; if (EmbeddedResourceMigrationType != null) { diff --git a/src/Umbraco.Infrastructure/Packaging/PackageMigrationBase.cs b/src/Umbraco.Infrastructure/Packaging/PackageMigrationBase.cs index 3166cdbd4f3b..21157f80646a 100644 --- a/src/Umbraco.Infrastructure/Packaging/PackageMigrationBase.cs +++ b/src/Umbraco.Infrastructure/Packaging/PackageMigrationBase.cs @@ -1,8 +1,14 @@ +using System; +using System.ComponentModel; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.PropertyEditors; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Migrations; +using Umbraco.Cms.Web.Common.DependencyInjection; namespace Umbraco.Cms.Infrastructure.Packaging { @@ -15,6 +21,7 @@ public abstract class PackageMigrationBase : MigrationBase private readonly MediaUrlGeneratorCollection _mediaUrlGenerators; private readonly IShortStringHelper _shortStringHelper; private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; + private readonly IOptions _packageMigrationsSettings; public PackageMigrationBase( IPackagingService packagingService, @@ -23,15 +30,42 @@ public PackageMigrationBase( MediaUrlGeneratorCollection mediaUrlGenerators, IShortStringHelper shortStringHelper, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, - IMigrationContext context) + IMigrationContext context, + IOptions packageMigrationsSettings) : base(context) { + _packagingService = packagingService; _mediaService = mediaService; _mediaFileManager = mediaFileManager; _mediaUrlGenerators = mediaUrlGenerators; _shortStringHelper = shortStringHelper; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; + _packageMigrationsSettings = packageMigrationsSettings; + } + + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("Use ctor with all params")] + public PackageMigrationBase( + IPackagingService packagingService, + IMediaService mediaService, + MediaFileManager mediaFileManager, + MediaUrlGeneratorCollection mediaUrlGenerators, + IShortStringHelper shortStringHelper, + IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, + IMigrationContext context) + : this( + packagingService, + mediaService, + mediaFileManager, + mediaUrlGenerators, + shortStringHelper, + contentTypeBaseServiceProvider, + context, + StaticServiceProvider.Instance.GetRequiredService>() + ) + { + } public IImportPackageBuilder ImportPackage => BeginBuild( @@ -42,7 +76,9 @@ public PackageMigrationBase( _mediaUrlGenerators, _shortStringHelper, _contentTypeBaseServiceProvider, - Context)); + Context, + _packageMigrationsSettings + )); } } diff --git a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs index 86f4e070c2ac..4ec87dfde730 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs @@ -1,9 +1,9 @@ using System; +using System.ComponentModel; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Configuration; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Exceptions; @@ -13,7 +13,9 @@ using Umbraco.Cms.Core.Runtime; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Persistence; +using Umbraco.Cms.Web.Common.DependencyInjection; using Umbraco.Extensions; +using ComponentCollection = Umbraco.Cms.Core.Composing.ComponentCollection; namespace Umbraco.Cms.Infrastructure.Runtime { @@ -29,6 +31,7 @@ public class CoreRuntime : IRuntime private readonly IEventAggregator _eventAggregator; private readonly IHostingEnvironment _hostingEnvironment; private readonly IUmbracoVersion _umbracoVersion; + private readonly IServiceProvider _serviceProvider; private CancellationToken _cancellationToken; /// @@ -44,7 +47,8 @@ public CoreRuntime( IUmbracoDatabaseFactory databaseFactory, IEventAggregator eventAggregator, IHostingEnvironment hostingEnvironment, - IUmbracoVersion umbracoVersion) + IUmbracoVersion umbracoVersion, + IServiceProvider serviceProvider) { State = state; _loggerFactory = loggerFactory; @@ -56,9 +60,40 @@ public CoreRuntime( _eventAggregator = eventAggregator; _hostingEnvironment = hostingEnvironment; _umbracoVersion = umbracoVersion; + _serviceProvider = serviceProvider; _logger = _loggerFactory.CreateLogger(); } + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete] + public CoreRuntime( + ILoggerFactory loggerFactory, + IRuntimeState state, + ComponentCollection components, + IApplicationShutdownRegistry applicationShutdownRegistry, + IProfilingLogger profilingLogger, + IMainDom mainDom, + IUmbracoDatabaseFactory databaseFactory, + IEventAggregator eventAggregator, + IHostingEnvironment hostingEnvironment, + IUmbracoVersion umbracoVersion + ):this( + loggerFactory, + state, + components, + applicationShutdownRegistry, + profilingLogger, + mainDom, + databaseFactory, + eventAggregator, + hostingEnvironment, + umbracoVersion, + null + ) + { + + } + /// /// Gets the state of the Umbraco runtime. /// @@ -76,6 +111,7 @@ public async Task StartAsync(CancellationToken cancellationToken) { _cancellationToken = cancellationToken; StaticApplicationLogging.Initialize(_loggerFactory); + StaticServiceProvider.Instance = _serviceProvider; AppDomain.CurrentDomain.UnhandledException += (_, args) => { diff --git a/src/Umbraco.Web.Common/DependencyInjection/UmbracoApplicationServicesCapture.cs b/src/Umbraco.Web.Common/DependencyInjection/UmbracoApplicationServicesCapture.cs deleted file mode 100644 index fa5adf7aeb0e..000000000000 --- a/src/Umbraco.Web.Common/DependencyInjection/UmbracoApplicationServicesCapture.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; - -namespace Umbraco.Cms.Web.Common.DependencyInjection -{ - /// - /// A registered to automatically capture application services - /// - internal class UmbracoApplicationServicesCapture : IStartupFilter - { - /// - public Action Configure(Action next) => - app => - { - StaticServiceProvider.Instance = app.ApplicationServices; - next(app); - }; - } -} diff --git a/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj b/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj index fcd62febf447..979215346957 100644 --- a/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj +++ b/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj @@ -49,4 +49,8 @@ + + + + From 44bd21ea2a58a1db4ad9428b445162af1469c3b4 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 6 Oct 2021 10:02:41 +0200 Subject: [PATCH 3/6] fix build --- .../DependencyInjection/UmbracoBuilderExtensions.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs index ef98553ba2e2..2d584f198ea5 100644 --- a/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs @@ -123,10 +123,6 @@ public static IUmbracoBuilder AddUmbraco( config, profiler); - // adds the umbraco startup filter which will call UseUmbraco early on before - // other start filters are applied (depending on the ordering of IStartupFilters in DI). - services.AddTransient(); - return new UmbracoBuilder(services, config, typeLoader, loggerFactory, profiler, appCaches, tempHostingEnvironment); } From 9cd677066704e122cc6548918e5313fbb081dbd0 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 6 Oct 2021 10:05:22 +0200 Subject: [PATCH 4/6] Minor code tidy and naming alignment. --- .../Models/PackageMigrationSettings.cs | 3 +++ .../Configuration/Models/UnattendedSettings.cs | 10 ++++++---- .../Packaging/ImportPackageBuilder.cs | 4 +--- .../Packaging/ImportPackageBuilderExpression.cs | 13 ++++++------- .../Packaging/PackageMigrationBase.cs | 9 ++------- src/Umbraco.Web.Common/Umbraco.Web.Common.csproj | 5 ----- 6 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/Umbraco.Core/Configuration/Models/PackageMigrationSettings.cs b/src/Umbraco.Core/Configuration/Models/PackageMigrationSettings.cs index 43210fc7b31a..27968fdcd2ad 100644 --- a/src/Umbraco.Core/Configuration/Models/PackageMigrationSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/PackageMigrationSettings.cs @@ -2,6 +2,7 @@ // See LICENSE for more details. using System.ComponentModel; + namespace Umbraco.Cms.Core.Configuration.Models { /// @@ -12,6 +13,7 @@ public class PackageMigrationSettings { private const bool StaticRunSchemaAndContentMigrations = true; private const bool StaticAllowComponentOverrideOfRunSchemaAndContentMigrations = true; + /// /// Gets or sets a value indicating whether package migration steps that install schema and content should run. /// @@ -23,6 +25,7 @@ public class PackageMigrationSettings /// [DefaultValue(StaticRunSchemaAndContentMigrations)] public bool RunSchemaAndContentMigrations { get; set; } = StaticRunSchemaAndContentMigrations; + /// /// Gets or sets a value indicating whether components can override the configured value for . /// diff --git a/src/Umbraco.Core/Configuration/Models/UnattendedSettings.cs b/src/Umbraco.Core/Configuration/Models/UnattendedSettings.cs index 08020f6e8980..7103a9534e90 100644 --- a/src/Umbraco.Core/Configuration/Models/UnattendedSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/UnattendedSettings.cs @@ -1,17 +1,19 @@ -using System.ComponentModel; +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace Umbraco.Cms.Core.Configuration.Models { - /// /// Typed configuration options for unattended settings. /// [UmbracoOptions(Constants.Configuration.ConfigUnattended)] public class UnattendedSettings { - internal const bool StaticInstallUnattended = false; - internal const bool StaticUpgradeUnattended = false; + private const bool StaticInstallUnattended = false; + private const bool StaticUpgradeUnattended = false; /// /// Gets or sets a value indicating whether unattended installs are enabled. diff --git a/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilder.cs b/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilder.cs index 130b1f3ed307..fef61a54c3d3 100644 --- a/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilder.cs +++ b/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilder.cs @@ -4,7 +4,6 @@ using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Migrations; @@ -32,8 +31,7 @@ public ImportPackageBuilder( shortStringHelper, contentTypeBaseServiceProvider, context, - options - )) + options)) { } diff --git a/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs b/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs index 8d4ce437eb62..1a994756f1f1 100644 --- a/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs +++ b/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Xml.Linq; using System.Xml.XPath; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Cms.Core; @@ -16,7 +15,6 @@ using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Migrations; -using Umbraco.Cms.Web.Common.DependencyInjection; using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.Packaging @@ -29,8 +27,9 @@ internal class ImportPackageBuilderExpression : MigrationExpressionBase private readonly MediaUrlGeneratorCollection _mediaUrlGenerators; private readonly IPackagingService _packagingService; private readonly IShortStringHelper _shortStringHelper; - private bool _executed; - private readonly IOptions _options; + private readonly PackageMigrationSettings _packageMigrationSettings; + + private bool _executed; public ImportPackageBuilderExpression( IPackagingService packagingService, @@ -40,7 +39,7 @@ public ImportPackageBuilderExpression( IShortStringHelper shortStringHelper, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IMigrationContext context, - IOptions options) : base(context) + IOptions packageMigrationSettings) : base(context) { _packagingService = packagingService; _mediaService = mediaService; @@ -48,7 +47,7 @@ public ImportPackageBuilderExpression( _mediaUrlGenerators = mediaUrlGenerators; _shortStringHelper = shortStringHelper; _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; - _options = options; + _packageMigrationSettings = packageMigrationSettings.Value; } /// @@ -77,7 +76,7 @@ public override void Execute() $"Nothing to execute, neither {nameof(EmbeddedResourceMigrationType)} or {nameof(PackageDataManifest)} has been set."); } - if (!_options.Value.RunSchemaAndContentMigrations) + if (!_packageMigrationSettings.RunSchemaAndContentMigrations) { Logger.LogInformation("Skipping import of embedded schema file, due to configuration"); return; diff --git a/src/Umbraco.Infrastructure/Packaging/PackageMigrationBase.cs b/src/Umbraco.Infrastructure/Packaging/PackageMigrationBase.cs index 21157f80646a..54b96955d40b 100644 --- a/src/Umbraco.Infrastructure/Packaging/PackageMigrationBase.cs +++ b/src/Umbraco.Infrastructure/Packaging/PackageMigrationBase.cs @@ -12,7 +12,6 @@ namespace Umbraco.Cms.Infrastructure.Packaging { - public abstract class PackageMigrationBase : MigrationBase { private readonly IPackagingService _packagingService; @@ -34,7 +33,6 @@ public PackageMigrationBase( IOptions packageMigrationsSettings) : base(context) { - _packagingService = packagingService; _mediaService = mediaService; _mediaFileManager = mediaFileManager; @@ -62,10 +60,8 @@ public PackageMigrationBase( shortStringHelper, contentTypeBaseServiceProvider, context, - StaticServiceProvider.Instance.GetRequiredService>() - ) + StaticServiceProvider.Instance.GetRequiredService>()) { - } public IImportPackageBuilder ImportPackage => BeginBuild( @@ -77,8 +73,7 @@ public PackageMigrationBase( _shortStringHelper, _contentTypeBaseServiceProvider, Context, - _packageMigrationsSettings - )); + _packageMigrationsSettings)); } } diff --git a/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj b/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj index 979215346957..537df5aab48f 100644 --- a/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj +++ b/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj @@ -48,9 +48,4 @@ <_Parameter1>Umbraco.Tests.UnitTests - - - - - From 2d32acf3344f50ca80b79edba243d48702a06a1b Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 6 Oct 2021 10:10:43 +0200 Subject: [PATCH 5/6] Update src/Umbraco.Web.UI/Umbraco.Web.UI.csproj --- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index d94b74e9cc7b..a050d22a161d 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -74,7 +74,6 @@ all - From e8205815f7b880d1601f8cbe92e0b12c06e6c686 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 6 Oct 2021 10:18:18 +0200 Subject: [PATCH 6/6] Removed default installation of starter kit. --- .../Packaging/ImportPackageBuilderExpression.cs | 2 -- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 1 - 2 files changed, 3 deletions(-) diff --git a/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs b/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs index 1a994756f1f1..838d59e14eee 100644 --- a/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs +++ b/src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs @@ -59,7 +59,6 @@ public ImportPackageBuilderExpression( public override void Execute() { - if (_executed) { throw new InvalidOperationException("This expression has already been executed."); @@ -67,7 +66,6 @@ public override void Execute() _executed = true; - Context.BuildingExpression = false; if (EmbeddedResourceMigrationType == null && PackageDataManifest == null) diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index d94b74e9cc7b..a050d22a161d 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -74,7 +74,6 @@ all -