SaveAndPublish not regenerating document XML in the new API
I am creating a buttload of documents via the new API, and even when I call SaveAndPublish on every document, the xml cache is not regenerated, before I manually click the save-and-publish button in the umbraco backoffice.
Can you share the code you are using to SaveAndPublish the documents you are creating?
When you click save and publish in the backoffice its actually calling the same SaveAndPublish method in the ContentService under the covers, so I suspect something is going wrong somewhere else.
if ( swapTemplate ) { SwapTemplate( category.Id ); }
return category.Id; }
As you can see, it is nothing out of the ordinary. Can it perhaps be because of the way I initialize the contentService? I initialize it simply by doing
_contentService = new ContentService();
instead of using ApplicationContext.
I have recorded a screencast showing us exploring the problem, and it looks like that the SaveAndPublish method doesn't initialize boolean properties. See screencast for details: http://screencast.com/t/qO3tE3TcJh
Hi Jan, if you are using the ContentService within the context of Umbraco I would always recommend that you get the service through the ApplicationContext. So please try that first of.
Another thing I found recently is an oversight within the SaveAndPublish method, which we'll fix in the next version. But until then you'll probably have to call .Save() and then .Publish() when creating new content using .CreateContent().
There's another thread that gives a little more insight into this issue.
I think I figured out what the problem is, and you are right. In the code you provided above you don't explicitly set the umbNaviHide property to either true or false, and because the underlying collection of properties are objects anything that is not set explicitly will not be saved to the database. When you click save and publish in the backoffice everything is explicitly set. So an easy workaround would be to add something like category.SetValue("umbNaviHide",false);
Looking through previous "problems" we have had with some websites, the copy function in the backoffice seem to "forget" to explicitly set variables as well. More specifically, we have had the same problem with items not being shown in our navigation due to the fact that umbNaviHide is not set to false after a copy.
Would be good to get this problem logged on the tracker - the one with copy "loosing" values. As far as I remember you already created an issue for this topic right? So maybe create a new one related to that, but specific to copying.
SaveAndPublish not regenerating document XML in the new API
I am creating a buttload of documents via the new API, and even when I call SaveAndPublish on every document, the xml cache is not regenerated, before I manually click the save-and-publish button in the umbraco backoffice.
I have tried regenerating it using the examples from http://our.umbraco.org/wiki/reference/api-cheatsheet/publishing-and-republishing, but none of those methods seem to do the trick.
How can I programmatically regenerate the XML using the new API?
Hi Jan,
Can you share the code you are using to SaveAndPublish the documents you are creating?
When you click save and publish in the backoffice its actually calling the same SaveAndPublish method in the ContentService under the covers, so I suspect something is going wrong somewhere else.
- Morten
Hi Morten,
Specifically, this is the code that does the saving and publishing on the nodes that do no work:
As you can see, it is nothing out of the ordinary. Can it perhaps be because of the way I initialize the contentService? I initialize it simply by doing
instead of using ApplicationContext.
I have recorded a screencast showing us exploring the problem, and it looks like that the SaveAndPublish method doesn't initialize boolean properties. See screencast for details: http://screencast.com/t/qO3tE3TcJh
Hi Jan, if you are using the ContentService within the context of Umbraco I would always recommend that you get the service through the ApplicationContext. So please try that first of.
Another thing I found recently is an oversight within the SaveAndPublish method, which we'll fix in the next version. But until then you'll probably have to call .Save() and then .Publish() when creating new content using .CreateContent().
There's another thread that gives a little more insight into this issue.
Let me know if any of this works.
Thanks,
Morten
Here is a thread I believe is related to this: http://our.umbraco.org/forum/developers/api-questions/39814-ContentServiceSaveAndPublish-inside-a-DocumentAfterPublish-method-throws-an-error
- Morten
Unfortunately changing the code use Save() followed by Publish() does not change the situation about the boolean not being initialized.
Using ContentService from the ApplicationContext also did not change anything.
Hey Jan,
I think I figured out what the problem is, and you are right. In the code you provided above you don't explicitly set the umbNaviHide property to either true or false, and because the underlying collection of properties are objects anything that is not set explicitly will not be saved to the database. When you click save and publish in the backoffice everything is explicitly set. So an easy workaround would be to add something like category.SetValue("umbNaviHide",false);
Of course, this makes perfectly sense, but shouldn't it work just as it does in the backoffice?
As in, the save method explicitly filling out values like the true/false and setting textfields to empty string?
Looking through previous "problems" we have had with some websites, the copy function in the backoffice seem to "forget" to explicitly set variables as well. More specifically, we have had the same problem with items not being shown in our navigation due to the fact that umbNaviHide is not set to false after a copy.
Would be good to get this problem logged on the tracker - the one with copy "loosing" values. As far as I remember you already created an issue for this topic right? So maybe create a new one related to that, but specific to copying.
Thanks,
Morten
I will post this as a bug on the issue tracker right away then.
I did not post a issue on the topic, but one of the other guys at the office might have done so in the past.
is working on a reply...