How to avoid infinite publish loop in publish action handler?
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.
How to avoid infinite publish loop in publish action handler?
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.
Test reply, as this post isn't showing up in the forum.
is working on a reply...