Removed unnecessary call to DistributedLockSchemaBuilder.

Also added code to commit the transaction if the schema was created so that it can be used in the same request (DataMigrationManager is doing the same after each migration).
This commit is contained in:
Sipke Schoorstra
2015-09-08 20:56:28 +01:00
parent 94db186b37
commit e9f883c296
4 changed files with 9 additions and 9 deletions

View File

@@ -23,7 +23,6 @@ using Orchard.Recipes.Models;
using Orchard.Recipes.Services; using Orchard.Recipes.Services;
using Orchard.Security; using Orchard.Security;
using Orchard.Settings; using Orchard.Settings;
using Orchard.Tasks.Locking.Services;
using Orchard.Utility.Extensions; using Orchard.Utility.Extensions;
namespace Orchard.Setup.Services { namespace Orchard.Setup.Services {
@@ -155,10 +154,6 @@ namespace Orchard.Setup.Services {
schemaBuilder.AlterTable("Orchard_Framework_DataMigrationRecord", schemaBuilder.AlterTable("Orchard_Framework_DataMigrationRecord",
table => table.AddUniqueConstraint("UC_DMR_DataMigrationClass_Version", "DataMigrationClass", "Version")); table => table.AddUniqueConstraint("UC_DMR_DataMigrationClass_Version", "DataMigrationClass", "Version"));
// Create the distributed lock record schema.
var distributedLockSchemaBuilder = new DistributedLockSchemaBuilder(_shellSettings, schemaBuilder);
distributedLockSchemaBuilder.CreateSchema();
var dataMigrationManager = environment.Resolve<IDataMigrationManager>(); var dataMigrationManager = environment.Resolve<IDataMigrationManager>();
dataMigrationManager.Update("Settings"); dataMigrationManager.Update("Settings");

View File

@@ -18,18 +18,21 @@ namespace Orchard.Data.Migration {
private readonly IDistributedLockService _distributedLockService; private readonly IDistributedLockService _distributedLockService;
private readonly IDataMigrationInterpreter _dataMigrationInterpreter; private readonly IDataMigrationInterpreter _dataMigrationInterpreter;
private readonly ShellSettings _shellSettings; private readonly ShellSettings _shellSettings;
private readonly ITransactionManager _transactionManager;
public AutomaticDataMigrations( public AutomaticDataMigrations(
IDataMigrationManager dataMigrationManager, IDataMigrationManager dataMigrationManager,
IDataMigrationInterpreter dataMigrationInterpreter, IDataMigrationInterpreter dataMigrationInterpreter,
IFeatureManager featureManager, IFeatureManager featureManager,
IDistributedLockService distributedLockService, IDistributedLockService distributedLockService,
ITransactionManager transactionManager,
ShellSettings shellSettings) { ShellSettings shellSettings) {
_dataMigrationManager = dataMigrationManager; _dataMigrationManager = dataMigrationManager;
_featureManager = featureManager; _featureManager = featureManager;
_distributedLockService = distributedLockService; _distributedLockService = distributedLockService;
_shellSettings = shellSettings; _shellSettings = shellSettings;
_transactionManager = transactionManager;
_dataMigrationInterpreter = dataMigrationInterpreter; _dataMigrationInterpreter = dataMigrationInterpreter;
Logger = NullLogger.Instance; Logger = NullLogger.Instance;
@@ -77,7 +80,8 @@ namespace Orchard.Data.Migration {
// Ensure the distributed lock record schema exists. // Ensure the distributed lock record schema exists.
var schemaBuilder = new SchemaBuilder(_dataMigrationInterpreter); var schemaBuilder = new SchemaBuilder(_dataMigrationInterpreter);
var distributedLockSchemaBuilder = new DistributedLockSchemaBuilder(_shellSettings, schemaBuilder); var distributedLockSchemaBuilder = new DistributedLockSchemaBuilder(_shellSettings, schemaBuilder);
distributedLockSchemaBuilder.EnsureSchema(); if (distributedLockSchemaBuilder.EnsureSchema())
_transactionManager.RequireNew();
} }
} }
} }

View File

@@ -13,11 +13,12 @@ namespace Orchard.Tasks.Locking.Services {
_schemaBuilder = schemaBuilder; _schemaBuilder = schemaBuilder;
} }
public void EnsureSchema() { public bool EnsureSchema() {
if (SchemaExists()) if (SchemaExists())
return; return false;
CreateSchema(); CreateSchema();
return true;
} }
public void CreateSchema() { public void CreateSchema() {

View File

@@ -110,7 +110,7 @@ namespace Orchard.Tasks.Locking.Services {
); );
}); });
return result; return result;
} }
private DistributedLock AcquireLockInternal(string name, TimeSpan? maxValidFor) { private DistributedLock AcquireLockInternal(string name, TimeSpan? maxValidFor) {