Copied to clipboard

Flag this post as spam?

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


  • Gary Cheetham 20 posts 144 karma points
    Oct 20, 2016 @ 11:49
    Gary Cheetham
    0

    Saving and Publishing a Node with the ContentService moves it 1 level up the tree

    I'm using the ContentService and MediaService to create a new IMedia, and then update a property on an existing IContent with the new IMedia's ID and publish the changes.

    Here's my code (more or less):

    var existingContentNode = _contentService.GetById(contentNodeId);
    
    var newImage = _mediaService.CreateMedia(newImageFileName, newMediaParentNodeId, "image");
    
    _mediaService.Save(newImage);
    
    existingContentNode.SetValue(imagePropertyAlias, newImage.Id);
    
    _contentService.SaveAndPublishWithStatus(existingContentNode);
    

    The image is always created and set, which is the desired behaviour. However, roughly half the time this code has an undesired side-affect and moves the existing content node one level up the tree, becoming a sibling of (what was) it's parent.

    I am unable to reproduce this on my local machine; this issue is only happening on the server.

    Further Information

    Umbraco version 7.4.2 assembly: 1.0.5921.28477

    I also have Ditto v0.8.4, uSync v3.2.0.740, and Chauffeur v0.6.4 installed (via NuGet).

    The dependencies on IMediaService and IContentService are being resolved by a DI container, Autofac v3.5.2 with the following code:

    var builder = new ContainerBuilder();
    // ... 
    
    builder.RegisterInstance(applicationContext.Services.ContentService).As<IContentService>();
    builder.RegisterInstance(applicationContext.Services.MediaService).As<IMediaService>();
    
    // ...
    

    Thanks in advance,

    Gary

  • Gary Cheetham 20 posts 144 karma points
    Oct 20, 2016 @ 15:12
    Gary Cheetham
    0

    UPDATE:

    I changed _contentService.SaveAndPublishedWithStatus(contentNode); to:

    _contentService.Save(contentNode);
    _contentService.Publish(contentNode);
    

    And the problem persists. This is leading me to believe that the issue happens during publish regardless of which method call I use.

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Oct 20, 2016 @ 19:56
    Alex Skrypnyk
    0

    Hi Gary,

    Is it right logic that you get parent node?

    From your code:

    var existingContentNode = _contentService.GetById(parentNodeId);
    

    parentNodeId? is it parent node ?

    Thanks,

    Alex

  • Gary Cheetham 20 posts 144 karma points
    Oct 21, 2016 @ 09:31
    Gary Cheetham
    0

    Yep, I've confirmed with the Visual Studio debugger that I'm getting the right node there.

    However, perhaps my way of naming the ID variable "parentNodeId" has caused some confusion. I was referring to the ID of the existing content node which I'm adding media to. I've edited my original post to make that a little clearer.

    Cheers, Gary

  • Gary Cheetham 20 posts 144 karma points
    Oct 21, 2016 @ 10:02
    Gary Cheetham
    0

    Update on Progress:

    I've changed the code which saves and publishes the node to:

    // Before any work is done, create a record of the node's parentId
    var existingContentNode = _contentService.GetById(contentNodeId);
    int parentIdBefore = parentNode.ParentId;
    
    // ....
    
    // After work is done, set the parentId to make sure it's not changed
    existingContentNode.ParentId = parentIdBefore;
    _contentService.SaveAndPublishWithStatus(existingContentNode);
    

    And it's still not working on the server. Additionally, some other weirdness is now going on, such as:

    • Changes to the node not actually being published, but the backoffice saying they have been.
    • Clicking "Save and Publish" in the backoffice publishes the changes but moves the node 1 level up the tree.

    I now think that the database and/or cache on the server's environment is corrupted or otherwise incongruous, so I'm starting the process of restoring it. I will report back when I'm done.

  • Tobias Pettersson 19 posts 112 karma points
    Apr 24, 2017 @ 09:08
    Tobias Pettersson
    0

    Hey Gary, any news on this issue cause I'm having the same problem myself. Using SaveAndPublishWithStatus() wont actually publish my content.

    In the Umbraco backoffice it looks like its published but if I try to fetch children from my parentnode i get an empty list until I actually manually publish the page created.

    Anything we're missing?

    EDIT: I have tried Save() and Publish() with the same results. Even tried the deprecated method umbraco.library.UpdateDocumentCache(), someone else had a smiliar problem and solved it using that. (was a long time ago tho).

    Tried setting the PublishState.Published on the created IContent but nothing changed.

  • Tobias Pettersson 19 posts 112 karma points
    Apr 24, 2017 @ 12:18
    Tobias Pettersson
    0

    For some reason I cleared my cookies and all of a sudden my pages showed up. I have no idea what specific cookie was causing the issue but it seems that was the problem.

    Right now I get the "I have no idea what im doing" feeling.

Please Sign in or register to post replies

Write your reply to:

Draft