Update page programatically without triggering ContentEvents

Vote:
 

I have a pagetype with some code in the event contentEvents.PublishedContent. Is it possible to update a page of this type without triggering the event. When editors update the page, I still want the event to be triggered.

I can use SaveAction.SkipValidation to skip validation, but is there a way to skip content events?

#210603
Nov 29, 2019 13:25
Vote:
 

There is no way to supress the events that I know of, but you can probably tackle the problem from a different perspective, like you can convert the IContent in PublishedContent event to, IChangeTrackable, and check if ChangedBy is something that assigned specifically for code or not before processing.

#210606
Nov 29, 2019 14:13
Vote:
 

Thank you Quan.

I ended up checking if SaveContentEventArgs.ForceCurrentVersion was true. For my use case, ForceCurrentVersion is set when I change this specific page from code.

#210607
Nov 29, 2019 14:23
Vote:
 

Quan: I'm not sure if I understood you correctly. In my use case, Changed By will be the username of the logged-in user using the admin tool that updates the pages programmatically. Because of the need for tracability, I can not change this to a pseudo-username like «update-by-code-user».

Is there some other property I can set during save, that I can check in ContentEvents. I do not actually want to ForceCurrentVersion, but instead create a new version of the content.

#210722
Dec 04, 2019 10:48
Vote:
 

In the PublishedContent event, you can look at the "SaveContentEventArgs.Transition".

For programmatic publishing it should be "Published -> Published", and for manual publishing it should be "CheckedOut -> Published"

#210741
Dec 04, 2019 12:28
Tomas Hensrud Gulla - Dec 05, 2019 10:16
Thanks! :-)