Allow installing when connection string is configured
Disable unattended installs by default and enable install empty database. Fix create user step by adding back the HasSomeNonDefaultUser check, if the check is missing the installer will skip creating the configured user since the second time NewInstallStep.RequiresExecution is called, Umbraco has been installed and it would return false and the user would never be created.
This commit is contained in:
@@ -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<UserDto>()
|
||||
.Where<UserDto>(x => x.Id == Constants.Security.SuperUserId && x.Password == "default");
|
||||
var result = scope.Database.ExecuteScalar<int>(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<int>("SELECT COUNT(*) FROM umbracoUser");
|
||||
has = result != 1;
|
||||
}
|
||||
scope.Complete();
|
||||
return has;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool IsUmbracoInstalled()
|
||||
{
|
||||
using (var scope = _scopeProvider.CreateScope(autoComplete: true))
|
||||
|
||||
@@ -47,14 +47,12 @@ namespace Umbraco.Core
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>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.</para>
|
||||
/// <para>It is then up to the implementor, that is setting this value, to take over the installation
|
||||
/// sequence.</para>
|
||||
/// the database, but the database is empty, the runtime enters the <c>Install</c> level. If this options
|
||||
/// is set to <c>false</c>, it enters the <c>BootFailed</c> level instead.</para>
|
||||
/// </remarks>
|
||||
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
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>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 <c>false</c>, it enters the Install level instead.</para>
|
||||
/// the database, but the database is empty, the runtime enters the <c>Install</c> level.
|
||||
/// If this option is set to <c>true</c> an unattended install will be performed and the runtime enters
|
||||
/// the <c>Run</c> level.</para>
|
||||
/// </remarks>
|
||||
public static bool InstallUnattended
|
||||
{
|
||||
get => _installUnattended ?? BoolSetting("Umbraco.Core.RuntimeState.InstallUnattended", true);
|
||||
get => _installUnattended ?? BoolSetting("Umbraco.Core.RuntimeState.InstallUnattended", false);
|
||||
set => _installUnattended = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user