How do you register a Document_AfterPublish in Umbraco 7. 'Normaly' this works, but it does not in umbraco 7. What am I doing wrong? It does log 'OnApplicationStarting 1' etc just never enters Document_AfterPublish
using Umbraco.Core;
using umbraco.cms.businesslogic;
using GeneralHelper;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
namespace EventHandlers
{
public class RegisterEvents : IApplicationEventHandler
{
public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
}
public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
Thank you. I tried several og the samples, but none of them seem to be working in Umbraco 7.1.4 - It never enters the 'AfterPublish' or 'BeforePublish' when i hit the save & publish or save botton.
The only way I got Umbraco 7 to react on something when hitting the save & publish, was by adding my own method in umbraco.controllers.js, but there must be a better way to do it.
$scope.saveAndPublish = function () {
var message = performSave({ saveMethod: contentResource.publish, statusMessage: "Publishing..." });
You know I hope people are going to say "there are no dumb questions" when they read this so here goes:
Lets say I define a class called "UmbracApplicationEventHandler" and I derive it from "UmbracoEventHandler" as above. How does an instance of this class get created and therefore any event defined within it called ?
I ask because I have done this, in order to register a 404 handler using the IContentFinder interface, but the "ApplicationStarting" event never gets called.
First of all: you should derive from "ApplicationEventHandler".
Second: the class is created because of the Umbraco system scanning for classes deriving from ApplicationEventHandler.
EventHandler Document_AfterPublish
How do you register a Document_AfterPublish in Umbraco 7. 'Normaly' this works, but it does not in umbraco 7. What am I doing wrong? It does log 'OnApplicationStarting 1' etc just never enters Document_AfterPublish
using Umbraco.Core;
using umbraco.cms.businesslogic;
using GeneralHelper;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
namespace EventHandlers
{
public class RegisterEvents : IApplicationEventHandler
{
public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
}
public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
Log.Add(LogTypes.Notify, 0, "OnApplicationStarting 1");
Document.AfterPublish += Document_AfterPublish;
Log.Add(LogTypes.Notify, 0, "OnApplicationStarting 2");
}
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
Log.Add(LogTypes.Notify, 0, "RegisterEvents");
}
public void Document_AfterPublish(Document sender, PublishEventArgs e)
{
Log.Add(LogTypes.Notify, 0, "Document_AfterPublish");
GeneralHelper.IndexNews.IndexAllNewsNow();
}
}
}
Please read this: http://our.umbraco.org/documentation/Reference/Events/application-startup
It should explain what to use :-)
Thank you. I tried several og the samples, but none of them seem to be working in Umbraco 7.1.4 - It never enters the 'AfterPublish' or 'BeforePublish' when i hit the save & publish or save botton.
The only way I got Umbraco 7 to react on something when hitting the save & publish, was by adding my own method in umbraco.controllers.js, but there must be a better way to do it.
$scope.saveAndPublish = function () {
var message = performSave({ saveMethod: contentResource.publish, statusMessage: "Publishing..." });
MYCODE();
return message;
};
Use this:
More information: http://our.umbraco.org/documentation/Reference/Events-v6/ContentService-Events
Thank you! Now it's working.
You know I hope people are going to say "there are no dumb questions" when they read this so here goes:
Lets say I define a class called "UmbracApplicationEventHandler" and I derive it from "UmbracoEventHandler" as above. How does an instance of this class get created and therefore any event defined within it called ?
I ask because I have done this, in order to register a 404 handler using the IContentFinder interface, but the "ApplicationStarting" event never gets called.
Thanks
First of all: you should derive from "ApplicationEventHandler".
Second: the class is created because of the Umbraco system scanning for classes deriving from ApplicationEventHandler.
Thanks, appreciate the information. The "UmbraceEventHandler" was a slip as I am indeed deriving from "ApplicationEventHandler".
is working on a reply...