1

I have an application that uses a combination of ContentService.Saved & ContentService.Saving to extend Umbraco to manage content.

I have two websites in one Umbraco installation I am using those methods to keep content up to date in different parts of the tree.

So far I have got everything working the way I wanted to.

Now I want to add a feature that: depending on which Umbraco User is logged in, will either publish the content or simply send it for approval.

So I have changed some lines of code from:

cs.SaveAndPublishWithStatus(savedNode, 0, false)

To this:

cs.SendToPublication(savedNode);

Now the problem that I am finding is that unlike the SaveAndPublishWithStatus() method, the cs.SendToPublication(); doesn't have the option of passing false so that a save event is not raised. So I get into an infinite loop.

When I attach the debugger and manually stop the infinite loop the first time it calls cs.SendToPublication(savedNode); I get exactly the behavior I want.

Any ideas about how I can get round this problem? Is there a different method that I should be using?

Claus
  • 1,975
  • 18
  • 24
Ayo Adesina
  • 2,231
  • 3
  • 37
  • 71
  • Is there a reason why you're doing this in code instead of based on user roles? – Mark Feb 01 '17 at 14:05
  • Yes, this Umbraco installation is driving two websites. When a user updates content in Site 1, this change is reflected in Site 2 (automatically), but before it is actually published in to site 2, it needs to be authorized by the manager of site two. – Ayo Adesina Feb 01 '17 at 14:22
  • 1
    Ah I see, I don't have an answer for you but maybe if you look up the code of the ContentService you'll find answers https://github.com/umbraco/Umbraco-CMS/blob/10b8fd9fb973ddb9b86ebf4e0f5755c43cd22496/src/Umbraco.Core/Services/ContentService.cs – Mark Feb 01 '17 at 14:35

1 Answers1

0

You are correct in saying that it currently isn't possible to set raiseEvents to false when sending an item to publication - that's a problem. I've added that overload in v. 7.6 (http://issues.umbraco.org/issue/U4-9490).

However considering that you need this now, an interim solution could be that you make sure your code is only run once when triggered by the .Saved / .Saving events.

One way to do this would be to check the last saved date (UpdateDate) in your code. If the content was saved within the last second of the current save operation, you know that this is a save event triggered by the save happening in SendToPublication action. Then you also know that the item has already been sent to publication and that this doesn't need to be done again - thereby preventing the endless loop from happening.

Claus
  • 1,975
  • 18
  • 24