--- comment_cck.module	Wed Jul 22 17:21:53 2009
+++ comment_cck.module	Fri Oct 29 17:05:10 2010
@@ -5,14 +5,14 @@
  * Implementation of hook_perm().
  */
 function comment_cck_perm() {
-  return array('change cck fields through comments');
+  return array('change cck fields through comments','change cck fields when editing comments');
 }
 
 /**
  * Implementation of hook_form_alter().
  */
 function comment_cck_form_alter(&$form, &$form_state, $form_id) {
-  if ($form_id == 'comment_form' && user_access('change cck fields through comments')) {
+  if ($form_id == 'comment_form' && user_access('change cck fields through comments') && (!strstr($form['#action'],'edit') || user_access('change cck fields when editing comments'))) {
     $node = node_load($form['nid']['#value']);
     // Check if any fields in this node type are comment_cck enabled.
     if ($fields = variable_get('comment_cck_fields_'. $node->type, array())) {
@@ -97,31 +101,40 @@
   }
 
   switch ($op) {
-    case 'update': case 'insert':
+    case 'update':
       $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);
-        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;
-        }
+        // 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);
+        node_load($comment['nid'], NULL, TRUE);
+      }
+      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.
+        $comment['revision_id'] = $node->vid;
+        node_load($comment['nid'], NULL, TRUE);
       }
       break;
