Workflow interferes with publication of programmatically created nodes
Hello everyone,
We are working on an Umbraco 4.7.2 site with Workflow for Umbraco 2.1. We've been using the package for quite a while and it has given us no trouble at all so far. Unfortunately, we came across a little problem these last couple of days. What happens is the following:
The site we are working on has 5 workflow configurations and 5 instantiation criterias. 4 out of the 5 instatiation criterias have the Document.AfterPublish event assigned as their Instantiating Event. We created a usercontrol that receives data from a webform, updates a node in the Content section and publishes it. The problem is that when the usercontrol tries to publish the node, workflow throws a Object reference not set to an instance of an object exception. The stacktrace is the following:
FergusonMoriyam.Workflow.Umbraco.Application.UmbracoEventService.ValidateCriteria(IWorkflowInstantiationCriteria
criteria) at
FergusonMoriyam.Workflow.Application.EventService.OnEvent(Object
sender, String eventName, Object[] args) at
umbraco.cms.businesslogic.web.Document.PublishEventHandler.Invoke(Document
sender, PublishEventArgs e) at
umbraco.cms.businesslogic.web.Document.PublishWithResult(User u) at
Desarrollo_Urbano.uploader.DocumentUpload.SavePdfToMedia(HttpPostedFile
postedFile, String nodeId, String mediaRoot, String type)
Now, we noticed that if we disabled the instantiations that were attached to the Document.AfterPublish event, the exception went away. Enabling the instantiations makes workflow throw the same exception again.
So, our question is: Does anybody know why is workflow trying to validate criteria when programmatically publishing a node? Is there any way to prevent this? We believe that the problem occurs when the ValidateCriteria() method tries to get the current user and that operation returns null. Is that correct?
The publish event fires whether you publish in the back office or programatically - there is no way to prevent this. A programatic publish and a back office publish is the same, they use the same code.
The issue that you describe does make sense. when validating a criteria workflow does the following:
var u = User.GetCurrent();
Log.Debug(string.Format("Validating criteria for user '{0}' - '{1}'", u.LoginName, u.Id));
I would describe that as being a bug in Workflow. The simplest way to resolve this would be to patch workflow, though the version that you use is very dated and not supported by Moriyama any longer.
If you'd like we can give you access to the old repository, so you can add a null check on the user?
Yes, we would like to have access to the old repository to make the specified changes. We would have to get in contact with you so you can give us instructions on how to compile the code correctly (remember you had to do that remotely the last time?). We need to do these changes quite quickly because this issue is really starting to mess up one of our client's website.
We appreciate any kind of assistance and hope to hear back from you soon.
I've added a null check so that your error doesn't happen.
Lastly, place the DLL from your project into your site and configure workflow to use your own event service in /config/fmworkflow/workflow.application.spring.config
Workflow interferes with publication of programmatically created nodes
Hello everyone,
We are working on an Umbraco 4.7.2 site with Workflow for Umbraco 2.1. We've been using the package for quite a while and it has given us no trouble at all so far. Unfortunately, we came across a little problem these last couple of days. What happens is the following:
The site we are working on has 5 workflow configurations and 5 instantiation criterias. 4 out of the 5 instatiation criterias have the Document.AfterPublish event assigned as their Instantiating Event. We created a usercontrol that receives data from a webform, updates a node in the Content section and publishes it. The problem is that when the usercontrol tries to publish the node, workflow throws a Object reference not set to an instance of an object exception. The stacktrace is the following:
Now, we noticed that if we disabled the instantiations that were attached to the Document.AfterPublish event, the exception went away. Enabling the instantiations makes workflow throw the same exception again.
So, our question is: Does anybody know why is workflow trying to validate criteria when programmatically publishing a node? Is there any way to prevent this? We believe that the problem occurs when the ValidateCriteria() method tries to get the current user and that operation returns null. Is that correct?
Hi Nicolás,
The publish event fires whether you publish in the back office or programatically - there is no way to prevent this. A programatic publish and a back office publish is the same, they use the same code.
The issue that you describe does make sense. when validating a criteria workflow does the following:
This would cause the exception that you describe.
I would describe that as being a bug in Workflow. The simplest way to resolve this would be to patch workflow, though the version that you use is very dated and not supported by Moriyama any longer.
If you'd like we can give you access to the old repository, so you can add a null check on the user?
Many Thanks
Hi Darren,
Yes, we would like to have access to the old repository to make the specified changes. We would have to get in contact with you so you can give us instructions on how to compile the code correctly (remember you had to do that remotely the last time?). We need to do these changes quite quickly because this issue is really starting to mess up one of our client's website.
We appreciate any kind of assistance and hope to hear back from you soon.
Thanks.
I'm sorry for the delay
I've been looking into your issue - and the easiest solution would be to override ValidateCriteria method the that is causing your issues.
You should see it has the following signature:
protected override bool ValidateCriteria(IWorkflowInstantiationCriteria criteria)
So if you create a new Visual studio project and reference the Workflow DLLs you could create a class with the following signature.
public class MyUmbracoEventService : UmbracoEventService
Next override the method that is causing your issue like this:
protected override bool ValidateCriteria(IWorkflowInstantiationCriteria criteria)
{
var u = User.GetCurrent();
if (u == null)
return false;
Log.Debug(string.Format("Validating criteria for user '{0}' - '{1}'", u.LoginName, u.Id));
return TheCriteriaValidationService.IsCriteriaValid((UmbracoWorkflowInstantiationCriteria) criteria, User.GetCurrent());
}
I've added a null check so that your error doesn't happen.
Lastly, place the DLL from your project into your site and configure workflow to use your own event service in /config/fmworkflow/workflow.application.spring.config
You'll see this declaration:
<object id="EventService"
type="FergusonMoriyam.Workflow.Umbraco.Application.UmbracoEventService, FergusonMoriyama.Umbraco4.Workflow"
factory-method="get_Instance">
You'll need to change the type and assembly declaration to match your implementation.
If you are unsure of how to do this. Please provide me with a zip of your bin directory and I will do this for you.
is working on a reply...