Sitecore inserting element data integrity

When you insert an element into Sitecore, you use the following code:

Item newItem = parentItem.Add("NameOfNewItem", template); 

Then you edit the item.

Then you save the item.

If the error occurs in the middle, AFTER the parentItem.Add command parentItem.Add fields of the new element are not saved, but the child element is created and placed in the content tree anyway, so we have an incomplete element in (really wrong).

Is it possible to insert an element in these lines?

  • create item
  • fill item
  • finally add the filled item to the content tree.

In other words, is there a way to put parentItem.Add at the end of the whole process?

This will really help improve data integrity.

+4
source share
2 answers

Basically you are asking for a way to use transactions to create an item.

This is not supported by Sitecore 6. It was mentioned (a couple of years ago) that Sitecore 7 would support transactions.

+1
source

Out of the box, I don't think transactions are supported. There's a good article on Sitecore and Item transactions here , which implements a unit of work similar to the approach for approximating atomic actions to elements.

The Sitecore build engine internally provides transactional support for operations that require it. The API does not seem to disclose this feature or allow access to the IDbConnection database.

 public virtual DataProviderTransaction CreateTransaction(); Declaring Type: Sitecore.Data.DataProviders.Sql.SqlDataApi Assembly: Sitecore.Kernel, Version=6.0.0.0 
+2
source

Source: https://habr.com/ru/post/1436648/


All Articles