Only trigger publish events when caused by an editor

Vote:
 

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
Vote:
 

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
Vote:
 

Hi Toft,

Try SaveAction.Patch

#195091
Jul 13, 2018 7:18
Ted
Vote:
 

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>();

userImpersonation.CreatePrincipal("SomeServiceAccount");

// 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
Vote:
 

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

#195096
Jul 13, 2018 10:06
Vote:
 

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
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.