summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaurits Lawende2012-08-20 13:18:45 (GMT)
committer Maurits Lawende2012-08-20 13:18:45 (GMT)
commit92fcf32c048446e186e458997c459e377c799791 (patch)
tree6e93edf7f48d5d48cfa14808e73f6acda5b1dd0b
parentf6106f6a38545adf6f055e1859b66b267650888d (diff)
Renumber rule id's in features export to keep export consistent
-rw-r--r--hansel.export.inc36
1 files changed, 34 insertions, 2 deletions
diff --git a/hansel.export.inc b/hansel.export.inc
index 15f922e..37e46bc 100644
--- a/hansel.export.inc
+++ b/hansel.export.inc
@@ -6,7 +6,39 @@
* @return array
*/
function hansel_export_config() {
- return hansel_get_config();
+ $config = hansel_get_config();
+ $mapping = array();
+
+ $export = array(
+ 'version' => $config['version'],
+ 'start_rid' => 0,
+ 'rules' => array(),
+ 'nodetypes' => $config['nodetypes'],
+ );
+
+ // Copy rules and renumber them.
+ $id = 0;
+ foreach ($config['rules'] as $rule) {
+ ++$id;
+ $mapping[$rule->rid] = $id;
+ $rule->rid = $id;
+ $export['rules'][$id] = clone $rule;
+ }
+
+ // Map start rule.
+ $export['start_rid'] = $mapping[$config['start_rid']];
+
+ // Map parents and destinations.
+ foreach ($export['rules'] as $id => $rule) {
+ if ($rule->pid) {
+ $export['rules'][$id]->pid = $mapping[$rule->pid];
+ }
+ if ($rule->action == 'goto') {
+ $export['rules'][$id]->destination = $mapping[$rule->destination];
+ }
+ }
+
+ return $export;
}
/**
@@ -27,7 +59,7 @@ function hansel_import_config($config) {
// Store all rules without actions and parent id's first, we will update
// those later cause we don't have a complete mapping here.
foreach ($config['rules'] as $rule) {
- if (is_array($rule)) {
+ if (is_array($rule)) {
// The input can be an array because we use features_var_export().
$rule = (object) $rule;
}