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.
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...
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:
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?
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".
Creating document through API does not update config correct
Hi
When I create a new document through the API and add tags using
and then save the document using
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
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
You don't need to do Doc.Save();
Just do:
I think in your code, publishwithresult returns false. Check that using the debugger..
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:
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
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:
Or if you prefer to work with an XDocument you can get it with:
This will always give you the latest content (ie. the content you were expecting when opening the umbraco.config file).
Regards
Jesper Hauge
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.
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:
Will not fetch the newly published header because Umbraco.config isn't updated straight away.
But if you replace
With
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
is working on a reply...