Drupal – Cron problem with drupal_goto() in hook_nodeapi()

One day, i found the the Drupal cron job failed to run. There was no error log and after i clicked the run cron manually in the status report, it was redirected to a specific node. This redirection was previously added by me in hook_nodeapi() such that under certain conditions, that specific node is displayed.

Finally, i fixed the problem by adding a condition in the hook_nodeapi() before redirect.

if ($_SERVER['SCRIPT_NAME'] != '/cron.php') {
  // redirect only if it is not triggered by cron.php
  drupal_goto('node/1');
}

 

Done =)

Reference: cron breaks on drupal_goto

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.