Tuesday, 14 May 2013


I had a little affair with Rules today. I was so deep inside of it, I never thought I could go that far. And nobody hurt. Being gentle and take a lot of attention pays back.

I was using a rule to execute custom actions when a workflow state is changed. It worked - sometimes. Sometimes not. I was suspicious of a custom code. The way to make it in code is to call workflow_transition(). It's not too much to screw up here, it expects a node object and a workflow state. So what the heck, let's debug. First you enter to the realm of workflow. It's doing a lot of make up, check and validation till it gets to the point it does the change. What you have to look for is the connection to Rules. Rules is not a god, just a simple module. So it has to use hooks. Workflow has a separate connector module: workflow_rules to handle that part. After a little grepping you will find the rules event definition for workflow. And there you can find the function. Which is a hook. So then you have to see which workflow function calls that hook. And then you can go back and find the post transaction hook. So far it's pretty clear. Then we entered Rules. I could use the famous meme: brace yourself, evals are coming. Rules first needs to load the main configuration, then the hooks, the events, the potential objects, the rules, the triggers and conditions of the rules .. a lot of things. And they mostly use evals. You have to be really careful not to skip any important one. But eventually you got your princess, I mean the point when you're about to call the final action. And there I've found the problem. My custom rules action had a parameter, which wasn't used if the transition change doesn't happen in a node update. (To be precise in that case there is only one node object in the context.)

So I just removed it and it works now. What was surprising that the error message (that I found later) only said it couldn't eval the expression. Which was - let's be frank - short for a help. Anyways, day is saved.

Then I've just got the notification email that tomorrow's web performance meetup was cancelled - sad face.

In the evening my mind was full of duck, but still managed to get my hands on two books regarding BackboneJS. Very much looking forward to read them.



No comments:

Post a Comment