Last active
January 2, 2016 18:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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