Hooks for tracking changes in CMS fields

Vote:
 

My goal is to set up a notification service via email that notifies subscribers when a particular field has changed in the CMS. Is there any hook for this already, e.g., diffing field values? 

#297663
Mar 03, 2023 21:17
Vote:
 

No there's isn't one. However, you can easily set one up using ContentEvents in CMS with very minimal code. 

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class ChangeEventInitialization : IInitializableModule
{
    var oldFieldValue = "";
    public void Initialize(InitializationEngine context)
    {
        var events = ServiceLocator.Current.GetInstance<IContentEvents>();
        events.PublishingContent += Events_PublishingContent;
    }
    private void Events_PublishingContent(object sender, EPiServer.ContentEventArgs e)
    {
         // Fetch the currently published version
         var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
         var publishedVersionOfPage = contentLoader.Get<IContent>(e.Content.ContentLink);
        // You can then do something like if (e.Content is SitePageData pageData) to get the pageData/contentData for pages/blocks to get the new value
        // Compare old with new and send email accordingly (use try/catch and other techniques based on requirements)
    }
    public void Uninitialize(InitializationEngine context)
    {
        var events = ServiceLocator.Current.GetInstance<IContentEvents>();
        events.PublishingContent -= Events_PublishingContent;
    }
}

 

#297744
Mar 04, 2023 23:39
Vote:
 

Thank you. I'm going to try implementing this as a proof of concept today. 

#297805
Mar 06, 2023 17:14
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.