You are here

function comment_delete_threading in Comment Delete 7

Re-threads comments attached to an entity.

Parameters

int $nid: The node ID of which to rethread comments.

1 call to comment_delete_threading()
comment_delete_move_replies in ./comment_delete.module
Moves comment replies up one thread.

File

./comment_delete.module, line 317
comment_delete.module

Code

function comment_delete_threading($nid) {
  $comments = array();

  // Retrieve all comments attached to entity.
  $results = db_select('comment', 'c')
    ->fields('c', array(
    'cid',
    'pid',
    'created',
  ))
    ->condition('c.nid', $nid)
    ->orderBy('c.created', 'ASC')
    ->execute();
  foreach ($results as $data) {
    $comments[] = (array) $data;
  }

  // Collect and calculate new comment threading strings.
  $tree = comment_delete_threading_tree($comments);
  $threads = comment_delete_threading_values($tree);

  // Update comment threads in database table.
  foreach ($threads as $cid => $thread_string) {
    db_update('comment')
      ->fields(array(
      'thread' => $thread_string . '/',
    ))
      ->condition('cid', $cid)
      ->execute();
  }
}