Copied to clipboard

Flag this post as spam?

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


  • Steven Newstead 62 posts 103 karma points
    Jul 11, 2011 @ 12:29
    Steven Newstead
    0

    Updating 'Link to document' after node moved in api

     

    Hi all,

    I am doing something similar to http://our.umbraco.org/forum/developers/api-questions/7461-Moving-a-document-not-updating-Link-to-document where I am moving a node in the AfterPublish event to a different area of the tree.

    Everything works well except the 'Link to document' and 'Alternative link' are not updating.

    I've tried using umbraco.library.RefreshContent(); in the AfterPublish like so:

     

    //Create the news item
    User author = User.GetUser(0);
    newsDoc.Move(newsMonth.Id);
    newsDoc.Publish(author);
    umbraco.library.UpdateDocumentCache(newsDoc.Id);
    umbraco.library.RefreshContent();

     

    but this does not appear to work.

     

     

    I've also tried this:

     

     

     

     

     

     

      public ContentUpdateCache()
            {
                umbraco.content.AfterUpdateDocumentCache += new content.DocumentCacheEventHandler(Content_UpdateCache);
            }

            private void Content_UpdateCache(Document sender, DocumentCacheEventArgs e)
            {
                if (sender.ContentType.Alias == "XXX")
                {
                   umbraco.library.RefreshContent();
                }
            }
        }


    But this doesn't work either

    Any help greatfully recieved, I'm sure I'm missing something obvious...

    thanks,

    Steve

     

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Jul 11, 2011 @ 12:51
    Sebastiaan Janssen
    0

    I think a simple document.Publish(new User(0)); before RefreshContent could well do the trick.

  • Steven Newstead 62 posts 103 karma points
    Jul 13, 2011 @ 09:20
    Steven Newstead
    0

    In the end what I had was more or less correct, I was doing this in the AfterPublish:

     

    //Create the news item
    User author =User.GetUser(0);
    newsDoc
    .Move(newsMonth.Id);
    newsDoc
    .Publish(author);
    umbraco
    .library.UpdateDocumentCache(newsDoc.Id);
    umbraco
    .library.RefreshContent();

     

    And this in the AfterUpdateDocumentCache

    publicContentUpdateCache()
            {
                umbraco.content.AfterUpdateDocumentCache+=new content.DocumentCacheEventHandler(Content_UpdateCache);
            }

            privatevoidContent_UpdateCache(Document sender,DocumentCacheEventArgs e)
            {
                if(sender.ContentType.Alias=="XXX")
                {
                    umbraco.library.RefreshContent();
                }
            }
        }

    This didn't seem to work, but then I deleted this line:

    umbraco.library.UpdateDocumentCache(newsDoc.Id);

    and it all seems to work, curious...

     

     

     

     

     

     

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft