Copied to clipboard

Flag this post as spam?

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


  • Fengelz 106 posts 221 karma points
    Sep 23, 2009 @ 11:13
    Fengelz
    0

    Publishing documents the right way

    Hi Everybody.

    Im currently working an a solution where I created an api that can store values in the umbraco solution (as documents) and retreive values such as memberinfo, quizanswers an such.

    Im expeiencing some minor problems when publishing the documents I create.

    1) Sometimes a node appears twice in the document tree (same text, same id, same childnodes). This I can fix by selecting "Move" and assign the parent node as the new parent node (ie. move it to where it already is).

    2) Some of the nodes appears as published in the content tree but doesnt show up in the XmlCache when I use umbraco.library.GetXmlNodeByXPath("..") and iterate through the nodes. this however I can fix by pressing Republish Entire Site on the Content root.

    I have to methods where I create and publish content. this is one of them:

     

    private void SubmitSale(int quantum)
        {
            Member m = Member.GetCurrentMember();
            if (m == null)
            {
                this.SetOutput(XmlResponse("Not signed in."));
                return;
            }
    
            Document allMemberSalesDoc = new Document(this._salesNodeId);
            Document currentMemberSales =
                allMemberSalesDoc.Children
                .Where(x => x.Text == m.Email)
                .FirstOrDefault();
    
            if (currentMemberSales == null)
            {
                currentMemberSales = Document.MakeNew(m.Email, DocumentType.GetByAlias("Repository"), this.Admin, allMemberSalesDoc.Id);
                currentMemberSales.Publish(this.Admin);
                umbraco.library.UpdateDocumentCache(currentMemberSales.Id);
            }
    
            Document memberAnswer = Document.MakeNew(DateTime.Now.ToString("dd-MM-yyyy HH:mm"), DocumentType.GetByAlias("Sale"), this.Admin, currentMemberSales.Id);
            memberAnswer.getProperty("Quantum").Value = quantum;
            if(memberAnswer.getProperty("Member")!=null)
                memberAnswer.getProperty("Member").Value = m.Id;
            memberAnswer.Save();
            memberAnswer.Publish(this.Admin);
            umbraco.library.UpdateDocumentCache(memberAnswer.Id);
            this.SetOutput(XmlResponse(true, "Salg oprettet"));
        }

    Any Idea what I might be doing wrong?

    kind regards

    - Sune Fengel

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Sep 23, 2009 @ 12:14
    Ismail Mayat
    0

    Sune,

    Does normal publish work properly eg via the gui? 

    Regards

    Ismail

  • Fengelz 106 posts 221 karma points
    Sep 23, 2009 @ 15:15
    Fengelz
    0

    Yes it does. I just tested it on a specifik node, and it does seem to work.

    - Sune

  • jonok 297 posts 658 karma points
    Nov 27, 2009 @ 02:44
    jonok
    0

    I'm doing something similar and sometimes when I publish or save, the node appears twice in the tree. The 2 nodes have the exact same id and children. Anybody got any ideas? I know there is a new tree in the next version of Umbraco but I need this working very soon so waiting isn't really an option.

  • Paul Blair 466 posts 731 karma points
    Jan 07, 2010 @ 23:47
    Paul Blair
    0

    I have just had the same problem with nodes appearing twice in the tree. Moving it (to the same parent node) corrects the issue. Config file all looked fine so I guess something dodgy had gone on in the database

  • Jonas Eriksson 930 posts 1825 karma points
    Jan 08, 2010 @ 08:20
    Jonas Eriksson
    0

    Fengelz and Paul, are you using 4.0.3? I use the same code and it works for me, however not very much tested after I upgraded to 4.0.3.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jan 08, 2010 @ 09:14
    Thomas Höhler
    0

    Just one hint, you don't need to Save the memberAnswer direct before you publish it. The publish will also save the node.

    Thomas

  • Fengelz 106 posts 221 karma points
    Jan 15, 2010 @ 10:48
    Fengelz
    0

    Thanks for the replys, the post is 3 months old and I never managed to fizx the problem. The project in question was definitely no umbraco 4.0.3.

    Thomas, thanks for the hint I guess I just copied the code from the Umbraco books where I think it says save the node. But I wont do so from now on :)

     

    - Sune

Please Sign in or register to post replies

Write your reply to:

Draft