I was trying to fix this issue #1541800: History doesn't get updated after comment has been saved by using a rule on "comment save"

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

This rule executes fine when I have the ajax comments module turned off.
When I turn it off I this error in a popup when I try to submit a comment:

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /mt/system/ajax
StatusText: Internal Server Error
ResponseText: [{"command":"settings","settings":{"basePath":"\/mt\/","pathPrefix":"","ajaxPageState":{"theme":"bartik","theme_token":"J_NTC7ULEM ....

The comment does get saved. Any idea how to fix that?

Comments

Berdir’s picture

Internal Server error is usually a PHP Fatal Error.

Try to turn on error logging in PHP if it isn't already and then check your server error logs for the actual error.

mototribe’s picture

Thanks Berdir, great idea!

I'm getting:

PHP Parse error: syntax error, unexpected '[' in /Users/uwe999/Sites/mt/sites/all/modules/rules/modules/php.eval.inc(125) : eval()'d code on line 3

When I replace the tokens with dummy values it works fine.
Maybe I'm better off using a hook_comment_insert?

cheers
UWE

mototribe’s picture

This hook seems to work fine for me 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();
  }
}

formatC'vt’s picture

Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)

try latest dev, please

formatC'vt’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)