Index: modules/comment/comment.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.admin.inc,v
retrieving revision 1.26
diff -u -p -r1.26 comment.admin.inc
--- modules/comment/comment.admin.inc	1 Jul 2009 20:39:20 -0000	1.26
+++ modules/comment/comment.admin.inc	5 Jul 2009 21:24:06 -0000
@@ -201,7 +201,7 @@ function comment_multiple_delete_confirm
     foreach ($form_state['values']['comments'] as $cid => $value) {
       $comment = comment_load($cid);
       // Perform the actual comment deletion.
-      _comment_delete_thread($comment);
+      comment_delete($comment->cid);
       _comment_update_node_statistics($comment->nid);
     }
     cache_clear_all();
@@ -216,7 +216,7 @@ function comment_multiple_delete_confirm
  * @param $cid
  *   The comment to be deleted.
  */
-function comment_delete($cid = NULL) {
+function comment_delete_page($cid = NULL) {
   $comment = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comment} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.cid = :cid', array(':cid' => $cid))->fetch();
   $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
   $output = '';
@@ -257,38 +257,10 @@ function comment_confirm_delete_submit($
   drupal_set_message(t('The comment and all its replies have been deleted.'));
   $comment = $form['#comment'];
   // Delete the comment and its replies.
-  _comment_delete_thread($comment);
+  comment_delete($comment->cid);
   _comment_update_node_statistics($comment->nid);
   // Clear the cache so an anonymous user sees that his comment was deleted.
   cache_clear_all();
 
   $form_state['redirect'] = "node/$comment->nid";
 }
-
-/**
- * Perform the actual deletion of a comment and all its replies.
- *
- * @param $comment
- *   An associative array describing the comment to be deleted.
- */
-function _comment_delete_thread($comment) {
-  if (!is_object($comment) || !is_numeric($comment->cid)) {
-    watchdog('content', 'Cannot delete non-existent comment.', array(), WATCHDOG_WARNING);
-
-    return;
-  }
-
-  // Delete the comment.
-  db_delete('comment')
-    ->condition('cid', $comment->cid)
-    ->execute();
-  watchdog('content', 'Comment: deleted %subject.', array('%subject' => $comment->subject));
-  module_invoke_all('comment_delete', $comment);
-
-  // Delete the comment's replies.
-  $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comment} c INNER JOIN {users} u ON u.uid = c.uid WHERE pid = :cid', array(':cid' => $comment->cid));
-  foreach ($result as $comment) {
-    $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
-    _comment_delete_thread($comment);
-  }
-}
Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.738
diff -u -p -r1.738 comment.module
--- modules/comment/comment.module	5 Jul 2009 18:00:08 -0000	1.738
+++ modules/comment/comment.module	5 Jul 2009 21:24:08 -0000
@@ -164,7 +164,7 @@ function comment_menu() {
   );
   $items['comment/delete'] = array(
     'title' => 'Delete comment',
-    'page callback' => 'comment_delete',
+    'page callback' => 'comment_delete_page',
     'access arguments' => array('administer comments'),
     'type' => MENU_CALLBACK,
   );
@@ -215,7 +215,16 @@ function comment_node_type($op, $info) {
   );
 
   switch ($op) {
+    case 'insert':
+      field_attach_create_bundle('comment_node_' . $info->type);
+      break;
+
+    case 'update':
+      field_attach_rename_bundle('comment_node_' . $info->old_type, 'comment_node_' . $info->new_type);
+      break;
+
     case 'delete':
+       field_attach_delete_bundle('comment_node_' . $info->type);
       foreach ($settings as $setting) {
         variable_del($setting . '_' . $info->type);
       }
@@ -728,9 +737,10 @@ function comment_node_insert($node) {
  * Implement hook_node_delete().
  */
 function comment_node_delete($node) {
-  db_delete('comment')
-    ->condition('nid', $node->nid)
-    ->execute();
+  $cids = db_query('SELECT cid FROM {comment} WHERE nid = :nid', array(':nid' => $node>nid))->fetchCol();
+  foreach ($cids as $cid) {
+    comment_delete($cid);
+  }
   db_delete('node_comment_statistics')
     ->condition('nid', $node->nid)
     ->execute();
@@ -805,7 +815,7 @@ function comment_user_cancel($edit, $acc
       foreach ($result as $cid) {
         $comment = comment_load($cid);
         // Delete the comment and its replies.
-        _comment_delete_thread($comment);
+        comment_delete($comment->cid);
         _comment_update_node_statistics($comment->nid);
       }
       break;
@@ -855,6 +865,7 @@ function comment_save($comment) {
       $comment->$key = $default;
     }
   }
+  field_attach_presave('comment', $comment);
   if ($comment->cid) {
     // Update the comment in the database.
     db_update('comment')
@@ -871,6 +882,7 @@ function comment_save($comment) {
       ))
       ->condition('cid', $comment->cid)
       ->execute();
+    field_attach_update('comment', $comment);
     // Allow modules to respond to the updating of a comment.
     module_invoke_all('comment_update', $comment);
     // Add an entry to the watchdog log.
@@ -948,6 +960,8 @@ function comment_save($comment) {
     // saved node to be propagated to the slave.
     db_ignore_slave();
 
+    field_attach_insert('comment', $comment);
+
     // Tell the other modules a new comment has been submitted.
     module_invoke_all('comment_insert', $comment);
     // Add an entry to the watchdog log.
@@ -963,6 +977,32 @@ function comment_save($comment) {
 }
 
 /**
+ * Delete a comment and all its replies.
+ *
+ * @param $comment
+ *   The comment to delete.
+ */
+function comment_delete($cid) {
+  $comment = comment_load($cid);
+  if ($comment) {
+
+    // Delete the comment.
+    db_delete('comment')
+      ->condition('cid', $comment->cid)
+      ->execute();
+    watchdog('content', 'Comment: deleted %subject.', array('%subject' => $comment->subject));
+    field_attach_delete('comment', $comment);
+    module_invoke_all('comment_delete', $comment);
+
+    // Delete the comment's replies.
+    $result = db_query('SELECT cid FROM {comment} WHERE pid = :cid', array(':cid' => $comment->cid));
+    foreach ($result as $row) {
+      comment_delete($row->cid);
+    }
+  }
+}
+
+/**
  * Implement hook_link().
  */
 function comment_link($type, $object, $build_mode) {
@@ -1640,6 +1680,8 @@ function comment_form(&$form_state, $edi
     $form['#action'] = url('comment/reply/' . $edit['nid']);
   }
 
+  field_attach_form('comment', (object) $edit, $form, $form_state);
+
   return $form;
 }
 
@@ -1748,6 +1790,7 @@ function comment_form_validate($form, &$
   }
 
   // Invoke other validation handlers.
+  field_attach_form_validate('comment', (object) $form_state['values'], $form, $form_state);
   module_invoke_all('comment_validate', $form_state['values']);
 
   if (isset($form_state['values']['date'])) {
@@ -1839,6 +1882,8 @@ function comment_form_submit($form, &$fo
   $edit = $form_state['values'];
   $node = node_load($edit['nid']);
   _comment_form_submit($edit);
+
+  field_attach_submit('comment', (object) $form_state['values'], $form, $form_state);
   if (user_access('post comments') && (user_access('administer comments') || $node->comment == COMMENT_NODE_OPEN)) {
     $comment = (object) $edit;
     comment_save($comment);
