diff --git a/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs b/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs index 4fad123548..63767fbdc4 100644 --- a/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs +++ b/src/Umbraco.Core/Migrations/Install/DatabaseBuilder.cs @@ -89,6 +89,29 @@ namespace Umbraco.Core.Migrations.Install return DbConnectionExtensions.IsConnectionAvailable(connectionString, providerName); } + internal bool HasSomeNonDefaultUser() + { + using (var scope = _scopeProvider.CreateScope()) + { + // look for the super user with default password + var sql = scope.Database.SqlContext.Sql() + .SelectCount() + .From() + .Where(x => x.Id == Constants.Security.SuperUserId && x.Password == "default"); + var result = scope.Database.ExecuteScalar(sql); + var has = result != 1; + if (has == false) + { + // found only 1 user == the default user with default password + // however this always exists on uCloud, also need to check if there are other users too + result = scope.Database.ExecuteScalar("SELECT COUNT(*) FROM umbracoUser"); + has = result != 1; + } + scope.Complete(); + return has; + } + } + internal bool IsUmbracoInstalled() { using (var scope = _scopeProvider.CreateScope(autoComplete: true)) diff --git a/src/Umbraco.Core/RuntimeOptions.cs b/src/Umbraco.Core/RuntimeOptions.cs index 8870bd9eb3..413c022721 100644 --- a/src/Umbraco.Core/RuntimeOptions.cs +++ b/src/Umbraco.Core/RuntimeOptions.cs @@ -47,14 +47,12 @@ namespace Umbraco.Core /// /// /// By default, when a database connection string is configured and it is possible to connect to - /// the database, but the database is empty, the runtime enters the BootFailed level. If this options - /// is set to true, it enters the Install level instead. - /// It is then up to the implementor, that is setting this value, to take over the installation - /// sequence. + /// the database, but the database is empty, the runtime enters the Install level. If this options + /// is set to false, it enters the BootFailed level instead. /// public static bool InstallEmptyDatabase { - get => _installEmptyDatabase ?? BoolSetting("Umbraco.Core.RuntimeState.InstallEmptyDatabase", false); + get => _installEmptyDatabase ?? BoolSetting("Umbraco.Core.RuntimeState.InstallEmptyDatabase", true); set => _installEmptyDatabase = value; } @@ -63,12 +61,13 @@ namespace Umbraco.Core /// /// /// By default, when a database connection string is configured and it is possible to connect to - /// the database, but the database is empty, an unattended install will be performed. If this options - /// is set to false, it enters the Install level instead. + /// the database, but the database is empty, the runtime enters the Install level. + /// If this option is set to true an unattended install will be performed and the runtime enters + /// the Run level. /// public static bool InstallUnattended { - get => _installUnattended ?? BoolSetting("Umbraco.Core.RuntimeState.InstallUnattended", true); + get => _installUnattended ?? BoolSetting("Umbraco.Core.RuntimeState.InstallUnattended", false); set => _installUnattended = value; } diff --git a/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs b/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs index f9ae40b52b..10f251d2e1 100644 --- a/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs @@ -141,14 +141,15 @@ namespace Umbraco.Web.Install.InstallSteps // left a version number in there but cleared out their db conn string, in that case, it's really a new install. if (_globalSettings.ConfigurationStatus.IsNullOrWhiteSpace() == false && databaseSettings != null) return false; - if (_databaseBuilder.IsConnectionStringConfigured(databaseSettings) && _databaseBuilder.IsDatabaseConfigured) - return _databaseBuilder.IsUmbracoInstalled() == false; + // if Umbraco is already installed there's already users in the database, skip this step + if (_databaseBuilder.IsConnectionStringConfigured(databaseSettings) && _databaseBuilder.IsDatabaseConfigured && _databaseBuilder.IsUmbracoInstalled()) + return _databaseBuilder.HasSomeNonDefaultUser() == false; // In this one case when it's a brand new install and nothing has been configured, make sure the // back office cookie is cleared so there's no old cookies lying around causing problems _http.ExpireCookie(Current.Configs.Settings().Security.AuthCookieName); - return true; + return true; } } }