Skip to content

Instantly share code, notes, and snippets.

@rhjelmeir
Last active January 2, 2016 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhjelmeir/8341713 to your computer and use it in GitHub Desktop.
Save rhjelmeir/8341713 to your computer and use it in GitHub Desktop.
Umbraco 6 AfterPublish Event Hook to hopefully rebuild local cache of all nodes from the database
using Umbraco.Core;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic;
using umbraco.cms.businesslogic.web;
using Umbraco.Core.Services;
using Umbraco.Core.Logging;
namespace Umbraco.Extensions.EventHandlers
{
public class RegisterEvents : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
Document.AfterPublish += Document_AfterPublish;
}
private void Document_AfterPublish(Document sender, PublishEventArgs e)
{
//Do what you need to do. In this case logging to the Umbraco log
Umbraco.Core.Logging.LogHelper.Info(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Sender: " + sender.Id + " the document " + sender.Text + " got published");
var contentService = ApplicationContext.Current.Services.ContentService;
contentService.RePublishAll();
umbraco.library.RefreshContent();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment