From 5cd2d568e39c9c7180ced2d985b20c2a4a9773b1 Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Fri, 22 Mar 2013 11:12:32 -0100 Subject: [PATCH] Fixes U4-1938 by actually calling and checking the Before/AfterDelete events for DataTypeDefinitions. Backported from 32fb51f603a3 --- .../datatype/DataTypeDefinition.cs | 64 +++++++++++++++---- 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/src/umbraco.cms/businesslogic/datatype/DataTypeDefinition.cs b/src/umbraco.cms/businesslogic/datatype/DataTypeDefinition.cs index 4633085987..4040f81409 100644 --- a/src/umbraco.cms/businesslogic/datatype/DataTypeDefinition.cs +++ b/src/umbraco.cms/businesslogic/datatype/DataTypeDefinition.cs @@ -5,6 +5,7 @@ using System.Collections; using System.Linq; using umbraco.DataLayer; using System.Xml; +using umbraco.cms.businesslogic.media; using umbraco.interfaces; using umbraco.cms.businesslogic.propertytype; @@ -80,21 +81,28 @@ namespace umbraco.cms.businesslogic.datatype #region Public methods public override void delete() { - //first clear the prevalues - PreValues.DeleteByDataTypeDefinition(this.Id); - - //next clear out the property types - var propTypes = PropertyType.GetByDataTypeDefinition(this.Id); - foreach (var p in propTypes) + DeleteEventArgs e = new DeleteEventArgs(); + FireBeforeDelete(e); + if (!e.Cancel) { - p.delete(); + //first clear the prevalues + PreValues.DeleteByDataTypeDefinition(this.Id); + + //next clear out the property types + var propTypes = PropertyType.GetByDataTypeDefinition(this.Id); + foreach (var p in propTypes) + { + p.delete(); + } + + //delete the cmsDataType role, then the umbracoNode + SqlHelper.ExecuteNonQuery("delete from cmsDataType where nodeId=@nodeId", + SqlHelper.CreateParameter("@nodeId", this.Id)); + base.delete(); + + cache.Cache.ClearCacheItem(string.Format("UmbracoDataTypeDefinition{0}", Id)); + FireAfterDelete(e); } - - //delete the cmsDataType role, then the umbracoNode - SqlHelper.ExecuteNonQuery("delete from cmsDataType where nodeId=@nodeId", SqlHelper.CreateParameter("@nodeId", this.Id)); - base.delete(); - - cache.Cache.ClearCacheItem(string.Format("UmbracoDataTypeDefinition{0}", Id)); } [Obsolete("Use the standard delete() method instead")] @@ -363,12 +371,42 @@ namespace umbraco.cms.businesslogic.datatype New(this, e); } + [Obsolete("This event is not used! Use the BeforeDelete or AfterDelete events")] public static event DeleteEventHandler Deleting; protected virtual void OnDeleting(EventArgs e) { if (Deleting != null) Deleting(this, e); } + + /// + /// Occurs when [before delete]. + /// + public new static event DeleteEventHandler BeforeDelete; + /// + /// Raises the event. + /// + /// The instance containing the event data. + protected new virtual void FireBeforeDelete(DeleteEventArgs e) + { + if (BeforeDelete != null) + BeforeDelete(this, e); + } + + /// + /// Occurs when [after delete]. + /// + public new static event DeleteEventHandler AfterDelete; + /// + /// Raises the event. + /// + /// The instance containing the event data. + protected new virtual void FireAfterDelete(DeleteEventArgs e) + { + if (AfterDelete != null) + AfterDelete(this, e); + } + #endregion }