Index: CHANGELOG.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/input_formats/CHANGELOG.txt,v
retrieving revision 1.2
diff -u -p -r1.2 CHANGELOG.txt
--- CHANGELOG.txt	10 Jun 2010 13:49:21 -0000	1.2
+++ CHANGELOG.txt	10 Jun 2010 14:36:11 -0000
@@ -3,6 +3,7 @@
 Input Formats 6.x-1.0-dev
 -------------------------
 
+- #820956: Preserve previous defined machine names each time input formats module is enabled.
 - #819860: Provide a new permission to import input formats.
 - #821036: Wysiwyg support. requires a patched version of wysiwyg, see: http://drupal.org/node/624018
 
Index: input_formats.api.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/input_formats/input_formats.api.inc,v
retrieving revision 1.1
diff -u -p -r1.1 input_formats.api.inc
--- input_formats.api.inc	5 Jun 2010 01:42:10 -0000	1.1
+++ input_formats.api.inc	10 Jun 2010 14:36:12 -0000
@@ -36,11 +36,24 @@ function input_formats_api_syncronize() 
  * Create the machine names for the existents input formats
  */
 function input_formats_api_sync_names() {
+  // Get all the machine names for input formats
+  $input_formats = input_formats_api_get_input_formats();
+  // Remove all the input_formats names
   db_query("TRUNCATE {input_formats}");
+  // Now, check if new filters were created while input formats was disabled
   $res = db_query("SELECT format, name FROM {filter_formats}");
+  $filters = array();
   while ($filter = db_fetch_object($res)) {
-    $machine_name = str_replace(' ', '_', strtolower($filter->name));
-    db_query("INSERT INTO {input_formats} (format, name, overriden) VALUES (%d, '%s', 0)", $filter->format, $machine_name);
+    $filters[$filter->format] = 1;
+    if (!isset($input_formats[$filter->format])) {
+      $input_formats[$filter->format] = str_replace(' ', '_', strtolower($filter->name));
+    }
+  }
+  // Finally, just add input formats for active filters
+  foreach ($input_formats as $format => $machine_name) {
+    if (!empty($filters[$format])) {
+      db_query("INSERT INTO {input_formats} (format, name, overriden) VALUES (%d, '%s', 0)", $format, $machine_name);
+    }
   }
 }
 
@@ -177,6 +190,17 @@ function input_formats_api_get_machine_n
   return db_result(db_query("SELECT name FROM {input_formats} WHERE format = %d", $format));
 }
 
+/**
+ * Get all the input formats using numeric id as key.
+ */
+function input_formats_api_get_input_formats() {
+  $input_formats = array();
+  $res = db_query("SELECT f.format, i.name FROM {filter_formats} f INNER JOIN {input_formats} i ON i.format = f.format");
+  while ($ob = db_fetch_object($res)) {
+    $input_formats[$ob->format] = $ob->name;
+  }
+  return $input_formats;
+}
 
 /**
  * Check if a input format exists.
