Skip to content

Commit 2a29cdc

Browse files
Allow opt out of import embedded schema file (#11296)
* Introduce an opt-out options from the import of embedded schema files. * 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 * fix build * Minor code tidy and naming alignment. * Update src/Umbraco.Web.UI/Umbraco.Web.UI.csproj * Removed default installation of starter kit. Co-authored-by: Andy Butland <[email protected]>
1 parent 83e79f9 commit 2a29cdc

File tree

14 files changed

+148
-44
lines changed

14 files changed

+148
-44
lines changed

src/JsonSchema/AppSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class CmsDefinition
4747
public RichTextEditorSettings RichTextEditor { get; set; }
4848
public RuntimeMinificationSettings RuntimeMinification { get; set; }
4949
public BasicAuthSettings BasicAuth { get; set; }
50+
public PackageMigrationSettings PackageMigration { get; set; }
5051
}
5152

5253
/// <summary>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) Umbraco.
2+
// See LICENSE for more details.
3+
4+
using System.ComponentModel;
5+
6+
namespace Umbraco.Cms.Core.Configuration.Models
7+
{
8+
/// <summary>
9+
/// Typed configuration options for package migration settings.
10+
/// </summary>
11+
[UmbracoOptions(Constants.Configuration.ConfigPackageMigration)]
12+
public class PackageMigrationSettings
13+
{
14+
private const bool StaticRunSchemaAndContentMigrations = true;
15+
private const bool StaticAllowComponentOverrideOfRunSchemaAndContentMigrations = true;
16+
17+
/// <summary>
18+
/// Gets or sets a value indicating whether package migration steps that install schema and content should run.
19+
/// </summary>
20+
/// <remarks>
21+
/// By default this is true and schema and content defined in a package migration are installed.
22+
/// Using configuration, administrators can optionally switch this off in certain environments.
23+
/// Deployment tools such as Umbraco Deploy can also configure this option to run or not run these migration
24+
/// steps as is appropriate for normal use of the tool.
25+
/// </remarks>
26+
[DefaultValue(StaticRunSchemaAndContentMigrations)]
27+
public bool RunSchemaAndContentMigrations { get; set; } = StaticRunSchemaAndContentMigrations;
28+
29+
/// <summary>
30+
/// Gets or sets a value indicating whether components can override the configured value for <see cref="RunSchemaAndContentMigrations"/>.
31+
/// </summary>
32+
/// <remarks>
33+
/// By default this is true and components can override the configured setting for <see cref="RunSchemaAndContentMigrations"/>.
34+
/// If an administrator wants explicit control over which environments migration steps installing schema and content can run,
35+
/// they can set this to false. Components should respect this and not override the configuration.
36+
/// </remarks>
37+
[DefaultValue(StaticAllowComponentOverrideOfRunSchemaAndContentMigrations)]
38+
public bool AllowComponentOverrideOfRunSchemaAndContentMigrations { get; set; } = StaticAllowComponentOverrideOfRunSchemaAndContentMigrations;
39+
}
40+
}

src/Umbraco.Core/Configuration/Models/UnattendedSettings.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
using System.ComponentModel;
1+
// Copyright (c) Umbraco.
2+
// See LICENSE for more details.
3+
4+
using System.ComponentModel;
25
using System.ComponentModel.DataAnnotations;
36

47
namespace Umbraco.Cms.Core.Configuration.Models
58
{
6-
79
/// <summary>
810
/// Typed configuration options for unattended settings.
911
/// </summary>
1012
[UmbracoOptions(Constants.Configuration.ConfigUnattended)]
1113
public class UnattendedSettings
1214
{
13-
internal const bool StaticInstallUnattended = false;
14-
internal const bool StaticUpgradeUnattended = false;
15+
private const bool StaticInstallUnattended = false;
16+
private const bool StaticUpgradeUnattended = false;
1517

1618
/// <summary>
1719
/// Gets or sets a value indicating whether unattended installs are enabled.

src/Umbraco.Core/Constants-Configuration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public static class Configuration
5252
public const string ConfigWebRouting = ConfigPrefix + "WebRouting";
5353
public const string ConfigUserPassword = ConfigPrefix + "Security:UserPassword";
5454
public const string ConfigRichTextEditor = ConfigPrefix + "RichTextEditor";
55+
public const string ConfigPackageMigration = ConfigPrefix + "PackageMigration";
5556
}
5657
}
5758
}

