From 20d6c7e536bbf1a13abfa688423ed0830d98ff24 Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Wed, 3 Mar 2021 15:09:42 +0000 Subject: [PATCH] Adds a new empty event with no extra data so we can subscribe when an Unattended install has completed --- .../Events/UnattendedInstallNotification.cs | 12 ++++++++++++ src/Umbraco.Infrastructure/RuntimeState.cs | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/Umbraco.Core/Events/UnattendedInstallNotification.cs diff --git a/src/Umbraco.Core/Events/UnattendedInstallNotification.cs b/src/Umbraco.Core/Events/UnattendedInstallNotification.cs new file mode 100644 index 0000000000..5bfb64e08f --- /dev/null +++ b/src/Umbraco.Core/Events/UnattendedInstallNotification.cs @@ -0,0 +1,12 @@ +using System; +using Umbraco.Cms.Core.Events; + +namespace Umbraco.Core.Events +{ + /// + /// Used to notify that an Unattended install has completed + /// + public class UnattendedInstallNotification : INotification + { + } +} diff --git a/src/Umbraco.Infrastructure/RuntimeState.cs b/src/Umbraco.Infrastructure/RuntimeState.cs index b62c30e4d2..4df0fac537 100644 --- a/src/Umbraco.Infrastructure/RuntimeState.cs +++ b/src/Umbraco.Infrastructure/RuntimeState.cs @@ -2,15 +2,16 @@ using System; using System.Threading; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Umbraco.Cms.Core; using Umbraco.Cms.Core.Configuration; using Umbraco.Cms.Core.Configuration.Models; +using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Exceptions; using Umbraco.Cms.Core.Semver; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Migrations.Install; using Umbraco.Cms.Infrastructure.Migrations.Upgrade; using Umbraco.Cms.Infrastructure.Persistence; +using Umbraco.Core.Events; namespace Umbraco.Cms.Core { @@ -24,6 +25,7 @@ namespace Umbraco.Cms.Core private readonly IUmbracoDatabaseFactory _databaseFactory; private readonly ILogger _logger; private readonly DatabaseSchemaCreatorFactory _databaseSchemaCreatorFactory; + private readonly IEventAggregator _eventAggregator; /// /// The initial @@ -42,13 +44,15 @@ namespace Umbraco.Cms.Core IUmbracoVersion umbracoVersion, IUmbracoDatabaseFactory databaseFactory, ILogger logger, - DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory) + DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory, + IEventAggregator eventAggregator) { _globalSettings = globalSettings.Value; _umbracoVersion = umbracoVersion; _databaseFactory = databaseFactory; _logger = logger; _databaseSchemaCreatorFactory = databaseSchemaCreatorFactory; + _eventAggregator = eventAggregator; } @@ -194,7 +198,7 @@ namespace Umbraco.Cms.Core Reason = reason; } - public void DoUnattendedInstall() + public async void DoUnattendedInstall() { // unattended install is not enabled if (_globalSettings.InstallUnattended == false) return; @@ -232,6 +236,11 @@ namespace Umbraco.Cms.Core creator.InitializeDatabaseSchema(); database.CompleteTransaction(); _logger.LogInformation("Unattended install completed."); + + // Emit an event with EventAggregator that unattended install completed + // Then this event can be listened for and create an unattended user + await _eventAggregator.PublishAsync(new UnattendedInstallNotification()); + } catch (Exception ex) {