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	14 Jul 2009 22:24:32 -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.740
diff -u -p -r1.740 comment.module
--- modules/comment/comment.module	10 Jul 2009 05:50:08 -0000	1.740
+++ modules/comment/comment.module	14 Jul 2009 22:24:33 -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,
   );
@@ -201,6 +201,38 @@ function comment_menu() {
 }
 
 /**
+ * Implement hook_fieldable_info().
+ */
+function comment_fieldable_info() {
+  $return = array(
+    'comment' => array(
+      'label' => t('Comment'),
+      'object keys' => array(
+        'id' => 'cid',
+        'bundle' => 'node_type',
+      ),
+      'bundle keys' => array(
+        'bundle' => 'type',
+      ),
+      'bundles' => array(),
+    ),
+  );
+  foreach (node_type_get_names() as $type => $name) {
+    $return['comment']['bundles']['comment_node_' . $type] = array(
+      'label' => $name,
+      'admin' => array(
+        'path' => 'todo',
+        'real path' => 'todo',
+        'bundle argument' => 'todo',
+        'access arguments' => array('administer comments'),
+      ),
+    );
+  }
+  return $return;
+}
+
+
+/**
  * Implement hook_node_type().
  */
 function comment_node_type($op, $info) {
@@ -215,7 +247,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 +769,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 +847,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 +897,9 @@ function comment_save($comment) {
       $comment->$key = $default;
     }
   }
+  $node = node_load($comment->nid);
+  $comment->node_type = $node->type;
+  field_attach_presave('comment', $comment);
   if ($comment->cid) {
     // Update the comment in the database.
     db_update('comment')
@@ -871,6 +916,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 +994,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 +1011,32 @@ function comment_save($comment) {
 }
 
 /**
+ * Perform the actual deletion of 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) {
@@ -1268,7 +1342,9 @@ function comment_load_multiple($cids = a
   if ($cids || $conditions) {
     $query = db_select('comment', 'c');
     $query->innerJoin('users', 'u', 'c.uid = u.uid');
+    $query->innerJoin('node', 'n', 'c.nid = n.nid');
     $query->addField('u', 'name', 'registered_name');
+    $query->addField('n', 'type', 'node_type');
     $query
       ->fields('c', array('cid', 'nid', 'pid', 'comment', 'subject', 'format', 'timestamp', 'name', 'mail', 'homepage', 'status', 'thread'))
       ->fields('u', array( 'uid', 'signature', 'picture', 'data', 'status'));
@@ -1287,8 +1363,10 @@ function comment_load_multiple($cids = a
     $comments = $query->execute()->fetchAllAssoc('cid');
   }
 
-  // Invoke hook_comment_load().
   if (!empty($comments)) {
+    // Attach fields.
+    field_attach_load('comment', $comments);
+    // Invoke hook_comment_load().
     module_invoke_all('comment_load', $comments);
   }
   return $comments;
@@ -1663,6 +1741,10 @@ function comment_form(&$form_state, $edi
     $form['#action'] = url('comment/reply/' . $edit['nid']);
   }
 
+  $comment = (object) $edit;
+  $comment->node_type = $node->type;
+  field_attach_form('comment', $comment, $form, $form_state);
+
   return $form;
 }
 
@@ -1761,6 +1843,11 @@ function comment_form_add_preview($form,
  */
 function comment_form_validate($form, &$form_state) {
   global $user;
+  $comment = (object) $form_state['values'];
+  $node = node_load($comment->nid);
+  $comment->node_type = $node->type;
+  field_attach_form_validate('comment', $comment, $form, $form_state);
+
   if ($user->uid === 0) {
     foreach (array('name', 'homepage', 'mail') as $field) {
       // Set cookie for 365 days.
@@ -1856,11 +1943,13 @@ function _comment_form_submit(&$comment_
  * Process comment form submissions; prepare the comment, store it, and set a redirection target.
  */
 function comment_form_submit($form, &$form_state) {
-  $edit = $form_state['values'];
-  $node = node_load($edit['nid']);
-  _comment_form_submit($edit);
+  _comment_form_submit($form_state['values']);
+
+  $comment = (object) $form_state['values'];
+  $node = node_load($comment->nid);
+  $comment->node_type = $node->type;
+  field_attach_submit('comment', $comment, $form, $form_state);
   if (user_access('post comments') && (user_access('administer comments') || $node->comment == COMMENT_NODE_OPEN)) {
-    $comment = (object) $edit;
     comment_save($comment);
     // Explain the approval queue if necessary.
     if ($comment->status == COMMENT_NOT_PUBLISHED) {
