Update page programatically without triggering ContentEvents


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?

Nov 29, 2019 13:25

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.

Nov 29, 2019 14:13

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.

Nov 29, 2019 14:23

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.

Dec 04, 2019 10:48

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"

Dec 04, 2019 12:28
- Dec 05, 2019 10:16
Thanks! :-)
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.