Updates the PetaPocoRepositoryBase to ensure that the deletion process is wrapped in a transaction so if any of the processes fail, it all gets rolled back.

This commit is contained in:
Shannon
2013-08-09 10:07:03 +10:00
parent 1e61563f79
commit ce847e97a8

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Persistence.Caching;
using Umbraco.Core.Persistence.Querying;
@@ -69,10 +70,26 @@ namespace Umbraco.Core.Persistence.Repositories
protected override void PersistDeletedItem(TEntity entity)
{
var deletes = GetDeleteClauses();
foreach (var delete in deletes)
//wrap in a transaction in case any of the delete processes fail so they'll get rolled back!
using (var trans = Database.GetTransaction())
{
Database.Execute(delete, new {Id = entity.Id});
try
{
foreach (var delete in deletes)
{
Database.Execute(delete, new { Id = entity.Id });
}
trans.Complete();
}
catch (Exception ex)
{
trans.Dispose();
LogHelper.Error(GetType(), "Deletion process failed, transaction rolled back", ex);
throw;
}
}
}
}
}