? comment_cck_fieldgroup_refactor.patch
Index: comment_cck.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/comment_cck/comment_cck.module,v
retrieving revision 1.13
diff -u -p -r1.13 comment_cck.module
--- comment_cck.module	8 May 2009 18:59:42 -0000	1.13
+++ comment_cck.module	22 Jul 2009 10:39:26 -0000
@@ -97,39 +97,31 @@ function comment_cck_comment(&$comment, 
   }
 
   switch ($op) {
-    case 'update':
+    case 'update': case 'insert':
       $original_node = node_load($comment['nid']);
       if ($fields = variable_get('comment_cck_fields_'. $original_node->type, array())) {
         // Ungroup the fields in this comment, if necessary.
         $comment_fields = _comment_cck_ungroup_fields($comment['comment_cck'], $fields, $original_node->type);
         // Merge the updated fields in this comment with the original node.
         $node = (object) array_merge((array) $original_node, $comment_fields);
-        // We don't want a node revision, since we're updating an old comment.
-        // @TODO: Do we?
-        $node->revision = 0;
-        $node->vid = db_result(db_query('SELECT vid FROM {comment_cck_revisions} WHERE cid = %d', $comment['cid']));
-        // Save the node with the updated field data.
-        node_save($node);
-      }
-      break;
-
-    case 'insert':
-      $original_node = node_load($comment['nid']);
-      if ($fields = variable_get('comment_cck_fields_'. $original_node->type, array())) {
-        // Ungroup the fields in this comment, if necessary.
-        $comment_fields = _comment_cck_ungroup_fields($comment['comment_cck'], $fields, $original_node->type);
-        // Merge the updated fields in this comment with the original node.
-        $node = (object) array_merge((array) $original_node, $comment_fields);
-        $previous_vid = $node->vid;
-        // We do want a node revision, since this is a new comment.
-        $node->revision = 1;
-        // Save the node with the updated field data.
-        node_save($node);
-        // Record that this comment added a node revision.
-        db_query('INSERT INTO {comment_cck_revisions} (cid, vid, previous_vid) VALUES (%d, %d, %d)', $comment['cid'], $node->vid, $previous_vid);
-        // Update the comment revision id.
-        // @TODO: What is this needed for?
-        $comment['revision_id'] = $node->vid;
+        if($op == 'update') {
+          // We don't want a node revision, since we're updating an old comment.
+          // @TODO: Do we?
+          $node->revision = 0;
+          $node->vid = db_result(db_query('SELECT vid FROM {comment_cck_revisions} WHERE cid = %d', $comment['cid']));
+          // Save the node with the updated field data.
+          node_save($node);
+        }
+        else {
+          $node->revision = 1;
+          // Save the node with the updated field data.
+          node_save($node);
+          // Record that this comment added a node revision.
+          db_query('INSERT INTO {comment_cck_revisions} (cid, vid, previous_vid) VALUES (%d, %d, %d)', $comment['cid'], $node->vid, $previous_vid);
+          // Update the comment revision id.
+          // @TODO: What is this needed for?
+          $comment['revision_id'] = $node->vid;
+        }
       }
       break;
 
@@ -248,6 +240,8 @@ function _comment_cck_ungroup_fields($co
     }
     return $comment_fields_flat;
   }
+
+  return $comment_fields;
 }
 
 /**
