Copied to clipboard

Flag this post as spam?

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


  • Jan Højriis Dragsbæk 12 posts 63 karma points
    Apr 16, 2013 @ 11:40
    Jan Højriis Dragsbæk
    0

    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?

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Apr 30, 2013 @ 20:41
    Morten Christensen
    0

    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 

  • Jan Højriis Dragsbæk 12 posts 63 karma points
    May 01, 2013 @ 08:52
    Jan Højriis Dragsbæk
    0

    Hi Morten,

     

    Specifically, this is the code that does the saving and publishing on the nodes that do no work:

        protected int AddOrGetCategory( int baseCategoryId, string categoryName, bool swapTemplate = false ) {
          INode categoryNode = uQuery.GetNode( baseCategoryId ).ChildrenAsList.FirstOrDefault( n => n.NodeTypeAlias == "ProductCategory" && ( n.GetProperty( "xmlName" ) != null && n.GetProperty( "xmlName" ).Value == categoryName.Trim() ) );
          IContent category = categoryNode != null ? _contentService.GetById( categoryNode.Id ) : _contentService.CreateContent( categoryName.Trim(), baseCategoryId, "ProductCategory" );

          if ( categoryNode != null ) {
            return category.Id;
          }

          category.SetValue( "xmlName", categoryName.Trim() );
          _contentService.SaveAndPublish( category );

          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

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    May 01, 2013 @ 21:04
    Morten Christensen
    0

    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

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    May 01, 2013 @ 21:08
  • Jan Højriis Dragsbæk 12 posts 63 karma points
    May 02, 2013 @ 14:23
    Jan Højriis Dragsbæk
    0

    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.

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    May 02, 2013 @ 15:12
    Morten Christensen
    100

    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);

  • Jan Højriis Dragsbæk 12 posts 63 karma points
    May 02, 2013 @ 15:17
    Jan Højriis Dragsbæk
    0

    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? 

  • Jan Højriis Dragsbæk 12 posts 63 karma points
    May 02, 2013 @ 15:25
    Jan Højriis Dragsbæk
    0

    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. 

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    May 02, 2013 @ 15:51
    Morten Christensen
    0

    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

  • Jan Højriis Dragsbæk 12 posts 63 karma points
    May 02, 2013 @ 15:57
    Jan Højriis Dragsbæk
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft