From 6517ef5a7c8c2161c7824cfc6bc8d9c0bd059763 Mon Sep 17 00:00:00 2001
From: Bob Vincent <bobvin@pillars.net>
Date: Sun, 22 May 2011 22:08:16 -0400
Subject: [PATCH] Issue #193409 by dami, catch, pillarsdotnet: List descendent comments on delete confirm page.

---
 modules/comment/comment.admin.inc |   39 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 38 insertions(+), 1 deletions(-)

diff --git a/modules/comment/comment.admin.inc b/modules/comment/comment.admin.inc
index 4f3d35071536658cda832478b20f6d99ffe2a5ef..b87697e85f7bfbfa70f7216a8b2939680ae0ae95 100644
--- a/modules/comment/comment.admin.inc
+++ b/modules/comment/comment.admin.inc
@@ -257,11 +257,35 @@ function comment_confirm_delete($form, &$form_state, $comment) {
   $form['#comment'] = $comment;
   // Always provide entity id in the same form key as in the entity edit form.
   $form['cid'] = array('#type' => 'value', '#value' => $comment->cid);
+
+  $descendants = array();
+  _comment_descendants($comment, &$descendants);
+
+  if (empty($descendants)) {
+    $description = t('This action cannot be undone');
+  }
+  else {
+    $description = t('The following replies to this comment will also be deleted. This action cannot be undone.');
+    $item = array();
+    $node = node_load(array('nid' => $comment->nid));
+    foreach ($descendants as $c) {
+      $basepath = base_path();
+      $args = array(
+        '!subject' => l(
+          $c->subject, $basepath . 'node/'. $node->nid .'/#comment-'. $c->cid
+        ),
+        '!user' => theme('username', user_load(array('uid' => $c->uid))),
+      );
+      $item[] = t('!subject by !user', $args);
+    }
+    $description .= theme('item_list', $item);
+  }
+
   return confirm_form(
     $form,
     t('Are you sure you want to delete the comment %title?', array('%title' => $comment->subject)),
     'node/' . $comment->nid,
-    t('Any replies to this comment will be lost. This action cannot be undone.'),
+    $description,
     t('Delete'),
     t('Cancel'),
     'comment_confirm_delete');
@@ -281,3 +305,16 @@ function comment_confirm_delete_submit($form, &$form_state) {
 
   $form_state['redirect'] = "node/$comment->nid";
 }
+
+/**
+ * Get all replies (including descendants down in the tree) to a comment.
+ * @$comment: comment
+ * @$descendants: array of all descendant comments
+ */
+function _comment_descendants($comment, &$descendants = array()) {
+  $result = db_query('SELECT c.* FROM {comments} c WHERE pid = %d', $comment->cid);
+  while ($child = db_fetch_object($result)) {
+    array_push($descendants, $child);
+    _comment_descendants($child, &$descendants);
+  }
+}
-- 
1.7.4.1

