Copied to clipboard

Flag this post as spam?

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


  • Anton Gildebrand 49 posts 149 karma points c-trib
    Jun 17, 2013 @ 00:48
    Anton Gildebrand
    0

    SaveAndPublish doesn't work

    I am having a hard time updating a node and make the changes reflect on the site. When i only call node.Save(), the changes isn't reflected on the site as expected. If i look in the backoffice, the nodes appears as unpublished (or at least have a unpublished version). So i want the changes to go live immediately. Therefore i called node.SaveAndPublish(new User(0)) instead. Now when i look in the backoffice, there is no unpublished version. However the changes to the node isn't published. It's first when i press the publish-button in the backoffice as the changes actually go live, even though the node appeared as published.

    Is this a bug in the API or what? How do i solve this?

            public static string Set()
            {
                string state = HttpContext.Current.Request["a"];
                string ev = HttpContext.Current.Request["e"];
    
                if ((state == "true" || state == "false") && ev.Length >= 4)
                {
                    Member m = Member.GetCurrentMember();
                    var node = new Document(Convert.ToInt16(ev));
    
                    if (node == null)
                        return "error";
                    else
                    {
                        var users = (from p in node.getProperty("guests").Value.ToString().Split(',')
                                     where p != m.Id.ToString()
                                     select p).ToList();
                        if (state == "true" && !users.Contains(m.Id.ToString()))
                        {
                            users.Add(m.Id.ToString());
                        }
                        else if (state == "false")
                        {
                            users = (from p in users
                                    where p != m.Id.ToString()
                                    select p).ToList();
    
                        }
                        node.getProperty("guests").Value = String.Join(",", users);
                        node.SaveAndPublish(new User(0));
                        return "success";
                    }
                }
                else
                    return "error";
            }
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 17, 2013 @ 10:35
    Jeavon Leopold
    0

    Hi Anton,

    Can I ask what version of Umbraco are you using as there have been quite a few changes to this method depending on version?

    Thanks,

    Jeavon

  • Anton Gildebrand 49 posts 149 karma points c-trib
    Jun 17, 2013 @ 10:48
    Anton Gildebrand
    0

    Hi Jeavon,

    Thank you for your reply.

    The version is 6.0.5.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 17, 2013 @ 10:57
    Jeavon Leopold
    0

    Ok, I think you just need to clear the cache after calling SaveAndPublish,

    Below is snippet from the documentation for the Publish method but it should be the same

     //Get the document
    var doc = new Document(1234);
    
    //create and store a xml representation of the document
    doc.Publish(user);
    
    //tell the runtime to retrieve the xml from the database and store in cache
    umbraco.library.UpdateDocumentCache(doc.Id);

     See if that works for you?

    Thanks,
    Jeavon
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 17, 2013 @ 11:32
    Jeavon Leopold
    0

    I should add that if you were to use the v6 API (rather than the v4 API) then you don't need to worry about flushing the cache (a great improvement). v6 API ContentService documentation is available here

Please Sign in or register to post replies

Write your reply to:

Draft