From 0166131e7e7c159e77c3a6903be63b73681ee2de Mon Sep 17 00:00:00 2001
From: saubhagya <saubhagyamaheshwari@gmail.com>
Date: Sun, 6 Jun 2010 22:38:39 +0530
Subject: [PATCH] first patch

---
 rules/includes/rules.plugins.inc |   68 +++++++++++++------------------------
 rules/rules.module               |   34 +++++--------------
 2 files changed, 33 insertions(+), 69 deletions(-)

diff --git a/rules/includes/rules.plugins.inc b/rules/includes/rules.plugins.inc
index 15e2f23..466a9fb 100644
--- a/rules/includes/rules.plugins.inc
+++ b/rules/includes/rules.plugins.inc
@@ -18,9 +18,7 @@ class RulesAction extends RulesAbstractPlugin implements RulesActionInterface {
    */
   protected function executeCallback(array $args, RulesState $state = NULL) {
     rules_log('Evaluating the action %name.', array('%name' => $this->elementName));
-    $return = $this->__call('execute', empty($this->info['named parameter']) ? $args : array($args));
-    // Get the (partially) wrapped arguments.
-    $args = $state->currentArguments;
+    $return = $this->__call('execute', rules_unwrap_data($args, $this->info['parameter']));
 
     if (is_array($return)) {
       foreach ($return as $name => $data) {
@@ -78,16 +76,12 @@ class RulesCondition extends RulesAbstractPlugin implements RulesConditionInterf
   }
 
   public function negate($negate = TRUE) {
-    $this->negate = (bool) $negate;
+    $this->negate = $negate;
     return $this;
   }
 
-  public function isNegated() {
-    return $this->negate;
-  }
-
   protected function executeCallback(array $args, RulesState $state = NULL) {
-    $return = (bool) $this->__call('execute', empty($this->info['named parameter']) ? $args : array($args));
+    $return = (bool)$this->__call('execute', rules_unwrap_data($args));
     rules_log('The condition %name evaluated to %bool', array('%name' => $this->elementName, '%bool' => $return ? 'TRUE' : 'FALSE'));
     return $this->negate ? !$return : $return;
   }
@@ -110,11 +104,6 @@ class RulesCondition extends RulesAbstractPlugin implements RulesConditionInterf
     $export = array($not . $this->elementName => $export['USING']);
     return $this->isRoot() ? $this->returnExport($export, $php) : $export;
   }
-
-  public function label() {
-    $label = parent::label();
-    return $this->negate ? t('NOT @condition', array('@condition' => $label)) : $label;
-  }
 }
 
 /**
@@ -231,12 +220,7 @@ class Rule extends RulesActionContainer {
     if (isset($element) && $element === $this->conditions) {
       return $this->availableVariables();
     }
-    $vars = parent::stateVariables($element);
-    // Take variable info assertions of conditions into account.
-    if (isset($this->conditions) && $assertions = $this->conditions->variableInfoAssertions()) {
-      $vars = RulesData::addMetadataAssertions($vars, $assertions);
-    }
-    return $vars;
+    return parent::stateVariables($element);
   }
 
   protected function exportChildren($key = NULL) {
@@ -398,24 +382,6 @@ class RulesOr extends RulesConditionContainer {
   public function label() {
     return !empty($this->label) ? $this->label : ($this->negate ? t('NOT OR') : t('OR'));
   }
-
-  /**
-   * Overridden to exclude all variable assertions as in an OR we cannot assert
-   * the children are successfully evaluated.
-   */
-  protected function stateVariables($element = NULL) {
-    $vars = $this->availableVariables();
-    if (isset($element)) {
-      // Add in variables provided by siblings executed before the element.
-      foreach ($this->children as $child) {
-        if ($child === $element) {
-          break;
-        }
-        $vars += $child->providesVariables();
-      }
-    }
-    return $vars;
-  }
 }
 
 /**
@@ -569,9 +535,7 @@ class RulesEventSet extends RulesRuleSet {
       if ($rules = rules_config_load_multiple(FALSE, array('event' => $name, 'active' => TRUE))) {
         $event = new RulesEventSet($info);
         $event->name = $name;
-        foreach ($rules as $rule) {
-          $event->rule($rule);
-        }
+        $event->optimize($rules);
         $event->setSkipSetup();
         cache_set('event_' . $name, $event, 'cache_rules');
         $event->destroy();
@@ -584,8 +548,24 @@ class RulesEventSet extends RulesRuleSet {
     // See rules_get_event_set().
     variable_set('rules_empty_sets', array_flip($empty));
   }
+}
 
-  protected function stateVariables($element = NULL) {
-    return $this->availableVariables();
-  }
+/**
+ * Interface for optimized rules
+ */
+interface RulesOptimizationInterface {
+  /**
+   * Convert the input rules into a decision tree structure
+   * 
+   * @param $rules
+   *   All the rules trigerrable by the RulesRuleSet or RulesEventSet  
+   */
+  public function optimize($rules);
 }