src/Umbraco.Web.Common/DependencyInjection/StaticServiceProvider.cs renamed to src/Umbraco.Core/DependencyInjection/StaticServiceProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
namespace Umbraco.Cms.Web.Common.DependencyInjection
55
{
66
/// <summary>
7-
/// INTERNAL Service locator. Should only be used if no other ways exist.
7+
/// Service locator for internal (umbraco cms) only purposes. Should only be used if no other ways exist.
88
/// </summary>
99
/// <remarks>
1010
/// It is created with only two goals in mind
1111
/// 1) Continue to have the same extension methods on IPublishedContent and IPublishedElement as in V8. To make migration easier.
12-
/// 2) To have a tool to avoid breaking changes in minor versions. All methods using this should in theory be obsolete.
12+
/// 2) To have a tool to avoid breaking changes in minor and patch versions. All methods using this should in theory be obsolete.
1313
///
1414
/// Keep in mind, every time this is used, the code becomes basically untestable.
1515
/// </remarks>
1616
[EditorBrowsable(EditorBrowsableState.Never)]
17-
internal static class StaticServiceProvider
17+
public static class StaticServiceProvider
1818
{
1919
/// <summary>
2020
/// The service locator.
2121
/// </summary>
2222
[EditorBrowsable(EditorBrowsableState.Never)]
23-
internal static IServiceProvider Instance { get; set; }
23+
public static IServiceProvider Instance { get; set; }
2424
}
2525
}

src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public static IUmbracoBuilder AddConfiguration(this IUmbracoBuilder builder)
7272
.AddUmbracoOptions<UnattendedSettings>()
7373
.AddUmbracoOptions<RichTextEditorSettings>()
7474
.AddUmbracoOptions<BasicAuthSettings>()
75-
.AddUmbracoOptions<RuntimeMinificationSettings>();
75+
.AddUmbracoOptions<RuntimeMinificationSettings>()
76+
.AddUmbracoOptions<PackageMigrationSettings>();
7677

7778
return builder;
7879
}

src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
using Umbraco.Cms.Core.Sync;
3939
using Umbraco.Cms.Core.Templates;
4040
using Umbraco.Cms.Core.Web;
41+
using Umbraco.Cms.Web.Common.DependencyInjection;
4142
using Umbraco.Extensions;
4243

4344
namespace Umbraco.Cms.Core.DependencyInjection

src/Umbraco.Infrastructure/Packaging/ImportPackageBuilder.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System;
22
using System.Xml.Linq;
3+
using Microsoft.Extensions.Options;
4+
using Umbraco.Cms.Core.Configuration.Models;
35
using Umbraco.Cms.Core.IO;
46
using Umbraco.Cms.Core.PropertyEditors;
5-
using Umbraco.Cms.Core.Serialization;
67
using Umbraco.Cms.Core.Services;
78
using Umbraco.Cms.Core.Strings;
89
using Umbraco.Cms.Infrastructure.Migrations;
@@ -20,15 +21,17 @@ public ImportPackageBuilder(
2021
MediaUrlGeneratorCollection mediaUrlGenerators,
2122
IShortStringHelper shortStringHelper,
2223
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
23-
IMigrationContext context)
24+
IMigrationContext context,
25+
IOptions<PackageMigrationSettings> options)
2426
: base(new ImportPackageBuilderExpression(
2527
packagingService,
2628
mediaService,
2729
mediaFileManager,
2830
mediaUrlGenerators,
2931
shortStringHelper,
3032
contentTypeBaseServiceProvider,
31-
context))
33+
context,
34+
options))
3235
{
3336
}
3437

src/Umbraco.Infrastructure/Packaging/ImportPackageBuilderExpression.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
using System.Xml.Linq;
66
using System.Xml.XPath;
77
using Microsoft.Extensions.Logging;
8+
using Microsoft.Extensions.Options;
89
using Umbraco.Cms.Core;
10+
using Umbraco.Cms.Core.Configuration.Models;
911
using Umbraco.Cms.Core.IO;
1012
using Umbraco.Cms.Core.Models;
1113
using Umbraco.Cms.Core.Packaging;
@@ -25,7 +27,9 @@ internal class ImportPackageBuilderExpression : MigrationExpressionBase
2527
private readonly MediaUrlGeneratorCollection _mediaUrlGenerators;
2628
private readonly IPackagingService _packagingService;
2729
private readonly IShortStringHelper _shortStringHelper;
28-
private bool _executed;
30+
private readonly PackageMigrationSettings _packageMigrationSettings;
31+
32+
private bool _executed;
2933

