Copied to clipboard

Flag this post as spam?

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


  • Kevin T Reynolds 15 posts 158 karma points
    Jun 26, 2020 @ 00:25
    Kevin T Reynolds
    0

    How can I save IContent in the publishing event?

    I have a custom content approval workflow that worked in Umbraco 7 by subscribing to the content_publishing event and changing a field on the node using the ContentService API to update approval state.

    In Umbraco 8 using the .Save method

        public void UpdateWaitingApprovalStatus(IContent contentToUpdate, string waitingApprovalPropertyAlias, string waitingApprovalValueToSet)
        {
            contentToUpdate.SetValue(waitingApprovalPropertyAlias, waitingApprovalValueToSet);
            _contentService.Save(contentToUpdate);
        }
    

    I get the following error Cannot save (un)publishing content with name: test - and state: Publishing, use the dedicated SavePublished method.

    But I can't seem to find that method anywhere, is there another way to save while PublishedState is Publishing?

    I can get around it by subscribing to the published event and using SaveAndPublish but that leaves two publish events in logs.

  • Bo Jacobsen 606 posts 2404 karma points
    Jun 26, 2020 @ 05:52
    Bo Jacobsen
    0

    Hi Kevin.

    I dunno if it helps, but try use _contentService.Save(contentToUpdate, raiseEvents = false);

  • Kevin T Reynolds 15 posts 158 karma points
    Jul 01, 2020 @ 17:11
    Kevin T Reynolds
    100

    I tested with the Save override that accepts an IEnumerable<IContent> and sure enough it doesn't check published state and worked exactly as I needed to. so if anyone comes accross this in the future _contentService.Save(new List<IContent>() { contentToUpdate}, raiseEvents = false); works as of Umbraco 8.6.3

  • Kevin T Reynolds 15 posts 158 karma points
    Jul 01, 2020 @ 01:11
    Kevin T Reynolds
    0

    Thanks but unfortunately not, the save method has a check for PublishedState, interestingly enough it looks like the method for saving multiple content items doesn't have that check.

    For now I'm still listening to the published event and republishing if I need to, but I'll try on a list of content tomorrow and report back.

Please Sign in or register to post replies

Write your reply to:

Draft