I made an event handler for the publish:end event in order to create a Sitemap XML file for each language available in my Sitecore instance every time Sitecore finishes publishing the site.
As described in Get Languages chosen for publish in publish:end event:
[...] actually the publish:end event hits once for every language - and you get get the language that is being published by doing EventArgs[0].Options.Language.
The problem is publish:end event is just hitting my event handler once and for the first selected language only. If I select 3 languages (En-US, Pt-BR, Fr-CA) during the publishing of my Sitecore instance, for example, publish:end event will hit my event handler one time just and display En-US as the value of the Property EventArgs[0].Options.Language
. It does not hit my event handler for the other 2 selected languages (Pt-BR, Fr-CA).
I am using Sitecore.NET 8.0 (rev. 150812).
Below is my configuration file for the event handler:
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<events>
<event name="publish:end">
<handler type="Project1.EventHandlers.BuildXMLSitemap, Project1.SBL" method="BuildSitemap" />
</event>
<event name="publish:end:remote">
<handler type="Project1.EventHandlers.BuildXMLSitemap, Project1.SBL" method="BuildSitemap" />
</event>
</events>
<!-- Update settings for the Trusted_Connection = True -->
<sites>
<site name="website">
<patch:attribute name="sitemapXmlFileName">sitemap</patch:attribute>
<patch:attribute name="sitemapXmlIndexFileName">sitemapindex</patch:attribute>
</site>
</sites>
</sitecore>
</configuration>
And below is my code:
namespace Project1.EventHandlers
{
public class BuildXMLSitemap
{
public void BuildSitemap(object sender, EventArgs args)
{
Language language = GetLanguage(args);
}
private Language GetLanguage(EventArgs args)
{
Language language;
if (args is PublishEndRemoteEventArgs)
{
var publishArgs = args as PublishEndRemoteEventArgs;
language = LanguageManager.GetLanguage(publishArgs.LanguageName);
}
else
{
var publisher = Event.ExtractParameter(args, 0) as Publisher;
if (publisher == null) return null;
language = publisher.Options.Language;
}
return language;
}
}
}
And here is my Sitecore instance with the languages configured:
And here is Sitecore Publish Site Dialog showing the available languages:
The publish:end handler is called only once per the publishing process, no matter how many languages are selected for the item publishing. This has been changed since Sitecore 7.2 as part of publishing improvements.
You might want to have a look at the publish:complete handler.