3034
public ImportPackageBuilderExpression(
3135
IPackagingService packagingService,
@@ -34,14 +38,16 @@ public ImportPackageBuilderExpression(
3438
MediaUrlGeneratorCollection mediaUrlGenerators,
3539
IShortStringHelper shortStringHelper,
3640
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
37-
IMigrationContext context) : base(context)
41+
IMigrationContext context,
42+
IOptions<PackageMigrationSettings> packageMigrationSettings) : base(context)
3843
{
3944
_packagingService = packagingService;
4045
_mediaService = mediaService;
4146
_mediaFileManager = mediaFileManager;
4247
_mediaUrlGenerators = mediaUrlGenerators;
4348
_shortStringHelper = shortStringHelper;
4449
_contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
50+
_packageMigrationSettings = packageMigrationSettings.Value;
4551
}
4652

4753
/// <summary>
@@ -59,6 +65,7 @@ public override void Execute()
5965
}
6066

6167
_executed = true;
68+
6269
Context.BuildingExpression = false;
6370

6471
if (EmbeddedResourceMigrationType == null && PackageDataManifest == null)
@@ -67,6 +74,12 @@ public override void Execute()
6774
$"Nothing to execute, neither {nameof(EmbeddedResourceMigrationType)} or {nameof(PackageDataManifest)} has been set.");
6875
}
6976

77+
if (!_packageMigrationSettings.RunSchemaAndContentMigrations)
78+
{
79+
Logger.LogInformation("Skipping import of embedded schema file, due to configuration");
80+
return;
81+
}
82+
7083
InstallationSummary installationSummary;
7184
if (EmbeddedResourceMigrationType != null)
7285
{

src/Umbraco.Infrastructure/Packaging/PackageMigrationBase.cs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
using System;
2+
using System.ComponentModel;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.Options;
5+
using Umbraco.Cms.Core.Configuration.Models;
16
using Umbraco.Cms.Core.IO;
27
using Umbraco.Cms.Core.PropertyEditors;
38
using Umbraco.Cms.Core.Services;
49
using Umbraco.Cms.Core.Strings;
510
using Umbraco.Cms.Infrastructure.Migrations;
11+
using Umbraco.Cms.Web.Common.DependencyInjection;
612

713
namespace Umbraco.Cms.Infrastructure.Packaging
814
{
9-
1015
public abstract class PackageMigrationBase : MigrationBase
1116
{
1217
private readonly IPackagingService _packagingService;
@@ -15,6 +20,7 @@ public abstract class PackageMigrationBase : MigrationBase
1520
private readonly MediaUrlGeneratorCollection _mediaUrlGenerators;
1621
private readonly IShortStringHelper _shortStringHelper;
1722
private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider;
23+
private readonly IOptions<PackageMigrationSettings> _packageMigrationsSettings;
1824

1925
public PackageMigrationBase(
2026
IPackagingService packagingService,
@@ -23,7 +29,8 @@ public PackageMigrationBase(
2329
MediaUrlGeneratorCollection mediaUrlGenerators,
2430
IShortStringHelper shortStringHelper,
2531
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
26-
IMigrationContext context)
32+
IMigrationContext context,
33+
IOptions<PackageMigrationSettings> packageMigrationsSettings)
2734
: base(context)
2835
{
2936
_packagingService = packagingService;
@@ -32,6 +39,29 @@ public PackageMigrationBase(
3239
_mediaUrlGenerators = mediaUrlGenerators;
3340
_shortStringHelper = shortStringHelper;
3441
_contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
42+
_packageMigrationsSettings = packageMigrationsSettings;
43+
}
44+
45+
[EditorBrowsable(EditorBrowsableState.Never)]
46+
[Obsolete("Use ctor with all params")]
47+
public PackageMigrationBase(
48+
IPackagingService packagingService,
49+
IMediaService mediaService,
50+
MediaFileManager mediaFileManager,
51+
MediaUrlGeneratorCollection mediaUrlGenerators,
52+
IShortStringHelper shortStringHelper,
53+
IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
54+
IMigrationContext context)
55+
: this(
56+
packagingService,
57+
mediaService,
58+
mediaFileManager,
59+
mediaUrlGenerators,
60+
shortStringHelper,
61+
contentTypeBaseServiceProvider,
62+
context,
63+
StaticServiceProvider.Instance.GetRequiredService<IOptions<PackageMigrationSettings>>())
64+
{
3565
}
3666

3767
public IImportPackageBuilder ImportPackage => BeginBuild(
@@ -42,7 +72,8 @@ public PackageMigrationBase(
4272
_mediaUrlGenerators,
4373
_shortStringHelper,
4474
_contentTypeBaseServiceProvider,
45-
Context));
75+
Context,
76+
_packageMigrationsSettings));
4677

4778
}
4879
}

0 commit comments

Comments
 (0)