Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow opt out of import embedded schema file #11296

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions src/JsonSchema/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class CmsDefinition
public RichTextEditorSettings RichTextEditor { get; set; }
public RuntimeMinificationSettings RuntimeMinification { get; set; }
public BasicAuthSettings BasicAuth { get; set; }
public PackageMigrationSettings PackageMigration { get; set; }
}

/// <summary>
Expand Down
37 changes: 37 additions & 0 deletions src/Umbraco.Core/Configuration/Models/PackageMigrationSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.

using System.ComponentModel;
namespace Umbraco.Cms.Core.Configuration.Models
{
/// <summary>
/// Typed configuration options for package migration settings.
/// </summary>
[UmbracoOptions(Constants.Configuration.ConfigPackageMigration)]
public class PackageMigrationSettings
{
private const bool StaticRunSchemaAndContentMigrations = true;
private const bool StaticAllowComponentOverrideOfRunSchemaAndContentMigrations = true;
/// <summary>
/// Gets or sets a value indicating whether package migration steps that install schema and content should run.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
[DefaultValue(StaticRunSchemaAndContentMigrations)]
public bool RunSchemaAndContentMigrations { get; set; } = StaticRunSchemaAndContentMigrations;
/// <summary>
/// Gets or sets a value indicating whether components can override the configured value for <see cref="RunSchemaAndContentMigrations"/>.
/// </summary>
/// <remarks>
/// By default this is true and components can override the configured setting for <see cref="RunSchemaAndContentMigrations"/>.
/// 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.
/// </remarks>
[DefaultValue(StaticAllowComponentOverrideOfRunSchemaAndContentMigrations)]
public bool AllowComponentOverrideOfRunSchemaAndContentMigrations { get; set; } = StaticAllowComponentOverrideOfRunSchemaAndContentMigrations;
}
}
1 change: 1 addition & 0 deletions src/Umbraco.Core/Constants-Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ConfigPackageMigration = ConfigPrefix + "PackageMigration";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
namespace Umbraco.Cms.Web.Common.DependencyInjection
{
/// <summary>
/// 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.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class StaticServiceProvider
public static class StaticServiceProvider
{
/// <summary>
/// The service locator.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static IServiceProvider Instance { get; set; }
public static IServiceProvider Instance { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public static IUmbracoBuilder AddConfiguration(this IUmbracoBuilder builder)
.AddUmbracoOptions<UnattendedSettings>()
.AddUmbracoOptions<RichTextEditorSettings>()
.AddUmbracoOptions<BasicAuthSettings>()
.AddUmbracoOptions<RuntimeMinificationSettings>();
.AddUmbracoOptions<RuntimeMinificationSettings>()
.AddUmbracoOptions<PackageMigrationSettings>();

return builder;
}
Expand Down
1 change: 1 addition & 0 deletions src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/Umbraco.Infrastructure/Packaging/ImportPackageBuilder.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,15 +22,18 @@ public ImportPackageBuilder(
MediaUrlGeneratorCollection mediaUrlGenerators,
IShortStringHelper shortStringHelper,
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
IMigrationContext context)
IMigrationContext context,
IOptions<PackageMigrationSettings> options)
: base(new ImportPackageBuilderExpression(
packagingService,
mediaService,
mediaFileManager,
mediaUrlGenerators,
shortStringHelper,
contentTypeBaseServiceProvider,
context))
context,
options
))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
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;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Packaging;
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;
using Umbraco.Extensions;

namespace Umbraco.Cms.Infrastructure.Packaging
Expand All @@ -26,6 +30,7 @@ internal class ImportPackageBuilderExpression : MigrationExpressionBase
private readonly IPackagingService _packagingService;
private readonly IShortStringHelper _shortStringHelper;
private bool _executed;
private readonly IOptions<PackageMigrationSettings> _options;

public ImportPackageBuilderExpression(
IPackagingService packagingService,
Expand All @@ -34,14 +39,16 @@ public ImportPackageBuilderExpression(
MediaUrlGeneratorCollection mediaUrlGenerators,
IShortStringHelper shortStringHelper,
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
IMigrationContext context) : base(context)
IMigrationContext context,
IOptions<PackageMigrationSettings> options) : base(context)
{
_packagingService = packagingService;
_mediaService = mediaService;
_mediaFileManager = mediaFileManager;
_mediaUrlGenerators = mediaUrlGenerators;
_shortStringHelper = shortStringHelper;
_contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
_options = options;
}

/// <summary>
Expand All @@ -53,12 +60,15 @@ public ImportPackageBuilderExpression(

public override void Execute()
{

if (_executed)
{
throw new InvalidOperationException("This expression has already been executed.");
}

_executed = true;


Context.BuildingExpression = false;

if (EmbeddedResourceMigrationType == null && PackageDataManifest == null)
Expand All @@ -67,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)
{
Expand Down
40 changes: 38 additions & 2 deletions src/Umbraco.Infrastructure/Packaging/PackageMigrationBase.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -15,6 +21,7 @@ public abstract class PackageMigrationBase : MigrationBase
private readonly MediaUrlGeneratorCollection _mediaUrlGenerators;
private readonly IShortStringHelper _shortStringHelper;
private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider;
private readonly IOptions<PackageMigrationSettings> _packageMigrationsSettings;

public PackageMigrationBase(
IPackagingService packagingService,
Expand All @@ -23,15 +30,42 @@ public PackageMigrationBase(
MediaUrlGeneratorCollection mediaUrlGenerators,
IShortStringHelper shortStringHelper,
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
IMigrationContext context)
IMigrationContext context,
IOptions<PackageMigrationSettings> 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<IOptions<PackageMigrationSettings>>()
)
{

}

public IImportPackageBuilder ImportPackage => BeginBuild(
Expand All @@ -42,7 +76,9 @@ public PackageMigrationBase(
_mediaUrlGenerators,
_shortStringHelper,
_contentTypeBaseServiceProvider,
Context));
Context,
_packageMigrationsSettings
));

}
}
40 changes: 38 additions & 2 deletions src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
{
Expand All @@ -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;

/// <summary>
Expand All @@ -44,7 +47,8 @@ public CoreRuntime(
IUmbracoDatabaseFactory databaseFactory,
IEventAggregator eventAggregator,
IHostingEnvironment hostingEnvironment,
IUmbracoVersion umbracoVersion)
IUmbracoVersion umbracoVersion,
IServiceProvider serviceProvider)
{
State = state;
_loggerFactory = loggerFactory;
Expand All @@ -56,9 +60,40 @@ public CoreRuntime(
_eventAggregator = eventAggregator;
_hostingEnvironment = hostingEnvironment;
_umbracoVersion = umbracoVersion;
_serviceProvider = serviceProvider;
_logger = _loggerFactory.CreateLogger<CoreRuntime>();
}

[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
)
{

}

/// <summary>
/// Gets the state of the Umbraco runtime.
/// </summary>
Expand All @@ -76,6 +111,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
{
_cancellationToken = cancellationToken;
StaticApplicationLogging.Initialize(_loggerFactory);
StaticServiceProvider.Instance = _serviceProvider;

AppDomain.CurrentDomain.UnhandledException += (_, args) =>
{
Expand Down

This file was deleted.

Loading