I have the following transform for my local site that injects a function call into the publish:itemProcessed event:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<sitecore>
<events timingLevel="custom" xdt:Transform="Insert">
<event name="publish:itemProcessed">
<handler type="Website.PublicSite.Web.PublishItemProcessed.PushContentForPublication, Website.PublicSite.Web" method="OnItemProcessed">
<database>master</database>
<uniqueIdField>Unique Id</uniqueIdField>
<clientKeyField>Client Key</clientKeyField>
<address1FieldName>Address Line 1</address1FieldName>
<latitudeField>Latitude</latitudeField>
<longitudeField>Longitude</longitudeField>
</handler>
</event>
</events>
</sitecore>
</configuration>
The following method is being called that populates the latitude and longitude values of the item using the item's address field and Google Location Services (this is the call to _service.GetCoordinates(publishedItem)):
public void OnItemProcessed(object sender, EventArgs args) {
ItemProcessedEventArgs itemProcessedEventArgs = args as ItemProcessedEventArgs;
PublishItemContext context = itemProcessedEventArgs?.Context;
if (context?.VersionToPublish == null) {
return;
}
Item publishedItem = context.VersionToPublish;
if (!CheckIfRunnable(publishedItem)) {
return;
}
if (publishedItem[LatitudeField].Length == 0 || publishedItem[LongitudeField].Length == 0)
{
Tuple<string, string> latLong = _service.GetCoordinates(publishedItem);
var latPos = latLong.Item1;
var longPos = latLong.Item2;
if (latPos == null || longPos == null)
{
throw new Exception("Error adding record to coordinates to store item. Location not found by Google Location API.");
}
//This will re-fire the saving pipeline
publishedItem.Editing.BeginEdit();
publishedItem[LatitudeField] = latPos;
publishedItem[LongitudeField] = longPos;
publishedItem.Editing.EndEdit();
}
}
The code is working as expected for the most part. The item is updated with the proper lat/long coordinates and is published to Web. However, only the item it the Master database has its latitude and longitude coordinates updated. For the Web database item, both of these fields are blank. My understanding is when I edit the publish item it should refire the publishing pipelines and an updated version of the item should be published to Web but that appears not to be the case. Anyone know how I can get both the Master and the Web database items to show the updated fields? Thanks for the help!