+
+/**
+ * Class implementing optimization method
+ */
+class RulesOptimization extends FacesExtender implements RulesOptimizationInterface {
+  public function optimize($rules){}
+}
\ No newline at end of file
diff --git a/rules/rules.module b/rules/rules.module
index a2b9046..5108563 100644
--- a/rules/rules.module
+++ b/rules/rules.module
@@ -257,8 +257,8 @@ function &rules_wrap_data(&$data = NULL, $info, $force = FALSE) {
   }
   $type = entity_metadata_list_extract_type($info['type']) ? 'list' : $info['type'];
   $cache = rules_get_cache();
-  if (isset($cache['data_info'][$type]['property info'])) {
-    $info['property info'] = $cache['data_info'][$type]['property info'];
+  if (isset($cache['data_info'][$type]['data info'])) {
+    $info['data info'] = $cache['data_info'][$type]['data info'];
   }
   // By default we do not wrap the data, except for completely unknown types.
   if (!empty($cache['data_info'][$type]['wrap']) || $force || empty($cache['data_info'][$type])) {
@@ -357,7 +357,7 @@ function rules_rules_plugin_info() {
       'extenders' => array(
         'RulesPluginUIInterface' => array(
           'class' => 'RulesRuleUI',
-        ),
+        ), 
       ),
     ),
     'loop' => array(
@@ -381,6 +381,11 @@ function rules_rules_plugin_info() {
     'event set' => array(
       'class' => 'RulesEventSet',
       'embeddable' => FALSE,
+      'extenders' => array(
+        'RulesOptimizationInterface' => array(
+          'class' => 'RulesOptimization',
+        ),
+      ),
     ),
     'rule set' => array(
       'class' => 'RulesRuleSet',
@@ -729,13 +734,6 @@ function rules_menu() {
     'type' => MENU_CALLBACK,
     'file' => 'ui/ui.forms.inc',
   );
-  $items[RULES_UI_RULE_PATH . '/%rules_config/autocomplete'] = array(
-    'page callback' => 'rules_ui_form_data_selection_auto_completion',
-    'page arguments' => array(7, 8, 9),
-    'access arguments' => array('administer rules'),
-    'type' => MENU_CALLBACK,
-    'file' => 'ui/ui.forms.inc',
-  );
   $items[RULES_UI_RULE_PATH . '/%rules_config/delete/%rules_element'] = array(
     'title callback' => 'rules_get_title',
     'title arguments' => array('Editing @plugin "@label"', 7),
@@ -753,7 +751,7 @@ function rules_menu() {
     'type' => MENU_CALLBACK,
     'file' => 'ui/ui.forms.inc',
   );
-  $items[RULES_UI_RULE_PATH . '/%rules_config/event/delete'] = array(
+  $items[RULES_UI_RULE_PATH . '/%rules_config/event/remove'] = array(
     //@todo: improve title.
     'title' => 'Remove event',
     'page callback' => 'drupal_get_form',
@@ -858,17 +856,3 @@ function rules_element_info() {
   return $types;
 }
 
-/**
- * Implements hook_modules_enabled().
- */
-function rules_modules_enabled($modules) {
-  rules_clear_cache();
-}
-
-/**
- * Implements hook_modules_disabled().
- */
-function rules_modules_disbled($modules) {
-  rules_clear_cache();
-  //TODO: Disable configs with now broken dependencies?
-}
-- 
1.7.0.2.msysgit.0

