Copied to clipboard

Flag this post as spam?

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


  • Rasmus Lynggaard 110 posts 297 karma points
    Aug 25, 2011 @ 17:42
    Rasmus Lynggaard
    0

    Document.MakeNew always publishes the node

    I'm creatin nodes through the API, but they shouldn't be published, but they are. Can someone tell me how I can create a new node and save it without publishing

    The code I have at the moment:

    var dct = DocumentType.GetByAlias("MyDocType");

    var author = User.GetUser(7); //Visitor
    var doc = Document.MakeNew(tbHeader.Text, dct, author, parentId);
    doc.getProperty("header").Value = tbHeader.Text;
    doc.getProperty("manchet").Value = tbManchet.Text;
    doc.getProperty("bodytext").Value = tbBodytext.Text.Replace(Environment.NewLine, "<br />");
    doc.Published = false;
    doc.SendToPublication(author);

    NB: The user used to create the node isn't even allowed to publish content

  • Rich Green 2245 posts 3918 karma points
    Aug 25, 2011 @ 17:48
    Rich Green
    0

    Hi Rasmus,

    Try this

    var dct = DocumentType.GetByAlias("MyDocType");
    var author = User.GetUser(7); //Visitor
    var doc = Document.MakeNew(tbHeader.Text, dct, author, parentId);
    doc.getProperty("header").Value = tbHeader.Text;
    doc.getProperty("manchet").Value = tbManchet.Text;
    doc.getProperty("bodytext").Value = tbBodytext.Text.Replace(Environment.NewLine, "
    ");

    //after creating the document, prepare it for publishing 
    doc.Publish(author);

    //You would usually call this to pubish the node
    //umbraco.library.UpdateDocumentCache(doc.Id);

    Rich

    NB: The API doesn't use the security options from the UI, I'm assuming your 'Visitor' user wouldn't have access to the API ;)

  • Rasmus Lynggaard 110 posts 297 karma points
    Aug 25, 2011 @ 18:09
    Rasmus Lynggaard
    0

    No, that doesn't do it. The node is still published, but the cache just isn't updated, which basically just means you can't see the content, but in the backend etc. the node will still seem like it's published. The content will also get into the cache, if you do a "republish entire site".

  • Rich Green 2245 posts 3918 karma points
    Aug 25, 2011 @ 18:11
    Rich Green
    0

    What about if you just comment out

     doc.Publish(author); 

    Rich

  • Rasmus Lynggaard 110 posts 297 karma points
    Aug 25, 2011 @ 18:16
    Rasmus Lynggaard
    0

    Nope, it's already published on Document.MakeNew

    The doc.publish etc. just calls the publish events and sends out notifications etc.

    I've made this little workaround that works for now:

    var dct = DocumentType.GetByAlias("MyDocType");

    var author = User.GetUser(7); //Visitor
    var doc = Document.MakeNew(tbHeader.Text, dct, author, parentId);
    doc.getProperty("header").Value = tbHeader.Text;
    doc.getProperty("manchet").Value = tbManchet.Text;
    doc.getProperty("bodytext").Value = tbBodytext.Text.Replace(Environment.NewLine, "
    ");
    doc.Published = false;
    doc.Save();
    doc.SendToPublication(author);
    doc.UnPublish();
    umbraco.library.UpdateDocumentCache(doc.Id);

    NB: This is a workaround, so if you have a solution to my problem, I would love to hear it.

Please Sign in or register to post replies

Write your reply to:

Draft