Copied to clipboard

Flag this post as spam?

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


  • tracker63 22 posts 20 karma points
    Apr 18, 2009 @ 05:27
    tracker63
    0

    Update: How to avoid infinte publish loop in publish action handler?

    Note: This a repost, I tried making this same post an hour ago, but it is still not showing up in the forum so something must have gone wrong during posting.
    Hi I'm editing data fields for a doc type in a publish event action handler and I am wondering how I can make these changes visible on the site, as I can't call the publish event in this action handler to update the page and make the changes visible as this will cause an infinite loop in calling publish within the publish action handler.

    I originally thought I could make these edits in the create event, and make a create event action handler and then call publish from the create action handler, however all the data fields are blank for the document in the create stage, so I can't make the needed edits at this stage.

    What I am using this action handler for is when a new City document is created I take the city's name, and the state name of it's parent node(the parent node of a city is a State document), and call a web service to get some housing information about that city and then enter that information into housing information fields in the City doc type. So what I do is in the publish event I get the city/state name, then get the info, and then add it to the city doc type and Save the city document. So when I look at the page in the umbraco backend's content section I can see the data in the fields, just that the data isn't visible on the website until I manually republish the page.

    Here is a sample bit of the code I'm using.

    [code]
    // only work with the publish event
    if (action.Alias != "publish")
    return true;

    // only work witih the cityMortgage document type
    if (documentObject.ContentType.Alias != "cityMortgage")
    return true;

    ....

    // 5 is just an example value for this form post
    int averageListingPrice = 5;
    documentObject.getProperty("averageListingPrice").Value = averageListingPrice.ToString();

    // save the changes to the document
    documentObject.Save();
    // umbraco.content.Instance.RefreshContentFromDatabaseAsync();
    return true;
    [/code]

    So if anyone knows how I can edit fields in the publish event, and then have these changes be visible on the website without needing to manually republish in the umbraco user interface backend that'd be very helpful as I'm stumped.
    You can see I commented out the RefreshContentAysnc part as I tried that to see if that would make the changes visible on the website without needing to call publish, but that didn't work.

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Apr 18, 2009 @ 08:03
    Richard Soeteman
    0

    Hi,

    What you can do is use the BeforeSave event. This event is called Before the document is actually saved. In that stage you only have to set the field properties for the City document. Umbraco is taking care of the rest including the publish if you hit save and publish offcourse. This is done server side so when you want to see the updates in Umbraco you need to refresh the page. If you want to see all the events that are available in Umbraco checkout this blogpost that I've written a few months back.

    One thing that came to mind while reading your post.. Have you also considered the option to get the data realtime? Umbraco has a great caching technology when you use Macro's, so performance shouldn't be an Issue.

    Hope it helps you,

    Richard

  • tracker63 22 posts 20 karma points
    Apr 21, 2009 @ 00:47
    tracker63
    0

    Thank you, I'll try it tonight.

Please Sign in or register to post replies

Write your reply to:

Draft