From f73e5dbcb113d611a82dc4314b529620e79c58d9 Mon Sep 17 00:00:00 2001
From: James Wilson <jrguitar21@gmail.com>
Date: Wed, 2 Mar 2011 12:30:43 -0500
Subject: [PATCH] Issue #928178 by jrguitar21, DamienMcKenna: Always export rules in the same order.

---
 rules/rules.export.inc |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/rules/rules.export.inc b/rules/rules.export.inc
index 4cda53b..cfb9f6a 100644
--- a/rules/rules.export.inc
+++ b/rules/rules.export.inc
@@ -14,8 +14,11 @@ function rules_export_items($export, $module = NULL) {
     // Allow item specific adaption before exporting
     foreach ($export[$item_type] as $item_name => $item) {
       rules_item_type_invoke($item_type, 'export', array($item_name, &$export[$item_type][$item_name], &$export, $module));
+      ksort($export[$item_type]);
     }
   }
+  // Sort the elements to avoid problems DIFFing the output between exports.
+  ksort($export);
   return $export;
 }
 
@@ -36,6 +39,10 @@ function rules_item_rule_set_export($set_name, &$rule_set, &$export, $module = N
     $rule_set['categories'][$module] = $module;
     $rule_set['status'] = 'default';
   }
+  // Sort the elements to avoid problems DIFFing the output between exports.
+  if (!empty($rule_set)) {
+    ksort($rule_set);
+  }
 }
 
 
@@ -57,6 +64,18 @@ function rules_item_rule_export($rule_name, &$rule, &$export, $module = NULL) {
       $rule['#categories'][$module] = $module;
     }
   }
+  // Sort the elements to avoid problems DIFFing the output between exports.
+  ksort($rule);
+  foreach($rule['#actions'] as $action_index => $action) {
+    ksort($rule['#actions'][$action_index]);
+    ksort($rule['#actions'][$action_index]['#info']);
+    ksort($rule['#actions'][$action_index]['#settings']);
+  }
+  foreach($rule['#conditions'] as $condition_index => $condition) {
+    ksort($rule['#conditions'][$condition_index]);
+    ksort($rule['#conditions'][$condition_index]['#info']);
+    ksort($rule['#conditions'][$condition_index]['#settings']);
+  }
 }
 
 /**
-- 
1.7.0.3

