Stuck in publishing loop

Vote:
 

Essentially, I'm attaching to the publishing event like so

contentEvents.PublishedContent += MyMethodOnPublish;

then eventually saving my content like so

contentRepository.Save(editablePage, SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);

but then the event for the content keeps getting called in an infinite loop, which kinda makes sense but obviously is not the desired behaviour, is there a recommended method to prevent this publishing loop?

using CMS 11.11.1.0

#208682
Edited, Oct 31, 2019 22:50
Vote:
 

Hi Noel

You don't need to save the content inside the event handler.

If you make any changes to the content being published, it will be saved right after your event handler. Unless you cancel the action, of course.

#208687
Oct 30, 2019 12:20
Vote:
 

To be more cleare on what Stefan says,

You need attach to contentEvents.PublishingContent instead of contentEvents.PublishedContent

Then you can change the content, and don't need to call the save method again.

#208700
Oct 30, 2019 13:11
Vote:
 

Thank you @Stefan and @Sebbe, yeah Stefan was mostly correct, except if using Published (instead of Publishing) then it complains about the properties being read-only.

#208702
Oct 30, 2019 13:13
Stefan Holm Olsen - Oct 30, 2019 13:22
Yeah. I mixed up those names when reading your post. Glad it works anyway.
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.