I'm trying to learn the rules module, so I can start using it instead of hard-coding all my rules into my modules.

I'm trying to learn components. My goal is a condition component that does the following:
1) Checks to see if the content has been promoted to the front page AND
2) Either is a new node, or the node was not previously promoted to the front page
In programming terms: (is_promoted && (is_new OR was_not_previously_promoted))

I've done the following:
1) Created a new 'AND' component
2) Under settings, I added two data types, 'saved content' and 'unsaved content', both of which are of data type 'Node'
3) I added a condition 'Content is promoted to frontpage'
Parameter: Content: [node]'

At this point, in my rule, I add my condition, passing in the node for 'saved content', and the 'unchanged node' for 'unsaved content' and when I create a new node, my action is not triggered. Using the rules debug, I see the following output:

0 ms Reacting on event Before saving content.
12.808 ms Evaluating conditions of rule Notify admins on new to page content. [edit]
13.52 ms Unable to load variable node_unchanged, aborting.
16.976 ms Unable to evaluate condition component_rules_content_promoted_to_front_page. [edit]
...

I know that I'm not using the node_unchanged yet, but I will be using it in further development of the rule.

I cannot understand why Rules is unable to evaluate the condition. The node obviously has the condition (whether true or false), as it's part of core. So why can't Rules evaluate it? Does it have something to do with the abort that comes before it? But if it does, I don't understand, as I'm checking the condition on the 'saved content' node which does exist, not on the 'node_unchanged' node which doesn't exist.

Any thoughts?

Comments

TR’s picture

Status: Active » Closed (cannot reproduce)

Can't really help you without an export of your Rule. The event you're reacting on determines which context variables are made available to your conditions. For example, if you're reacting on "After saving new content" then of course there will be no node_unchanged, while if you are reacting on "After updating existing content" then of course there SHOULD be a node_unchanged.

If you try to use node_unchanged in one of your conditions, and if the event doesn't provide node_unchanged, then there will be an error. If this is a component and you've defined one of the input variables as node_unchanged, then Rules will check to ensure that variable is available before executing the component, even if you're not using the variable in the component.

So if this is still a problem for you in the current version of Rules, feel free to reopen this issue with an export of a simplified version of your rule (don't include all sorts of extra actions and other things that don't affect the problem), and include details about how to reproduce the problem.

Jaypan’s picture

I opened this four years ago. I can't even remember what project it was on, but I'm pretty sure I abandoned using the Rules module around that time because I couldn't figure out issues like this.