Copied to clipboard

Flag this post as spam?

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


  • Thomas Dolberg 74 posts 95 karma points
    Mar 06, 2011 @ 23:57
    Thomas Dolberg
    0

    Creating document through API does not update config correct

    Hi

    When I create a new document through the API and add tags using 

    umbraco.cms.businesslogic.Tags.Tag.AddTagsToNode

    and then save the document using

                User user = new umbraco.BusinessLogic.User(0);
                umbraco.BusinessLogic.Actions.Action.RunActionHandlers(doc, umbraco.BusinessLogic.Actions.ActionUpdate.Instance);
                doc.Save();
                if (doc.PublishWithResult(user))
                {
                    umbraco.library.UpdateDocumentCache(doc.Id);
                    umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Publish, user, doc.Id, "");
                
                }

    the tags are not published to the umbraco.config.

    When going to the created document through the backend and hitting "save and publish", the tags are published to the umbraco.config file.

     

    Any ideas why this is?

     

    thanks

    Thomas

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 07, 2011 @ 17:51
    Jan Skovgaard
    0

    Is it by intention that you don't use

    doc.Publish(user); after you have saved the document? I'm not sure but I think the XML cache will not be updated before the publish event has been called...

    /Jan

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Mar 08, 2011 @ 08:44
    Sebastiaan Janssen
    0

    You don't need to do Doc.Save();

    Just do:

    doc.Publish(new User(0));
    umbraco.library.UpdateDocumentCache(doc.Id)
    

    I think in your code, publishwithresult returns false. Check that using the debugger..

  • Max Mumford 266 posts 293 karma points
    Aug 02, 2011 @ 13:35
    Max Mumford
    0

    Did you ever get a fix for this? I am experiencing the same problem -

    http://our.umbraco.org/forum/developers/api-questions/22771-Node-published-and-cache-updated-but-content-not-in-xml

    The node *is* being published but the xml is not being updated using:

    d.Publish(new User());
    umbraco.library.UpdateDocumentCache(d.Id);
  • Thomas Dolberg 74 posts 95 karma points
    Aug 07, 2011 @ 00:19
    Thomas Dolberg
    0

    Hi Max,

    it was part of a migrating proces, but I ended up using CMSImport instead, so I never continued down this path.

     

    Hope you get it solved.

     

    best regards

    Thomas

  • Jesper Hauge 298 posts 487 karma points c-trib
    Aug 08, 2011 @ 10:30
    Jesper Hauge
    1

    Hi all,

    The umbraco.config file is only a disk backup of the live data, and is not updated right away when using doc.Publish(0), generally umbraco.config is mostly used for populating the in-memory xml document that is used by the frontend, on application start. The file will eventually get updated but it it isn't constantly kept up to date.

    I've found that to be sure you've got the latest xml content after doing a doc.publish you need to get the xml content via the API, you can get the document as an XmlDocument with:

    umbraco.content.Instance.XmlContent

    Or if you prefer to work with an XDocument you can get it with:

    XDocument.Load(new XmlNodeReader(content.Instance.XmlContent))

    This will always give you the latest content (ie. the content you were expecting when opening the umbraco.config file).

    Regards
    Jesper Hauge 

     

  • Max Mumford 266 posts 293 karma points
    Aug 09, 2011 @ 11:09
    Max Mumford
    0

    Thanks for the reply. So you can confirm that xslt uses the umbraco.config file to get it's data? This seems like a small but irritating caveat. How long on average would one have to wait for the umbraco.config file to update? Is there any way around this?

    Max.

  • Jesper Hauge 298 posts 487 karma points c-trib
    Aug 09, 2011 @ 13:11
    Jesper Hauge
    1

    Hi again Max,

    No - the xslt files processed by Umbraco via Macros does not process the umbraco.config file in \App_Data, it processes the xml-document in umbraco.content.Instance.XmlContent, which is always up to date. 

    So doing a Document.Publish() in some server side code, like in a usercontrol or something like that, and then showing a page that contains xslt macros, shouldn't cause any problems. What can cause problems, and I suspect that was what Thomas experienced (anyway I've had the problem myself), is doing a Document.Publish() and then retriving the Umbraco.config file in code, and doing something with this file. For instance:

    protected void Page_Load(object sender, EventArgs e)
    {
    // Fetch document edit and publish
    var doc = new Document(1);
    doc.getProperty("header").Value = "New header";
    doc.Publish(new User(0));
    umbraco.library.UpdateDocumentCache(doc.Id);

    // Load xml from umbraco.config and get node
    var xdoc = XDocument.Load(Server.MapPath("/App_Data/Umbraco.config"));
    var element = xdoc.Descendants("page").Where(n => n.Attribute("id") == 1).FirstOrDefault();
    string header = element.Element("header").Value;


    Will not fetch the newly published header because Umbraco.config isn't updated straight away.

    But if you replace

    var xdoc = XDocument.Load(Server.MapPath("/App_Data/Umbraco.config"));

    With

    var xdoc = XDocument.Load(new XmlNodeReader(content.Instance.XmlContent));

    It will work because the XmlDocument in umbraco.content.Instance.XmlContent, is the "real" xml-document Umbraco is rendering content from. The Umbraco.config file will be updated later automatically, or when you right-click the content node and select "Republish entire site".

    I hope that explains it a little bit better.

    Regards
    Jesper Hauge 

Please Sign in or register to post replies

Write your reply to:

Draft