Skip to content

Commit

Permalink
Avoid breaking changes from merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
bergmania committed Oct 4, 2021
1 parent 779f3b7 commit fed6eaa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
37 changes: 28 additions & 9 deletions src/Umbraco.Infrastructure/Persistence/UmbracoDatabaseFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NPoco;
using NPoco.FluentMappings;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Infrastructure.Migrations.Install;
using Umbraco.Cms.Infrastructure.Persistence.FaultHandling;
Expand Down Expand Up @@ -72,21 +73,21 @@ private DbProviderFactory DbProviderFactory

#region Constructors

/// <summary>

/// <summary>
/// Initializes a new instance of the <see cref="UmbracoDatabaseFactory"/>.
/// </summary>
/// <remarks>Used by the other ctor and in tests.</remarks>
public UmbracoDatabaseFactory(
internal UmbracoDatabaseFactory(
ILogger<UmbracoDatabaseFactory> logger,
ILoggerFactory loggerFactory,
IOptions<GlobalSettings> globalSettings,
IOptionsMonitor<ConnectionStrings> connectionStrings,
IMapperCollection mappers,
IDbProviderFactoryCreator dbProviderFactoryCreator,
DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory,
NPocoMapperCollection npocoMappers)
NPocoMapperCollection npocoMappers,
string connectionString)
{

_globalSettings = globalSettings;
_mappers = mappers ?? throw new ArgumentNullException(nameof(mappers));
_dbProviderFactoryCreator = dbProviderFactoryCreator ?? throw new ArgumentNullException(nameof(dbProviderFactoryCreator));
Expand All @@ -95,22 +96,40 @@ public UmbracoDatabaseFactory(
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_loggerFactory = loggerFactory;

var settings = connectionStrings.CurrentValue.UmbracoConnectionString;
if (settings == null)
if (connectionString is null)
{
logger.LogDebug("Missing connection string, defer configuration.");
return; // not configured
}

var configConnectionString = new ConfigConnectionString("Custom", connectionString);
// could as well be <add name="umbracoDbDSN" connectionString="" providerName="" />
// so need to test the values too
if (settings.IsConnectionStringConfigured() == false)
if (configConnectionString.IsConnectionStringConfigured() == false)
{
logger.LogDebug("Empty connection string or provider name, defer configuration.");
return; // not configured
}

Configure(settings.ConnectionString, settings.ProviderName);
Configure(configConnectionString.ConnectionString, configConnectionString.ProviderName);
}

/// <summary>
/// Initializes a new instance of the <see cref="UmbracoDatabaseFactory"/>.
/// </summary>
/// <remarks>Used by the other ctor and in tests.</remarks>
public UmbracoDatabaseFactory(
ILogger<UmbracoDatabaseFactory> logger,
ILoggerFactory loggerFactory,
IOptions<GlobalSettings> globalSettings,
IOptionsMonitor<ConnectionStrings> connectionStrings,
IMapperCollection mappers,
IDbProviderFactoryCreator dbProviderFactoryCreator,
DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory,
NPocoMapperCollection npocoMappers):
this(logger, loggerFactory, globalSettings, mappers, dbProviderFactoryCreator, databaseSchemaCreatorFactory, npocoMappers, connectionStrings?.CurrentValue?.UmbracoConnectionString?.ConnectionString)
{

}

#endregion
Expand Down
14 changes: 3 additions & 11 deletions src/Umbraco.Infrastructure/Runtime/SqlMainDomLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public SqlMainDomLock(
loggerFactory.CreateLogger<UmbracoDatabaseFactory>(),
loggerFactory,
_globalSettings,
connectionStrings,
new MapperCollection(() => Enumerable.Empty<BaseMapper>()),
dbProviderFactoryCreator,
databaseSchemaCreatorFactory,
npocoMappers);
npocoMappers,
connectionStringName);
MainDomKey = MainDomKeyPrefix + "-" + (Environment.MachineName + MainDom.GetMainDomId(_hostingEnvironment)).GenerateHash<SHA1>();
}

Expand All @@ -88,18 +88,10 @@ public SqlMainDomLock(
hostingEnvironment,
databaseSchemaCreatorFactory,
npocoMappers,
Constants.System.UmbracoConnectionName
connectionStrings.CurrentValue.UmbracoConnectionString.ConnectionString
)
{

loggerFactory.CreateLogger<UmbracoDatabaseFactory>(),
loggerFactory,
_globalSettings,
connectionStrings,
new MapperCollection(() => Enumerable.Empty<BaseMapper>()),
dbProviderFactoryCreator,
databaseSchemaCreatorFactory,
npocoMappers);
}

public async Task<bool> AcquireLockAsync(int millisecondsTimeout)
Expand Down

0 comments on commit fed6eaa

Please sign in to comment.