You are here

function casetracker_comment_insert in Case Tracker 7

Implements hook_comment_insert().

File

./casetracker.module, line 385
Enables the handling of projects and their cases.

Code

function casetracker_comment_insert($comment) {

  // Load the node here -- it is almost certainly static cached already.
  $node = is_array($comment) ? node_load($comment['nid']) : node_load($comment->nid);

  // Bail if this is not a casetracker node.
  if (!casetracker_is_case($node->type)) {
    return;
  }
  $new = (object) $comment->casetracker;
  $new->cid = $comment->cid;
  $new->nid = $comment->nid;
  $new->vid = $comment->revision_id;
  $new->state = 1;
  $new->assign_to = casetracker_get_uid($new->assign_to);

  // Populate old state values from node
  $old = $node->casetracker;
  $old->cid = $comment->cid;
  $old->state = 0;
  drupal_write_record('casetracker_case', $new, array(
    'nid',
    'vid',
  ));

  // Fire events for case change
  if (is_callable('rules_invoke_event')) {

    //Determine if the user id has changed
    if ($new->assign_to && $new->assign_to != $node->casetracker->assign_to) {
      $user = user_load($new->assign_to);
      rules_invoke_event('casetracker_assign_case', $node, $user);
    }
    _casetracker_change_event($node, $node->casetracker, $new);
  }
  drupal_write_record('casetracker_comment_status', $old);
  drupal_write_record('casetracker_comment_status', $new);
}