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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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