6

I'm using Ajax_comments to add comments on nodes without having to reload the page on save. Now the "node history" doesn't get updated which throws off the "new comment" count.

I tried to create a rule to update the node history on "comment save". Seems like my only option is to execute PHP code. How do I combine PHP code with tokens to get something like this:

if ([current-user:uid]) {
   db_merge('history')
     ->key(array(
       'uid' => [current-user:uid],
       'nid' => [comment:node:nid],
     ))
     ->fields(array('timestamp' => [site:current-date]))
     ->execute();
  }
0
3

It turns out that the above code works when I turn of the Ajax Comments module. With that module, it throws an internal server error.

I reported it as issue.

This hook does the job now:

function hook_comment_insert($comment) {
  //dpm($comment);

  if ($comment->uid) {
   db_merge('history')
     ->key(array(
       'uid' => $comment->uid,
       'nid' => $comment->nid,
     ))
     ->fields(array('timestamp' => REQUEST_TIME))
     ->execute();
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.