? 858274_api_functions.patch
? 889410_comments.patch
? tests
? uuid-api.patch
Index: uuid.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uuid/uuid.admin.inc,v
retrieving revision 1.4
diff -u -p -r1.4 uuid.admin.inc
--- uuid.admin.inc	11 Jun 2010 04:06:52 -0000	1.4
+++ uuid.admin.inc	8 Sep 2010 13:34:41 -0000
@@ -63,6 +63,22 @@ function uuid_admin() {
     );
   }
 
+  $form['comment'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Comment settings'),
+  );
+  $form['comment']['uuid_automatic_for_comments'] = array(
+    '#type' => 'radios',
+    '#title' => t('Automatic UUID generation for comments'),
+    '#default_value' => variable_get('uuid_automatic_for_comments', FALSE),
+    '#options' => array(
+      TRUE => t('Enabled'),
+      FALSE => t('Disabled'),
+    ),
+    '#description' => t('Should UUIDs be created automatically for comments?'),
+  );
+
+
   $form['settings'] = array(
     '#type' => 'fieldset',
     '#title' => t('Synchronization'),
@@ -89,6 +105,14 @@ function uuid_sync() {
     }
   }
 
+  // Comments.
+  if (variable_get('uuid_automatic_for_comments', FALSE)) {
+    $result = db_query("SELECT cid FROM {comments} WHERE cid NOT IN (SELECT cid FROM {uuid_comments})");
+    while($item = db_fetch_object($result)) {
+      db_query("INSERT INTO {uuid_comments} (cid, uuid) VALUES(%d, '%s')", $item->cid, uuid_uuid());
+    }
+  }
+
   $types = variable_get('uuid_automatic_for_nodes', array());
 
   // Remove disabled node types.
Index: uuid.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uuid/uuid.install,v
retrieving revision 1.4
diff -u -p -r1.4 uuid.install
--- uuid.install	11 Jun 2010 04:06:52 -0000	1.4
+++ uuid.install	8 Sep 2010 13:34:42 -0000
@@ -32,6 +32,7 @@ function uuid_schema() {
     'uuid_users' => uuid_table_schema('users', 'uid'),
     'uuid_vocabulary' => uuid_table_schema('vocabulary', 'vid'),
     'uuid_term_data' => uuid_table_schema('term_data', 'tid'),
+    'uuid_comments' => uuid_table_schema('comments', 'cid'),
   );
 }
 
@@ -76,6 +77,7 @@ function uuid_uninstall() {
   variable_del('uuid_automatic_for_nodes');
   variable_del('uuid_automatic_for_users');
   variable_del('uuid_automatic_for_taxonomy');
+  variable_del('uuid_automatic_for_comments');
 
   // Remove tables.
   drupal_uninstall_schema('uuid');
@@ -107,3 +109,14 @@ function uuid_update_6002() {
 
   return $ret;
 }
+
+/**
+ * Create uuid_comment table.
+ */
+function uuid_update_6003() {
+  $ret = array();
+
+  db_create_table($ret, 'uuid_comments', uuid_table_schema('comments', 'cid'));
+
+  return $ret;
+}
Index: uuid.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uuid/uuid.module,v
retrieving revision 1.4
diff -u -p -r1.4 uuid.module
--- uuid.module	11 Jun 2010 04:06:52 -0000	1.4
+++ uuid.module	8 Sep 2010 13:34:44 -0000
@@ -200,6 +200,39 @@ function uuid_taxonomy($op, $type, $arra
 }
 
 /**
+ * Implementation of hook_comment().
+ */
+function uuid_comment(&$a1, $op) {
+  switch ($op) {
+    // Make sure that a new entry gets made in the comments_uuid table when new content
+    // is added.
+    case 'insert':
+      if (!empty($a1['uuid']) && uuid_is_valid($a1['uuid'])) {
+        db_query("INSERT INTO {uuid_comments} (cid, uuid) VALUES (%d, '%s')", $a1['cid'], $a1['uuid']);
+      }
+      else if (variable_get('uuid_automatic_for_comments', FALSE)) {
+        db_query("INSERT INTO {uuid_comments} (cid, uuid) VALUES (%d, '%s')", $a1['cid'], uuid_uuid());
+      }
+      break;
+      
+    case 'update':
+      if (isset($a1['uuid']) && uuid_is_valid($a1['uuid'])) {
+        $exists = db_result(db_query('SELECT 1 FROM {uuid_comments} WHERE cid = %d', $a1['cid']));
+
+        if (!$exists && variable_get('uuid_automatic_for_comments', FALSE)) {
+          db_query("INSERT INTO {uuid_comments} (cid, uuid) VALUES (%d, '%s')", $a1['cid'], uuid_uuid());
+        }
+      }
+      break;
+
+    // Clean up comments_uuid table when content is deleted.
+    case 'delete':
+      db_query("DELETE FROM {uuid_comments} WHERE cid = %d", $a1->cid);
+      break;
+  }
+}
+
+/**
  * Determines if a UUID is valid.
  */
 function uuid_is_valid($uuid) {
