Currently Rules only makes an intersection of the variables of all events assigned to a rule available. However it would be useful if one could make use of all variables.
If a not-defined variable is accessed, rules would error out anyway. One can check for empty-variables though.

With that one could easily do rules like:
if a node has been inserted or a node has been updated and the node status has been changed to published, do something.

To figure out whether the node status has been changed, one would have to compare the unchanged-status with the now one, i.e. one needs access to node_unchanged - for what this improvement is needed.

Patch attached, which works for me.
Also it would be nice to have a condition to check for the event that actually triggered a rule, but that could be a follow-up.

CommentFileSizeAuthor
rules_event.patch1005 bytesfago
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

klausi’s picture

Component: Rules Core » Rules Engine

I find it akward if there are top level variables in Rules that are sometimes NULL and sometimes not. I can accept that fact for fields and other properties, but otherwise I think it is a nice benefit that we can rely on top level variables. What happens if those empty variables are passed down to components? Do we have to check now each and every variable before we make use of them? I'm not convinced of this approach, more input welcome.

fago’s picture

>Do we have to check now each and every variable before we make use of them?
hm, indeed this puts the burden on the site-builder to know which variables might be empty and to check them. Although that party is already the case, e.g. for fields or all properties.

>I'm not convinced of this approach, more input welcome.
I'm not 100% sure either. Yep, more input would be great :)

Here is a a recent example rule I did which only works with the patch:

{ "rules_commerce_sp_subscription_started" : {
    "LABEL" : "Subscription started",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "commerce_sp" ],
    "REQUIRES" : [ "rules", "rules_scheduler" ],
    "ON" : [ "user_update", "user_insert" ],
    "IF" : [
      { "NOT data_is_empty" : { "data" : [ "account:field-commerce-sp-validity" ] } },
      { "OR" : [
          { "entity_is_new" : { "entity" : [ "account" ] } },
          { "data_is_empty" : { "data" : [ "account-unchanged:field-commerce-sp-validity" ] } }
        ]
      }
    ],
    "DO" : [
      { "component_rules_commerce_sp_subscription_start" : { "user" : [ "account" ] } },
      { "schedule" : {
          "component" : "rules_commerce_sp_subscription_end",
          "date" : [ "account:field-commerce-sp-validity" ],
          "identifier" : "expire-[account:uid]",
          "param_user" : [ "account" ]
        }
      }
    ]
  }
}
fago’s picture

Status: Needs review » Postponed

Well, coming back to this now, I must agree that making it possible to use not defined variables is kind of ugly. Let's don't do it for now.

fago’s picture

Issue summary: View changes

improved example

TR’s picture

Component: Rules Engine » Rules Core
Issue summary: View changes
Status: Postponed » Closed (won't fix)

It's been more than seven years, and no compelling use case for this has emerged. Nor have we received any contributions from the community on this issue. I agree with the sentiments expressed in #1 and #3, and I am now marking this as "Won't fix".