Skip to content

Instantly share code, notes, and snippets.

@harmony7
Created April 14, 2014 06:43
Show Gist options
  • Save harmony7/10621982 to your computer and use it in GitHub Desktop.
Save harmony7/10621982 to your computer and use it in GitHub Desktop.
RouteController transaction fix
diff --git a/src/Orchard.Web/Modules/Upgrade/Controllers/RouteController.cs b/src/Orchard.Web/Modules/Upgrade/Controllers/RouteController.cs
--- a/src/Orchard.Web/Modules/Upgrade/Controllers/RouteController.cs
+++ b/src/Orchard.Web/Modules/Upgrade/Controllers/RouteController.cs
@@ -25,6 +25,7 @@
public class RouteController : Controller {
private readonly IContentDefinitionManager _contentDefinitionManager;
private readonly IOrchardServices _orchardServices;
+ private readonly ITransactionManager _transactionManager;
private readonly ISessionFactoryHolder _sessionFactoryHolder;
private readonly ShellSettings _shellSettings;
private readonly IAutorouteService _autorouteService;
@@ -33,12 +34,14 @@
public RouteController(
IContentDefinitionManager contentDefinitionManager,
IOrchardServices orchardServices,
+ ITransactionManager transactionManager,
ISessionFactoryHolder sessionFactoryHolder,
ShellSettings shellSettings,
IAutorouteService autorouteService,
IReportsCoordinator reportsCoordinator) {
_contentDefinitionManager = contentDefinitionManager;
_orchardServices = orchardServices;
+ _transactionManager = transactionManager;
_sessionFactoryHolder = sessionFactoryHolder;
_shellSettings = shellSettings;
_autorouteService = autorouteService;
@@ -84,12 +87,16 @@
_reportsCoordinator.Information("Migration", "Adding parts to " + contentType);
+ _transactionManager.RequireNew(System.Data.IsolationLevel.Serializable); // this will create a new transaction
+
// migrating parts
_contentDefinitionManager.AlterTypeDefinition(contentType,
builder => builder
.WithPart("AutoroutePart")
.WithPart("TitlePart"));
+ _transactionManager.RequireNew(System.Data.IsolationLevel.Serializable); // this will commit current transaction
+
// force the first object to be reloaded in order to get a valid AutoroutePart
_orchardServices.ContentManager.Clear();
@@ -110,7 +117,8 @@
isContainable = true;
}
- using (new TransactionScope(TransactionScopeOption.RequiresNew)) {
+ _transactionManager.RequireNew(System.Data.IsolationLevel.Serializable); // this will create a new transaction
+ {
var command = session.Connection.CreateCommand();
command.CommandText = string.Format(@"
SELECT Title, Path FROM {0}
@@ -139,6 +147,7 @@
errors = true;
}
}
+ _transactionManager.RequireNew(System.Data.IsolationLevel.Serializable); // this will commit current transaction
count++;
}
@@ -146,6 +155,8 @@
_orchardServices.ContentManager.Clear();
} while (contents.Any());
+
+ _transactionManager.RequireNew(System.Data.IsolationLevel.Serializable); // this will create a new transaction
_contentDefinitionManager.AlterTypeDefinition(contentType, builder => builder.RemovePart("RoutePart"));
@@ -157,6 +168,8 @@
_autorouteService.CreatePattern(contentType, "Title", "{Content.Slug}", "my-sample-title", true);
}
+ _transactionManager.RequireNew(System.Data.IsolationLevel.Serializable); // this will commit current transaction
+
if (errors) {
_orchardServices.Notifier.Warning(T("Some content items could not be imported. Please refer to the corresponding Report."));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment