Only trigger publish events when caused by an editor

Toft Stade
Member since: 2009

My goal is to trigger publish events only when a page is published by an editor or a certain condition is met.

We have some jobs that parse, populate and republishes content on a regular basis but I would like to not trigger publish events when triggered by jobs. 

Any ideas?

#195058 Jul 12, 2018 11:25
  • Toft Stade
    Member since: 2009

    I solved it for now by always using SaveAction.ForceCurrentVersion when saving from job and do a check in the event if SaveContentEventArgs.ForceCurrentVersion is true.

    #195062 Edited, Jul 12, 2018 12:56

    Hi Toft,

    Try SaveAction.Patch

    #195091 Jul 13, 2018 7:18
  • Ted
    Member since: 2006

    We usually set up a "service account" user to use for automated tasks, such as scheduled jobs, etc.

    var humanUser = PrincipalInfo.CurrentPrincipal;
    var userImpersonation = ServiceLocator.Current.GetInstance<IUserImpersonation>();
    // Do work as 'SomeServiceAccount'
    PrincipalInfo.CurrentPrincipal = humanUser;

    This way we get more relevant version history (as we can see what has been done by an editor and what has been done by an integration, scheduled job, or such) and at the same time we can use current user info to determine whether specific validation should take place.

    It also avoids scheduled jobs being run as anonymous users, forcing developers to add SaveAction.NoAccess when working with IContentRepository methods.

    I realize this doesn't exactly answer your original question, but suppressing/avoiding publishing events can have adverse (unintentional) side-effects. :)

    #195093 Edited, Jul 13, 2018 9:01
  • Toft Stade
    Member since: 2009

    Yes, I found that one soon after posting, very useful.

    #195096 Jul 13, 2018 10:06
  • Toft Stade
    Member since: 2009

    This looks exactly like what we'll set up when we find SaveAction.Patch isn't enough. Thank you.

    #195097 Jul 13, 2018 10:08