5

I can't run cron, manually or automatically. I installed Cron Debug module, checked all modules, and found out that the Search module makes cron stuck. When I disable it, cron is working.

I suppose the reason is one of my nodes has bad PHP code in it. I googled for "search_cron errors", and found a solution in Drupal.org I tried it by editing node.module, but I got this error:

Fatal error: Call to undefined function db_fetch_object() in /home/mysite/public_html/modules/node/node.module on line 2616

Can you propose me a solution on how I can find the errorenous PHP code in nodes? I am using Drupal 7.12.

  • 3
    The suggestion you followed is for drupal 6, and from your line number, I am assuming you are running drupal 7... – Jimajamma Feb 16 '12 at 23:40
  • What kind of error or miss behaviour do you get when you try to run cron (without the D6 change in node.module)? – BetaRide Feb 20 '12 at 18:51
  • cron job is run for some seconds, than it becomes stucked without an error message. white screen. – trante Feb 20 '12 at 21:21
5

i was facing this issue after upgrading a big application from 6 to 7.This is what I did. From the database run this query

SELECT n.nid FROM node n LEFT JOIN search_dataset d ON d.type = 'node' AND d.sid = 
n.nid WHERE   
d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid asc

This will give you the last node that is giving you issues and has refused to be re-indexed. From there you can do what you want with that node. For my case I realized it was a whole content type that was not displaying well. I had to resave one of the fields to allow this content type to display.

  • 1
    OMG everyone should upvote this! I have dealt with this on many sites and never found such an elegant solution to find the culrpit. For anyone having this problem, it is probably your search_cron failing. Yes increasing memory may help and even solve it. but the bigger issue is that search_cron is failing while trying to index nodes. Debugging it usually involves touching the system search module manually. This query however lead me right to the culprit node which had 8000 entity references and was causing the job to freeze. NOTE: Look at the very top of the results of this query for the nid – Matt Campbell May 11 '17 at 16:21
2

The function db_fetch_object() doesn't exist in Drupal 7, it was replaced by the new Database API. Checkout Dynamic Querys, Ranges and limits or even Static querys for more details.

In this specific case, you don't need to write nearly as much code. This function that thread suggests editing, node_update_index(), looks like this in Drupal 7.

function node_update_index() {
   $limit = (int)variable_get('search_cron_limit', 100);

   $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit, array(), array('target' => 'slave'));

   foreach ($result as $node) {
     _node_index_node($node);
   }
}

According to that thread, you just want to store the nid of the nodes as they are indexed so you can tell which one is causing the problem. To do that, you just need to add the call to watchdog() in the foreach loop, like so...

function node_update_index() {
   $limit = (int)variable_get('search_cron_limit', 100);

   $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit, array(), array('target' => 'slave'));

   foreach ($result as $node) {
     watchdog('cron', "about to index node " . $node->nid);   /// ADD THIS TO DEBUG
     _node_index_node($node);
   }
}
0

create views page, add title field, field_body, add exposed filter body - option "contain", save, open the page and try to find bad string db_fetch_object, then delete it or make it correct

  • No. db_fetch_object is a function. It is not defined in D6. – stefgosselin Aug 20 '12 at 3:14
  • It was defined in D6, but not in D7 – Chaulky Aug 20 '12 at 3:31
0

Adding the Watch Dog line worked for me.

However, if you are working on an active live system:

I would suggest that you use drush with two terminals open to run the following commands:

1) drush search-index 2) drush watchdog-show

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.