Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Feb 27, 2014 @ 12:47
    Dan Diplo
    0

    ContentService.Saving event in 6.1.6 doesn't match documentation

    So I've read in the official documentation that you should no longer use the ContentService.Created event anymore manipulate new documents:

    "Both the ContentService.Creating and ContentService.Created events have been obsoleted."

    Instead it says to use the ContentService.Saving method:

    "The ContentService.Saving and ContentService.Saved events will always trigger before and after an entity has been persisted. You can determine if an entity is brand new in either of those events. In the Saving event - before the entity is persisted - you can check the entity's HasIdentity property which will be 'false' if it is brand new."

    However, I've just checked, and when I create a brand new content node in 6.1.6 the HasIdentity property is actually set to true in the Saving event. This contradicts the documentation.

    Example Code

    public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        ContentService.Saving += ContentService_Saving;
    }
    void ContentService_Saving(IContentService service, Umbraco.Core.Events.SaveEventArgs<IContent> e)
    {
        foreach (var doc in e.SavedEntities)
        {
            // Check whether it is a new item - this replaces ContentService.Creating
            if (!doc.HasIdentity)
            {
          // doc.HasIdentity == true even when creating a brand new document
            }
        }
    }
    
    Can anyone shed any light on whether this is a bug or whether the documentation is wrong?
Please Sign in or register to post replies

Write your reply to:

Draft