Umbraco publishing API events: knowing what changed?
Hello
What is the official way in the Umbraco API to determine what changed during publication of a content item from the previous time it was published?
For example, my content item has a RTE body text property, and I would like to know if it changed and how (i.e. before and after state so that I can perform my own comparison on the delta/differences).
There is a method called IsPropertyDirty() that can be called to check if a property has changed. I know of nothing that can get you the original value, but you could roll your own code to do this
Snippet
using Umbraco.Core;
public class Register : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentService.Published += ContentService_Published;
}
private void ContentService_Published(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<IContent> e)
{
foreach (var newContent in e.PublishedEntities.Where(x => x.IsPropertyDirty("bodyText"))
{
var originalContent = Umbraco.Web.UmbracoContext.Current.ContentCache.GetById(newContent.Id);
// now compare newContent.GetValue("bodyText") vs originalContent.GetPropertyValue("bodyText")
}
}
}
You are correct, you did specify publishing event. I was lazy and copied my code from a Published event, strangely I do also have a publishing event I could have used, but for some reason ignored it, because it was bigger.
Umbraco publishing API events: knowing what changed?
Hello
What is the official way in the Umbraco API to determine what changed during publication of a content item from the previous time it was published? For example, my content item has a RTE body text property, and I would like to know if it changed and how (i.e. before and after state so that I can perform my own comparison on the delta/differences).
Thanks Andrew
Hi
There is a method called IsPropertyDirty() that can be called to check if a property has changed. I know of nothing that can get you the original value, but you could roll your own code to do this
Snippet
Cheers
great thank you. btw I think you meant the ContentService.Publishing rather than ContentService.Published event.
You are correct, you did specify publishing event. I was lazy and copied my code from a Published event, strangely I do also have a publishing event I could have used, but for some reason ignored it, because it was bigger.
Oh well, I'm sure you can amend accordingly.
is working on a reply...