Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ayo Adesina 430 posts 1023 karma points
    Feb 01, 2017 @ 12:50
    Ayo Adesina
    0

    ContentService.SaveAndPublishWithStatus VS ContentService.SendToPublication

    Hello Umbraco People,

    I have an application that uses the 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, I don't want to publish the content, I want to 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 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 in to an infinite loop.

    When I attach the debugger and manually stop the infinate 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?

  • Ayo Adesina 430 posts 1023 karma points
    Feb 01, 2017 @ 14:26
    Ayo Adesina
    0

    Anyone...?

  • Marcin Zajkowski 112 posts 585 karma points MVP 6x c-trib
    Feb 02, 2017 @ 19:29
    Marcin Zajkowski
    0

    First of all, why you're not using user permissions / roles for handling it? If you would use Writer's and Editor's roles you'll have this workflow by default.

    enter image description here

    I don't know your solution, but on the other side, you can cancel event population after catching the item action in SendingToPublish event handler (doing whatever you want before it). Did you try it?

    private void ContentService_SendingToPublish(IContentService sender, Umbraco.Core.Events.SendToPublishEventArgs<Umbraco.Core.Models.IContent> e)
    {
        // Check if it's for your item or node...
        // Do something...
    
        e.Cancel = true;
    }
    

    Adding this flag may be helpful as you suggested in other thread too. Depending on desired solution, but worth to raise as a Pull Request and discuss with Core devs maybe.

  • Ayo Adesina 430 posts 1023 karma points
    Feb 06, 2017 @ 11:51
    Ayo Adesina
    0

    I'm using user permissions / roles, however this project is an Umbraco instance that drives two different websites, so when you update data in one node, I am updating the data automatically in another node.

    Which is why I am doing this in code.

    I have since updated this code to try and use the Published & Publishing methods instead, which is working a little better, but I am still having issues.

    In the ContentService_Published Method, I am calling

    cs.SaveAndPublishWithStatus(publishedNode, currentUser.Id, false);

    The problem I am having is even though I am passing false it still raises an events so it calls back in to ContentService_Published and causes an infinite loop.

    Any points/Ideas any one... starting to think I might have to give up on this.

Please Sign in or register to post replies

Write your reply to:

Draft