@@ -40,7 +40,8 @@ public class SqlMainDomLock : IMainDomLock
40
40
private bool _errorDuringAcquiring ;
41
41
private readonly object _locker = new object ( ) ;
42
42
private bool _hasTable = false ;
43
-
43
+ private bool _acquireWhenTablesNotAvailable = false ;
44
+
44
45
public SqlMainDomLock (
45
46
ILogger < SqlMainDomLock > logger ,
46
47
ILoggerFactory loggerFactory ,
@@ -99,7 +100,8 @@ public async Task<bool> AcquireLockAsync(int millisecondsTimeout)
99
100
_hasTable = db . HasTable ( Cms . Core . Constants . DatabaseSchema . Tables . KeyValue ) ;
100
101
if ( ! _hasTable )
101
102
{
102
- // the Db does not contain the required table, we must be in an install state we have no choice but to assume we can acquire
103
+ _logger . LogDebug ( "The DB does not contain the required table so we must be in an install state. We have no choice but to assume we can acquire." ) ;
104
+ _acquireWhenTablesNotAvailable = true ;
103
105
return true ;
104
106
}
105
107
@@ -225,6 +227,13 @@ private void ListeningLoop()
225
227
}
226
228
}
227
229
230
+ // In case we acquired the main dom doing install when there was no database. We therefore have to insert our lockId now, but only handle this once.
231
+ if ( _acquireWhenTablesNotAvailable )
232
+ {
233
+ _acquireWhenTablesNotAvailable = false ;
234
+ InsertLockRecord ( _lockId , db ) ;
235
+ }
236
+
228
237
db . BeginTransaction ( IsolationLevel . ReadCommitted ) ;
229
238
// get a read lock
230
239
_sqlServerSyntax . ReadLock ( db , Cms . Core . Constants . Locks . MainDom ) ;
@@ -434,7 +443,10 @@ private RecordPersistenceType InsertLockRecord(string id, IUmbracoDatabase db)
434
443
private bool IsMainDomValue ( string val , IUmbracoDatabase db )
435
444
{
436
445
return db . ExecuteScalar < int > ( "SELECT COUNT(*) FROM umbracoKeyValue WHERE [key] = @key AND [value] = @val" ,
437
- new { key = MainDomKey , val = val } ) == 1 ;
446
+ new { key = MainDomKey , val = val } ) == 1 ;
447
+
448
+
449
+
438
450
}
439
451
440
452
/// <summary>
@@ -447,6 +459,7 @@ private bool IsMainDomValue(string val, IUmbracoDatabase db)
447
459
#region IDisposable Support
448
460
private bool _disposedValue = false ; // To detect redundant calls
449
461
462
+
450
463
protected virtual void Dispose ( bool disposing )
451
464
{
452
465
if ( ! _disposedValue )
0 commit comments