When using some action that injects a new variable into the rule (e.g. "Load content by id" or "Add a new string varibale"), we're asked to type the "Machine readable variable name". We're warned that this name should be unique.

Rules then tries to validate for uniqueness, in rules_admin_new_variables_form_validate(), but it fails in this task.

Comments

fago’s picture

Component: Rules Core » Rules Engine

bump, need to have a look at that.

mooffie’s picture

I still remember something of this.

One bug is that get_available_variables() do "return rules_admin_element_filter($vars)" instead of "return array_filter($vars, 'rules_admin_element_filter')".

Another is that _get_available_variables() has the following:

   function _get_available_variables($all = FALSE) {
     if (!isset($this->_variables)) {
       $this->_variables = array();

In other words, the $this->_variables cache is used for both $all and !$all. This isn't alright.

I fixed these two bugs in my loop patch. Here's a paste:

Index: rules.admin_rule_proxy.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/rules/rules/Attic/rules.admin_rule_proxy.inc,v
retrieving revision 1.1.2.15
diff -u -F^[^a-z]*function -r1.1.2.15 rules.admin_rule_proxy.inc
--- rules.admin_rule_proxy.inc	24 Sep 2008 14:48:55 -0000	1.1.2.15
+++ rules.admin_rule_proxy.inc	21 Nov 2008 09:03:42 -0000
@@ -258,7 +343,9 @@   function get_defined_variables($id = N
     if (isset($id)) {
       $vars = array_diff_assoc($vars, $this->element_get_new_variables($this->get_element($id)));
     }
-    return rules_admin_element_filter($vars);
+    // @glitch
+    // Rules bug.
+    return array_filter($vars, 'rules_admin_element_filter');
   }
 
   /**
@@ -267,8 +354,10 @@   function get_defined_variables($id = N
    * @param $all If set to TRUE all variables defined in this rule set will returned.
    */
   function _get_available_variables($all = FALSE) {
-    if (!isset($this->_variables)) {
-      $this->_variables = array();
+    // @glitch
+    // Rules bug. $this->_variables stored both $all and !$all.
+    if (!isset($this->_variables[$all])) {
+      $this->_variables[$all] = array();
       $set = $this->get_set();
 
       //sort the rules
@@ -277,15 +366,14 @@   function _get_available_variables($all
       foreach (element_children($set['rules']) as $name) {
         if ($name == $this->get_rule_name()) {
           if (!$all) {
-            return $this->_variables;
+            return $this->_variables[$all];
           }
         }
-        foreach ($set['rules'][$name]['#actions'] as $action) {
-          $info = rules_get_element_info($action);
-          $this->_variables += $info['new variables'];
+        if (isset($set['rules'][$name]['#actions'])) {
+          $this->_variables[$all] += $this->_get_tree_new_variables($set['rules'][$name]['#actions'], $all);
         }
       }
     }
-    return $this->_variables;
+    return $this->_variables[$all];
   }
 }

(I don't remember if that's all that's needed to fix this issue's bug.)

mitchell’s picture

Status: Active » Needs review
fago’s picture

Status: Needs review » Fixed

I've fixed that recently, before releasing beta5.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.